Skip to content

feat(instrumentation-xml-http-request): support migration to stable HTTP semconv, v1.23.1#5662

Merged
trentm merged 8 commits intoopen-telemetry:mainfrom
trentm:trentm-instr-xhr-http-semconv-migration
May 9, 2025
Merged

feat(instrumentation-xml-http-request): support migration to stable HTTP semconv, v1.23.1#5662
trentm merged 8 commits intoopen-telemetry:mainfrom
trentm:trentm-instr-xhr-http-semconv-migration

Conversation

@trentm
Copy link
Copy Markdown
Contributor

@trentm trentm commented May 8, 2025

Configure the instrumentation with semconvStabilityOptIn: 'http' to use the new, stable semconv v1.23.1 semantics or 'http/dup' for both old (v1.7.0) and stable semantics. When semconvStabilityOptIn is not specified (or does not contain these values), it uses the old semconv v1.7.0. I.e. the default behavior is unchanged.

Closes: #5650
Refs: #5646

…TTP semconv, v1.23.1

Configure the instrumentation with semconvStabilityOptIn: 'http' to use the new, stable semconv v1.23.1 semantics or 'http/dup' for both old (v1.7.0) and stable semantics. When semconvStabilityOptIn is not specified (or does not contain these values), it uses the old semconv v1.7.0. I.e. the default behavior is unchanged.

Closes: open-telemetry#5650
Refs: open-telemetry#5646
@trentm trentm self-assigned this May 8, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.01%. Comparing base (5954fde) to head (adcb19e).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5662   +/-   ##
=======================================
  Coverage   95.01%   95.01%           
=======================================
  Files         310      310           
  Lines        7971     7971           
  Branches     1609     1609           
=======================================
  Hits         7574     7574           
  Misses        397      397           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trentm trentm marked this pull request as ready for review May 8, 2025 22:30
@trentm trentm requested a review from a team as a code owner May 8, 2025 22:30
Copy link
Copy Markdown
Member

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

First pass, this looks great! A question on request body and env vars

let knownMethods: { [key: string]: boolean };
function getKnownMethods() {
if (knownMethods === undefined) {
const cfgMethods = getStringListFromEnv(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this usable in a web package? Or should this be configured programmatically like the OptIn config option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. It'll "work" but get undefined everytime, because it'll get this implementation:
https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.0/packages/opentelemetry-core/src/platform/browser/environment.ts#L29-L31

So this should probably change. BTW, the same code exists in instrumentation-fetch currently.

The spec says:

If the HTTP instrumentation could end up converting valid HTTP request methods to _OTHER, then it MUST provide a way to override the list of known HTTP methods. If this override is done via environment variable, then the environment variable MUST be named OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and support a comma-separated list of case-sensitive known HTTP methods (this list MUST be a full override of the default known method, it is not a list of known methods in addition to the defaults).

I'm not sure if this instrumentation qualifies for If the HTTP instrumentation could end up converting valid HTTP request methods to _OTHER.
Thoughts?

The alternative would be to have a httpKnownMethods config option to this instrumentation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same code exists in instrumentation-fetch currently

Yeah I'm catching different things in each one, with lots to review some things don't stand out the first time around 😅 I guess a config option would be the way to do it, though I don't love that if we can help it. 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is new and already in the fetch instr I think it's okay to let it be as-is and we can look into it for a follow-up, and fix both of them at the same time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I opened #5677 for this.

Copy link
Copy Markdown
Member

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

Thank you 🙌

instrumentations: [new XMLHttpRequestInstrumentation()],
instrumentations: [
new XMLHttpRequestInstrumentation({
semconvStabilityOptIn: 'http',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: is this optin config necessary in this test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, not really.

It was necessary to make the old version of this test (see changes below) fail. Before this PR, this test was using the presence of the SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH span attr as a sign that PerformanceTiming resource usage was working (implementation in addSpanNetworkEvents from sdk-trace-web). When using only the newer semconv (via semconvStabilityOptIn: 'http',) that attr is not added -- for a different reason.

In a perfect "lots of tests have no maintenance or cognitive overhead"-world, this test would be run for all three OLD, STABLE, and DUPLICATE cases ... but I felt that was overkill given the exhaustive tests in xhr.test.ts.

@trentm trentm added this pull request to the merge queue May 9, 2025
Merged via the queue into open-telemetry:main with commit 0c21db4 May 9, 2025
18 checks passed
@trentm trentm deleted the trentm-instr-xhr-http-semconv-migration branch May 9, 2025 22:28
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Aug 26, 2025
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.

[instr-xhr] Add dual-emit option for HTTP stable attributes

2 participants