Skip to content

add new baggage APIs which act on currently active baggage #5365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ida613
Copy link
Collaborator

@ida613 ida613 commented Mar 5, 2025

What does this PR do?

Provides users with a set of global functions which act on the currently active baggage of implicitly propagated context

Motivation

From the baggage RFC:

Generally speaking, the Baggage API should be exposed on the Context object or class on APM SDKs where the context itself is exposed. On SDKs where context is implicit, the Baggage API can be exposed through static/global functions that act on the currently active baggage.

Added return statements because

If any language implements baggage as an immutable object or data structure (as defined in the OpenTelemetry Baggage API specification), the functions above that modify baggage (set and remove) will need to return the new (modified) baggage object. However, if baggage is mutable and modified in place, those functions don't need to return a value.

Plugin Checklist

Additional Notes

Copy link

github-actions bot commented Mar 5, 2025

Overall package size

Self size: 9.33 MB
Deduped: 102.57 MB
No deduping: 103.09 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | @datadog/libdatadog | 0.5.1 | 29.73 MB | 29.73 MB | | @datadog/native-appsec | 8.5.2 | 19.33 MB | 19.34 MB | | @datadog/native-iast-taint-tracking | 3.3.1 | 13.99 MB | 13.99 MB | | @datadog/pprof | 5.7.1 | 9.51 MB | 9.88 MB | | @opentelemetry/core | 1.30.1 | 908.66 kB | 7.16 MB | | protobufjs | 7.4.0 | 2.77 MB | 5.42 MB | | @datadog/wasm-js-rewriter | 4.0.0 | 2.85 MB | 3.58 MB | | @datadog/native-metrics | 3.1.1 | 1.02 MB | 1.43 MB | | @opentelemetry/api | 1.8.0 | 1.21 MB | 1.21 MB | | import-in-the-middle | 1.13.1 | 117.64 kB | 839.26 kB | | source-map | 0.7.4 | 226 kB | 226 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | lru-cache | 7.18.3 | 133.92 kB | 133.92 kB | | pprof-format | 2.1.0 | 111.69 kB | 111.69 kB | | @datadog/sketches-js | 2.1.1 | 109.9 kB | 109.9 kB | | lodash.sortby | 4.7.0 | 75.76 kB | 75.76 kB | | ignore | 5.3.2 | 53.63 kB | 53.63 kB | | istanbul-lib-coverage | 3.2.0 | 29.34 kB | 29.34 kB | | rfdc | 1.4.1 | 27.15 kB | 27.15 kB | | @isaacs/ttlcache | 1.4.1 | 25.2 kB | 25.2 kB | | dc-polyfill | 0.1.8 | 25.08 kB | 25.08 kB | | tlhunter-sorted-set | 0.1.0 | 24.94 kB | 24.94 kB | | shell-quote | 1.8.2 | 23.54 kB | 23.54 kB | | limiter | 1.1.5 | 23.17 kB | 23.17 kB | | retry | 0.13.1 | 18.85 kB | 18.85 kB | | semifies | 1.0.0 | 15.84 kB | 15.84 kB | | jest-docblock | 29.7.0 | 8.99 kB | 12.76 kB | | crypto-randomuuid | 1.0.0 | 11.18 kB | 11.18 kB | | ttl-set | 1.0.0 | 4.61 kB | 9.69 kB | | path-to-regexp | 0.1.12 | 6.6 kB | 6.6 kB | | koalas | 1.0.2 | 6.47 kB | 6.47 kB | | module-details-from-path | 1.0.3 | 4.47 kB | 4.47 kB |

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

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.37%. Comparing base (28eaa41) to head (433b9e2).
Report is 104 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5365      +/-   ##
==========================================
- Coverage   79.47%   79.37%   -0.10%     
==========================================
  Files         509      515       +6     
  Lines       22811    23437     +626     
==========================================
+ Hits        18128    18603     +475     
- Misses       4683     4834     +151     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Mar 5, 2025

Datadog Report

Branch report: ida613/global-baggage
Commit report: 6ac3235
Test service: dd-trace-js-integration-tests

✅ 0 Failed, 930 Passed, 0 Skipped, 14m 54.99s Total Time

@pr-commenter
Copy link

pr-commenter bot commented Mar 17, 2025

Benchmarks

Benchmark execution time: 2025-04-14 22:48:56

Comparing candidate commit 433b9e2 in PR branch ida613/global-baggage with baseline commit 28eaa41 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 915 metrics, 18 unstable metrics.

@ida613 ida613 changed the title WIP: add new baggage APIs which act on currently active baggage add new baggage APIs which act on currently active baggage Mar 17, 2025
@ida613 ida613 marked this pull request as ready for review March 17, 2025 21:17
@ida613 ida613 requested a review from a team as a code owner March 17, 2025 21:18
@ida613 ida613 requested review from rochdev and BridgeAR March 20, 2025 17:46
Copy link
Collaborator

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

The transport itself seems fine, I just don't see how this is integrated and exposed to users. That is something that still needs to be addressed :)

@ida613
Copy link
Collaborator Author

ida613 commented Mar 26, 2025

The transport itself seems fine, I just don't see how this is integrated and exposed to users. That is something that still needs to be addressed :)

Should I update our api documentation? Are there other ways we can expose global functions to users?

@ida613
Copy link
Collaborator Author

ida613 commented Apr 1, 2025

@BridgeAR Hey Ruben, I reached out to Rachel, who implemented context-based public baggage APIs for golang, and there is really nothing left to do except maybe for adding the APIs to the public doc. Are you able to give this PR a go? Thank you :)

@ida613
Copy link
Collaborator Author

ida613 commented Apr 3, 2025

@BridgeAR sorry about misunderstanding you before! I have added the APIs to NoopProxy to make them accessible to the public. Please let me know if this solution is fine and I'll update the test :)

Copy link
Collaborator

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Thanks for exposing the API now!
While it would work that way, it should not be on the no op proxy class. The name is an indicator for no operation, so all methods on that class should just do nothing. Instead, the API should probably be exposed on the main Tracer proxy.
Can you please also add tests that actually use the API as an integration test and also add documentation for it?

@ida613
Copy link
Collaborator Author

ida613 commented Apr 4, 2025

@BridgeAR thank you for your review Ruben! :) This is awkward, technically baggage is separate from tracing and does not require tracing to be enabled to work

@BridgeAR
Copy link
Collaborator

BridgeAR commented Apr 4, 2025

@ida613 that is fair! I feel I am actually not the right person to suggest where to add the functionality in that case. I just know that it should not be the NoopProxy.

@rochdev do you have an opinion about that?

@bengl
Copy link
Collaborator

bengl commented Apr 5, 2025

The methods should be added to the proxy in dd-trace/src/proxy.js. No-op versions of this should be added to the NoopTracer proxy (i.e. the one currently in this file).

@rochdev
Copy link
Member

rochdev commented Apr 6, 2025

This is awkward, technically baggage is separate from tracing and does not require tracing to be enabled to work

Unfortunately the original design of the library was only a tracer (hence the name dd-trace) and the default export ended up being the tracer itself. This means that anything, whether or not related to tracing, needs to be on the tracer to be exposed. Of course that could be directly on the proxy instead of the underlying tracer, but from a public API perspective they are the effectively the same. The underlying implementation however should indeed not be coupled to tracing.

@ida613
Copy link
Collaborator Author

ida613 commented Apr 7, 2025

Made changes as Bryan suggested! Will work on tests now

@ida613
Copy link
Collaborator Author

ida613 commented Apr 8, 2025

@BridgeAR @rochdev I've updated the tests. Let me know if there is anything else to update :)

Copy link
Collaborator

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

The code is looking good to me!

I believe we still need some documentation for it. Otherwise it would be pretty much "in the wild" :D
I believe our TS definition is pretty much that documentation, if I am not mistaken.

@ida613
Copy link
Collaborator Author

ida613 commented Apr 15, 2025

@BridgeAR added the TS definition! let me know if it's good to go :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants