Cloudflare - v1.3.0
    Preparing search index...

    Class AnalyticsBinding<E>

    Accessor for the Analytics Engine dataset binding (analytics_engine_datasets in wrangler.json).

    The dataset carries telemetry — measurements to aggregate — and never log lines: Analytics Engine samples at volume, so an individual line written here may simply not be there when it is needed. Logging belongs to Logger in @bayudwiyansatria/core, which writes to the runtime's log stream instead.

    const dataset = new AnalyticsBinding() // binding name from the configuration layer

    dataset.writeSafe(ctx.env, {
    indexes: ['/api/v1/articles'], // sampling key
    blobs: ['POST', '201'], // dimensions to filter by
    doubles: [42, 1] // duration and a unit count
    })

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Hierarchy (View Summary)

    • Binding<AnalyticsEngineDataset, E>
      • AnalyticsBinding
    Index
    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • Checks whether the binding is available on the given environment.

      Use this to degrade gracefully when a binding is optional.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Resolves the binding, failing fast when it is not configured.

      Parameters

      • env: E

        The Worker environment.

      Returns AnalyticsEngineDataset

      The resolved binding.

      MissingBindingError When the binding is absent from the environment.

    • Resolves the binding without throwing.

      Parameters

      • env: E

        The Worker environment.

      Returns AnalyticsEngineDataset

      The resolved binding, or null when it is not configured.

    • Writes a data point to the dataset.

      Parameters

      • env: E

        The Worker environment.

      • event: AnalyticsEngineDataPoint

        The data point — blobs, doubles, and indexes.

      Returns void

      MissingBindingError When the Analytics Engine binding is absent.

    • Writes a data point, swallowing any failure.

      Telemetry is never worth failing a request over, so a missing binding or a rejected write is logged and reported through the return value instead of propagating.

      Parameters

      • env: E

        The Worker environment.

      • event: AnalyticsEngineDataPoint

        The data point — blobs, doubles, and indexes.

      Returns boolean

      true when the write was accepted, false when it failed.

      The two failures are not the same event, and conflating them is what made the earlier version of this method unreadable in production. A Worker with no TELEMETRY dataset bound is configured that way — it is the degraded path this accessor documents — so an error line per request would be a permanent, sampled, billed restatement of a deployment decision. A write that was accepted and then rejected is a real fault, and rare enough to be worth a line.

      Both go through Logger rather than console.error directly, so the line is one indexed JSON object like every other and analytics.error is a filter rather than a substring search.