Instrument fetch (undici) for HTTP client spans - #190
Closed
Jackson Weber (JacksonWeber) wants to merge 1 commit into
Closed
Instrument fetch (undici) for HTTP client spans#190Jackson Weber (JacksonWeber) wants to merge 1 commit into
Jackson Weber (JacksonWeber) wants to merge 1 commit into
Conversation
The distro only registered @opentelemetry/instrumentation-http (Node core http/https). The OpenAI SDK used by LangChain issues requests via the global fetch (undici) on Node 18+, so LLM HTTP calls produced no client spans. Register @opentelemetry/instrumentation-undici (enabled by default). When the fetch-based A365 exporter is active, a merged undici ignoreRequestHook skips its export origin so telemetry traffic is not self-traced (undici does not honor tracing suppression). Adds unit tests for the registration wiring, the ignore-hook behavior, and A365 origin resolution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Jackson Weber (JacksonWeber)
July 14, 2026 02:14
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Undici (fetch) instrumentation to ensure outgoing HTTP client spans are emitted for fetch-based SDKs (notably the OpenAI Node SDK used by LangChain) on Node 18+ where fetch is backed by Undici and is not covered by the core http/https instrumentation.
Changes:
- Add
@opentelemetry/instrumentation-undiciand enable it by default viaInstrumentationOptions.undici. - Register
UndiciInstrumentationincreateInstrumentations, including an optional origin-basedignoreRequestHookto prevent exporter self-instrumentation. - Add unit tests covering undici registration/config behavior and A365 exporter-origin resolution; update SDKStats bitmap assertions accordingly.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/internal/unit/main.test.ts | Updates SDKStats instrumentation bitmap assertions to include UNDICI and adds coverage for disabling undici via options. |
| test/internal/unit/distro/instrumentations.test.ts | New unit tests validating undici instrumentation registration/config and A365 exporter-origin resolution logic. |
| src/types.ts | Adds undici?: UndiciInstrumentationConfig to the public instrumentation options type with explanatory docs. |
| src/shared/config.ts | Enables undici instrumentation by default in internal defaults and updates the documented list of supported instrumentations. |
| src/distro/instrumentations.ts | Registers UndiciInstrumentation and composes an ignoreRequestHook when exporter origins should be filtered. |
| src/distro/distro.ts | Adds undici to A365 “disabled by default” list and resolves exporter origins to avoid tracing exporter traffic via undici. |
| package.json | Adds @opentelemetry/instrumentation-undici dependency. |
| package-lock.json | Adds lock entries for @opentelemetry/instrumentation-undici. |
| CHANGELOG.md | Documents the new fetch/undici instrumentation feature under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * | ||
| * @internal | ||
| */ | ||
| export function _resolveA365ExporterOrigins(a365Config: A365Configuration): string[] { |
There was a problem hiding this comment.
A little confused here, why do we need to do this? I think A365 drops the http spans anyways.
Radhika Gupta (rads-1996)
left a comment
Member
There was a problem hiding this comment.
Do you mind sharing a screenshot of the spans?
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Outgoing LLM HTTP calls produced no HTTP client spans. The distro only registered
@opentelemetry/instrumentation-http, which patches Node's corehttp/httpsmodules — but the OpenAI Node SDK used by LangChain (ChatOpenAI/AzureChatOpenAI) issues its requests via the globalfetch(undici) on Node 18+, which was never instrumented.This registers
@opentelemetry/instrumentation-undici(enabled by default) sofetch-based HTTP client spans are produced.Changes
@opentelemetry/instrumentation-undici@^0.29.0(matches the pinned@opentelemetry/instrumentation@^0.219.0).undici?: UndiciInstrumentationConfigtoInstrumentationOptions; enabled by default.UndiciInstrumentationincreateInstrumentations.undicito the A365 disabled-by-default instrumentations.ignoreRequestHookskips its export origin. (Undici does not honor tracing suppression, so exporter traffic would otherwise be traced as spurious dependency spans on other exporters, e.g. Azure Monitor.)Tests
test/internal/unit/distro/instrumentations.test.ts(10 tests): undici registered by default / disabled on request; ignore-hook filters exporter origins while tracing realfetch; delegates to caller-provided hooks; caller config is cloned not mutated;_resolveA365ExporterOriginsresolution.main.test.ts(undici bit now auto-included).fetch()and a LangChainChatOpenAIcall both emit HTTP client spans (incl. thePOST …/chat/completionsLLM request); disabling undici reproduces the missing-span behavior.