Skip to content

fix(native-spans): span-meta language, lazy transport requires, /v0.6/stats slash, IPv6 host#168

Merged
bengl merged 4 commits into
mainfrom
bengl/fix-span-language
Jul 10, 2026
Merged

fix(native-spans): span-meta language, lazy transport requires, /v0.6/stats slash, IPv6 host#168
bengl merged 4 commits into
mainfrom
bengl/fix-span-language

Conversation

@bengl

@bengl bengl commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Four small native-spans fixes that unblock dd-trace-js system-tests / init guardrails / v0.6 stats / IPv6 on the native-spans branch (#9139).

1. span-meta languagejavascript

process_span stamped span.meta["language"] from ChangeBufferState's tracer_language (= the lang arg = "nodejs", the Datadog-Meta-Lang header value). The span-meta language tag must be "javascript" for the Node.js tracer (matching the JS pipeline's span_format and system-tests test_meta_language_tag). Pass "javascript" for the span meta; header + StatsMeta.lang untouched.

2. Lazy-require node:http/node:https/node:fs in the transport

The transport eagerly required these builtins at module load. It loads during dd-trace-js's own tracer init (before user code), and dd-trace instruments builtins by wrapping them in place when required through its hook — so http got wrapped during init, and a user ESM app that then imports http (e.g. under --require) got instrumented when it must not (breaks init.spec.js "should not initialize ESM instrumentation", ~10 Platform + guardrails checks). Require them lazily inside httpRequest/detectEntityHeaders.

3. Avoid double slash in the /v0.6/stats URL

Stats URL was format!("{}{}", agent_url, "/v0.6/stats"); agent_url (URL.toString()) ends in /, so the path became //v0.6/stats. The agent records the raw path and stats tooling matches /v0.6/stats exactly, so client stats silently never arrived (root cause of the 0-stats parametric + resource_renaming E2E failures). Trim the trailing slash.

4. Strip IPv6 brackets from the transport host

libdatadog derives the connect host from the agent URI, keeping the brackets for an IPv6 literal ([::1]). Node's http.request treats host as a name to resolve, so [::1]getaddrinfo ENOTFOUND [::1] and traces never reach an IPv6 agent (system-tests ipv6 "No trace has been found", 5 shards). Strip the brackets for the TCP connect target; the pre-rendered Host: header keeps them (RFC 3986).

Known follow-ups (not in this PR): span-event array attributes and span_events-as-tag are dd-trace-js-side (the binding already supports typed array attrs).

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

Overall package size

Self size: 30.09 MB
Deduped: 30.09 MB
No deduping: 30.09 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------|

🤖 This report was automatically generated by heaviest-objects-in-the-universe

… lang

The change buffer's process_span stamps span.meta["language"] from the
tracer_language passed to ChangeBufferState, which was the `lang` argument.
dd-trace-js passes lang="nodejs" (the Datadog-Meta-Lang header value that
identifies the tracer library) but the span-meta language tag must be
"javascript" for the Node.js tracer (matching the JS pipeline's span_format
and system-tests test_meta_language_tag). Pass "javascript" as the span-meta
language while leaving set_language(lang) and StatsMeta.lang untouched.
@bengl bengl force-pushed the bengl/fix-span-language branch from 0ef1e80 to 46f1648 Compare July 10, 2026 03:16
@bengl bengl changed the title fix(pipeline): stamp span-meta language as javascript, not the tracer lang fix(native-spans): span-meta language=javascript + lazy transport builtin requires Jul 10, 2026
The Node HTTP transport eagerly required node:http/https/fs at module load.
Because this module is loaded during dd-trace-js's own tracer init (before user
code), and dd-trace instruments builtins by wrapping them in place when they're
required through its hook, the eager require made http get wrapped during init.
A user ESM app that then imports http (e.g. under --require) saw the wrapped
builtin and got instrumented when it must not, breaking dd-trace-js's
init/guardrail expectations (~10 Platform + guardrails checks).

Require node:http/https inside httpRequest and node:fs inside
detectEntityHeaders (their only consumers), so nothing instrumentable is loaded
until the first agent send \u2014 matching the JS agent exporter's lazy timing.
@bengl bengl force-pushed the bengl/fix-span-language branch from 46f1648 to b5a9a6a Compare July 10, 2026 04:36
@bengl bengl changed the title fix(native-spans): span-meta language=javascript + lazy transport builtin requires fix(native-spans): span-meta language + lazy transport requires + /v0.6/stats double-slash Jul 10, 2026
The stats sender concatenated agent_url + "/v0.6/stats". agent_url normally
ends in "/" (Node's URL.toString() normalizes a bare authority that way), so
the request path became "//v0.6/stats". The agent records the raw request
path, so stats tooling and the test-agent (which match "/v0.6/stats" exactly)
miss the request entirely — client stats appear to never arrive. Trim the
trailing slash so the path is exactly "/v0.6/stats".
@bengl bengl force-pushed the bengl/fix-span-language branch from b5a9a6a to 81e17c9 Compare July 10, 2026 13:03
@bengl bengl changed the title fix(native-spans): span-meta language + lazy transport requires + /v0.6/stats double-slash fix(native-spans): span-meta language, lazy transport requires, /v0.6/stats slash, IPv6 host Jul 10, 2026
@bengl bengl marked this pull request as ready for review July 10, 2026 13:23
@bengl bengl requested review from a team as code owners July 10, 2026 13:23
libdatadog derives the request host from the agent URI, which keeps the
brackets for an IPv6 literal (e.g. `[::1]`). Node's `http.request` treats the
`host` option as a name to resolve, so `[::1]` fails with `getaddrinfo
ENOTFOUND [::1]` and traces never reach an IPv6 agent (the system-tests ipv6
scenario: "No trace has been found"). Strip the surrounding brackets in
httpRequest so the IPv6 address is used directly (Node accepts `::1`).
@bengl bengl force-pushed the bengl/fix-span-language branch from 81e17c9 to 1245e94 Compare July 10, 2026 13:25
@bengl bengl merged commit fefe136 into main Jul 10, 2026
47 checks passed
@bengl bengl deleted the bengl/fix-span-language branch July 10, 2026 14:15
@bengl bengl mentioned this pull request Jul 10, 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.

2 participants