Skip to content

Add tail-based sampling rate to Hive Console OpenTelemetry tracing#2134

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/customize-sampling-rate
Draft

Add tail-based sampling rate to Hive Console OpenTelemetry tracing#2134
Copilot wants to merge 4 commits intomainfrom
copilot/customize-sampling-rate

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

hiveTracingSetup previously had no way to sample successful traces — everything was always reported to Hive Console. This adds a tail-based samplingRate option that always reports traces containing GraphQL errors while sampling successful traces at a configurable rate.

API changes

  • hiveTracingSetup accepts a new samplingRate?: number (0–1, default 1). Distinct from the OTEL head-based samplingRate in openTelemetrySetup — this is evaluated after spans are collected, so error traces are never dropped.
  • A custom OTEL-level sampler can still be provided alongside for head-based sampling.
  • HiveTracingSpanProcessorOptions exposes samplingRate on both the endpoint and custom-processor variants.
hiveTracingSetup({
  target: 'my-target',
  accessToken: 'my-token',
  contextManager: new AsyncLocalStorageContextManager(),
  // Report 10% of successful traces; always report traces with GraphQL errors
  samplingRate: 0.1,
});

Implementation

  • HiveTracingSpanProcessor: sampling decision is made in onEnd when the HTTP root span closes and error counts are known. Traces with SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT > 0 bypass the rate check entirely.
  • hiveTracingSetup: replaced {...options} spread into openTelemetrySetup with an explicit field list to avoid forwarding Hive-specific fields (processor, accessToken, samplingRate, etc.) that are not part of OpentelemetrySetupOptions — this also resolves TypeScript discriminated-union conflicts between HiveSamplingOptions and SamplingOptions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • rover.apollo.dev
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node ./install.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>otel trace sampling</issue_title>
<issue_description>Customers want control over sampling the graphql requests reported by the gateway to hive console. E.g. they want to ALWAYS report all spans whose parent span has errors, but have a custom sampling rate for every other "successful" graphql request.

It should be possible to customize this behaviour via simple and intuitive configuration.</issue_description>

Comments on the Issue (you are @copilot in this section)


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Co-authored-by: ardatan <20847995+ardatan@users.noreply.github.com>
…rror-always-report behavior

Co-authored-by: ardatan <20847995+ardatan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/graphql-hive/gateway/sessions/0e83b079-a582-4db0-b4e9-a80049e2cec4
Copilot AI changed the title [WIP] Add control over GraphQL request sampling Add tail-based sampling rate to Hive Console OpenTelemetry tracing Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

otel trace sampling

2 participants