Skip to content

refactor(instrumentation-http): Add back support for http semconv#5665

Merged
JamieDanielson merged 10 commits intoopen-telemetry:mainfrom
JamieDanielson:jamie.http-semconv-redo
May 12, 2025
Merged

refactor(instrumentation-http): Add back support for http semconv#5665
JamieDanielson merged 10 commits intoopen-telemetry:mainfrom
JamieDanielson:jamie.http-semconv-redo

Conversation

@JamieDanielson
Copy link
Copy Markdown
Member

@JamieDanielson JamieDanielson commented May 8, 2025

Which problem is this PR solving?

Short description of the changes

See #5646. This is re-implementing the support for dual-emit HTTP semantic conventions. I couldn't do a revert, because other changes have gone in since legacy attributes were removed. Much of this is copy-pasted though from the previous implementation, with some additional changes related to the new synthetic attributes, stable outgoing metrics, and shared utility for SemconvStability.

  • Updated local semconv constants file to include the experimental semantic conventions in use
  • Updated usages of unstable/experimental semantic conventions to use imports from local semconv package
  • Updated README to include table of semantic convention attributes emitted, including details on the migration
  • Added SemconvStability and set attributes accordingly
  • Update changelog to try to capture the changes that happened with the package, including moving the previous entry to a refactor.

Type of change

  • Sort of a revert, but sort of a re-implementation

How Has This Been Tested?

Unit tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

At this point it is mostly copy-paste from when
most of it was removed, but there have been a
few features since then (synthetic) and also a
few things were dropped and re-added already
like metrics. This also uses the new utility for
semconv stability instead of the old hardcoded enum.
Some things are still missing according to tests so will
need another pass. Doing this all in one PR is... a lot.
Possibly too much, but not sure if it is easier to
split either. It is just a lot of change.
| [`requireParentforOutgoingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L103) | Boolean | Require that is a parent span to create new span for outgoing requests. |
| [`requireParentforIncomingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L105) | Boolean | Require that is a parent span to create new span for incoming requests. |
| [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L107) | `object` | List of case insensitive HTTP headers to convert to span attributes. Client (outgoing requests, incoming responses) and server (incoming requests, outgoing responses) headers will be converted to span attributes in the form of `http.{request\|response}.header.header_name`, e.g. `http.response.header.content_length` |
Http instrumentation has a few [configuration options](https://github.com/open-telemetry/opentelemetry-js/blob/e1ec4026edae53a2dea3a9a604d6d21bb5e8d99f/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L60-L93) available to choose from.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note for reviewer: I removed the links from the table and put a general link up here. It makes the table easier to work with, but more importantly, the links were no longer linking to the right place and they are fragile anyway.

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.

+1 from me. I did the same in other instrumentation READMEs. Those links are a maintenance pain.

@trentm trentm mentioned this pull request May 9, 2025
3 tasks
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.03%. Comparing base (0665c85) to head (73049a9).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5665   +/-   ##
=======================================
  Coverage   95.03%   95.03%           
=======================================
  Files         310      310           
  Lines        7988     7992    +4     
  Branches     1607     1614    +7     
=======================================
+ Hits         7591     7595    +4     
  Misses        397      397           

see 1 file with indirect coverage changes

🚀 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.

@JamieDanielson JamieDanielson marked this pull request as ready for review May 9, 2025 21:31
@JamieDanielson JamieDanielson requested a review from a team as a code owner May 9, 2025 21:31
@JamieDanielson
Copy link
Copy Markdown
Member Author

I'm not quite sure how to handle the changelog. My first thought is to Skip Changelog, because it should just be reimplementing behavior that was already in the previous release. But there is the other PR in Breaking Changes, so we have to somehow offset the two.

Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Nice! A few nits is all. I think this is good.

Comment thread experimental/packages/opentelemetry-instrumentation-http/README.md Outdated
Comment thread experimental/packages/opentelemetry-instrumentation-http/README.md Outdated
Comment thread experimental/packages/opentelemetry-instrumentation-http/src/http.ts Outdated
[ATTR_NET_PEER_NAME]: hostname,
[ATTR_HTTP_HOST]: headers.host ?? `${hostname}:${port}`,
};

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.

nit unrelated to this change: I notice that #5488 added ATTR_USER_AGENT_ORIGINAL to newAttributes.

I think it probably should not have. Notice that newAttributes has a comment "Opt-in attributes left off for now" and per https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-client-span user_agent.original is Opt-in.

Possibly if enableSyntheticSourceDetection is configured, this could be considered as an Opt-in to also capture the raw user_agent.original.

Anyway, not for this PR.

Comment thread experimental/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts Outdated
Comment thread experimental/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts Outdated
@trentm
Copy link
Copy Markdown
Contributor

trentm commented May 10, 2025

I'm not quite sure how to handle the changelog.

The end result for release will be that there was churn in instr-http that should just amount to a refactor. So I'd move the earlier breaking-change one to a refactor(instrumentation-http): ... one that discusses the change/sorta-revert and links to both. It would be helpful context if someone finds some issue and comes looking for possible culprits in the changelog.

@JamieDanielson JamieDanielson changed the title feat(instrumentation-http): Add back support for http semconv refactor(instrumentation-http): Add back support for http semconv May 12, 2025
JamieDanielson and others added 2 commits May 12, 2025 10:55
Co-authored-by: Trent Mick <trentm@gmail.com>
@JamieDanielson
Copy link
Copy Markdown
Member Author

Thanks for the review and notes @trentm ! I've made the changes suggested (holding off on the user agent change since it went in separately as mentioned). Let me know if you see anything else.

Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

LGTM with a suggestion/correction for the content-length-related attrs.

Comment thread experimental/packages/opentelemetry-instrumentation-http/README.md Outdated
@JamieDanielson JamieDanielson added this pull request to the merge queue May 12, 2025
Merged via the queue into open-telemetry:main with commit 697e1d3 May 12, 2025
18 checks passed
@JamieDanielson JamieDanielson deleted the jamie.http-semconv-redo branch May 12, 2025 20:26
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-http] Add (back) dual-emit option for HTTP stable attributes Implement stable http semantic conventions

3 participants