Skip to content

Update JS otel sample to use parent-sampler filtering - #719

Open
Cecilia Avila (ceciliaavila) wants to merge 4 commits into
mainfrom
southworks/update/otel-sample-span-filtering
Open

Update JS otel sample to use parent-sampler filtering#719
Cecilia Avila (ceciliaavila) wants to merge 4 commits into
mainfrom
southworks/update/otel-sample-span-filtering

Conversation

@ceciliaavila

Copy link
Copy Markdown
Collaborator

Related issue: #1282

Description

This pull request updates the OpenTelemetry Node.js sample to introduce a custom sampler that filters out specific span categories (such as storage operations) from telemetry data. It removes the AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES environment variable from the .env template as it is now deprecated in the SDK.

Key changes:

Telemetry Sampling Improvements:

  • Added a SpanNameFilteringSampler class in instrumentation.ts to filter out spans by name, preventing certain categories (like storage operations) from being recorded or exported. This sampler is now used in place of the default AlwaysOnSampler and is configured to filter out storage-related spans (STORAGE_READ, STORAGE_WRITE, STORAGE_DELETE).

Configuration Cleanup:

  • Removed the AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES environment variable from the template in env.TEMPLATE, as span filtering is now handled programmatically via the custom sampler.

Testing

These images show the spans registered with the two methods: First, using the deprecated AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES env variable; Second image, using the parent sampler filter.
image

image

Copilot AI lite review requested due to automatic review settings September 4, 2026 14:53
@github-actions github-actions Bot added the Samples Changes to Samples label Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The lockfile changes introduce non-reproducible/local-path entries and a Node engine requirement mismatch (Node 22+) versus the sample’s documented Node 20+ prerequisite.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the Node.js OpenTelemetry sample to replace env-var-based span-category disabling with a programmatic sampler that filters out selected span names (notably storage operations), aligning with the deprecation of AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES in the SDK.

Changes:

  • Added a custom SpanNameFilteringSampler in the OTel SDK bootstrap and configured it to drop storage spans (STORAGE_READ/WRITE/DELETE).
  • Added @microsoft/agents-telemetry dependency to consume shared span-name constants.
  • Removed the deprecated AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES entry from the sample .env template.
File summaries
File Description
samples/nodejs/otel/src/instrumentation.ts Introduces and wires a custom sampler to filter out selected span names before export.
samples/nodejs/otel/package.json Adds @microsoft/agents-telemetry dependency for SpanNames.
samples/nodejs/otel/package-lock.json Updates lockfile to include the new dependency and refreshes transitive dependency resolutions.
samples/nodejs/otel/env.TEMPLATE Removes the deprecated telemetry span-category env var from the template.
Review details

Files not reviewed (1)

  • samples/nodejs/otel/package-lock.json: Generated file
  • Files reviewed: 3/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread samples/nodejs/otel/package-lock.json Outdated
Comment thread samples/nodejs/otel/package-lock.json Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Samples Changes to Samples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants