Skip to content

[#646] JS OTel sample leaves an open connection when shutting down#649

Open
ceciliaavila wants to merge 3 commits into
mainfrom
southworks/fix/js-otel-shut-down
Open

[#646] JS OTel sample leaves an open connection when shutting down#649
ceciliaavila wants to merge 3 commits into
mainfrom
southworks/fix/js-otel-shut-down

Conversation

@ceciliaavila

Copy link
Copy Markdown
Collaborator

Fixes #646

Description

This pull request enhances OpenTelemetry instrumentation for the Node.js sample by improving the SDK shutdown process. It also adds support for Undici HTTP client tracing to have observability over fetch requests.

Detailed Changes

  • Improved the SDK shutdown handler to handle multiple signals safely, enforce a shutdown timeout, and ensure the process exits cleanly after shutdown.
  • Explicitly enabled the AlwaysOnSampler for tracing to ensure all traces are captured.
  • Added @opentelemetry/instrumentation-undici as a dependency and enabled UndiciInstrumentation in the SDK configuration to support tracing for the Undici HTTP client.

Testing

These images show the sample successfully restarted and the traces properly exported.
image

image

Copilot AI review requested due to automatic review settings July 8, 2026 13:16
@github-actions github-actions Bot added the Samples Changes to Samples label Jul 8, 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.

Pull request overview

This pull request updates the Node.js OpenTelemetry (OTel) sample to shut down the OTel SDK more reliably (to avoid lingering connections on restart) and expands tracing coverage by adding Undici (fetch) instrumentation.

Changes:

  • Adds a guarded shutdown handler with a timeout and explicit process exit after sdk.shutdown().
  • Enables AlwaysOnSampler to ensure traces are always sampled.
  • Adds @opentelemetry/instrumentation-undici and wires UndiciInstrumentation into the SDK.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
samples/nodejs/otel/src/instrumentation.ts Updates SDK configuration (sampler + instrumentations) and improves shutdown handling to avoid lingering resources.
samples/nodejs/otel/package.json Bumps OpenTelemetry dependencies and adds Undici instrumentation dependency.
samples/nodejs/otel/package-lock.json Updates lockfile to reflect the new/updated OpenTelemetry dependency graph.
Files not reviewed (1)
  • samples/nodejs/otel/package-lock.json: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread samples/nodejs/otel/src/instrumentation.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

JS OTel sample leaves an open connection when shutting down

2 participants