Skip to content
All docs

Docs · Product guides

Bounded span metrics and collector sampling

Source: docs/span-metrics.md

On this page

The native metric-rule API is available to a signed-in current native owner for preview and approval. Reads require current native telemetry access covering the exact service, environment and team. Bearer credentials cannot manage these rules. This is a partial implementation; it does not qualify the complete PORT-078 or PORT-010 contract.

  1. POST /api/porthole/v1/metric-rules/preview with a definition.
  2. Inspect the normalized definition, maximum series count, input restrictions and cost limitations. The preview binds its exact definition, target ID, expected revision, owner and session for five minutes.
  3. POST /api/porthole/v1/metric-rules/approve with the returned previewId and digest, and confirm: "approve-metric-rule". Successful fresh native identity proof from the preceding five minutes is required again at commit. Each preview authorizes at most one mutation. To revise, supply the existing id and revision to the preview door first.
  4. GET /api/porthole/v1/metric-rules to list authorized definitions. POST /api/porthole/v1/metric-rules/query with id, revision, from and through to read delta aggregates over a half-open nanosecond range.

A definition contains name, exact service, environment, team, exact spanName, kind, value, unit, dimensions and upstream. Kinds are counter, sum and distribution. Counter values are one per matched span; sums accept integer amount or quantity attributes, bounded to one billion in magnitude; duration distributions use value: "duration" with nanoseconds, bounded to one trillion per span. Non-integral, missing or out-of-range values remain missing and make coverage incomplete. Percentiles use exact nearest ranks. Queries refuse beyond 100,000 points; rule history is bounded to 100 revisions. Large distribution sums may exceed safe integer precision; distribution percentiles remain exact within the supported per-span range.

Optional status: "error" selects OTLP error spans; the default is any. Optional inputStage: "pre-sampling" selects the separate full-input fork; default accepted selects normal intake. An ordinary rule cannot silently borrow full-input counts or unrelated RED metrics. upstream must be complete, sampled or unknown; this is an owner declaration, never independent verification. Empty inputs, pending relevant inputs, reported losses, invalid values and undeclared dimension values remain incomplete.

Dimensions are limited to region, plan and endpoint, each with explicit permitted values. At most 20 values per dimension and 100 combined series, including [other] buckets, are allowed. Forbidden keys and excessive proposals refuse before approval. Unlisted actual values enter [other], disclose incompleteness and never create unbounded series. Preview authorizes no external purchase; existing installation quotas and billing still apply, and a USD estimate is unavailable.

Rules apply only to batches accepted after approval. Contributions commit atomically with durable processing and are unique by rule revision, batch identity and ordinal. An identical retry does not add points; changing bytes under one explicit batch identity refuses. Reusing spans under a new batch identity intentionally counts again. Exemplars carry only the permitted scope and a timestamp within the queried range. A sampled-out trace may have no retained graph.

Stock collector fork

The configuration at collectors/sampling/collector.yaml uses the official OTel Contrib collector 0.135.0. node collectors/sampling/release.mjs acquires and verifies its published Linux x64 archive. Configure the listen addresses, destination and private credential through the named collector environment variables. Do not commit credentials.

The full-input pipeline forks to /api/porthole/v1/ingest/pre-sampling/traces before the tail processor. That door persists authenticated original input for metric derivation, without exposing it as retained traces. Normal sampled output reaches /v1/traces. The tail processor has a two-second decision window, a 20,000-trace memory buffer and explicit decision caches; it retains error and slow traces and probabilistically samples ordinary traces at ten percent. This is a probabilistic rate, not an exact cohort quota. It assumes all spans of each trace reach the same collector. Events later than the decision window, routing across independent collectors, collector restart and buffer exhaustion remain unqualified. Its memory buffer is not durable. Do not use this configuration as a production protection or zero-loss claim.

Both branches can be drained through /api/porthole/v1/ingest/drain. Full-input derivation uses the unsampled fork; processing may occur after the collector made its tail decision. Source envelopes remain in durable custody; this implementation does not claim sampled retention reduces physical storage. Existing delivery accounting exposes full-input versus retained differences as incomplete rather than silently declaring complete coverage. Automatic collector loss reporting is not implemented. Datadog Agent stats are not implemented here.

Native and Settings archives preserve rule definitions and points, exclude preview approvals, and restore rules quarantined. A restored rule cannot be evaluated or derive new points until a new native owner approves a new revision. Complete independent archive and journal qualification remains pending. Removing a canonical source record or erasing an envelope also deletes its derived points. Broader mixed-subject and analytical custody obligations remain under PORT-035 and PORT-096.

Qualification

The existing spanMetricJourney in tests/porthole/ingest.mjs runs through the emitted Worker and D1. Push Verify invokes the focused API journey with 1,000 spans. The clause's separate 10,000-span qualification uses PORTHOLE_METRIC_SCALE=1; add PORTHOLE_METRIC_COLLECTOR=1 to exercise the official collector, delayed errors, slow traces and ordinary sampling. Invoke it through PORTHOLE_METRIC_RULES_ONLY=1 node tests/runtime.mjs, with an external hard timeout. Qualification receipts must name the exact committed SHA. No live Datadog account or production traffic is used.

The adopted policy is owner-only, fresh native proof, exact single-use preview binding, scoped reads, private audit, no outbound effect or purchase, and inactive restore. CT approval is pending; neither clause is DONE. Programmatic credentials, monitor integration, arbitrary predicates and attributes, priced USD estimates and full collector loss qualification remain open.