refactor(llmobs): centralize session_id injection in handleLLMObsInjection#9353
Conversation
Overall package sizeSelf size: 6.77 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
…ction Session_id was propagated via a separate path from the other LLMObs propagated values (parent_id, ml_app): it was stored on _trace.tags as a `_dd.p.*` tag and injected implicitly by the standard propagator, while the others are injected explicitly in handleLLMObsInjection. Per review feedback, handle all of them in one place. The in-process trace-level default now lives under an internal, non-`_dd.p.` key (_ml_obs.trace_session_id) for sibling inheritance only, and handleLLMObsInjection emits `_dd.p.llmobs_sid` alongside parent_id/ml_app. Session is now handled the same way as ml_app rather than as a standard-propagator special case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
e1dc73a to
3ed7f1c
Compare
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 87b59eb | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-15 14:35:35 Comparing candidate commit 87b59eb in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2322 metrics, 36 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9353 +/- ##
========================================
Coverage 96.64% 96.65%
========================================
Files 923 923
Lines 122844 122959 +115
Branches 20989 21055 +66
========================================
+ Hits 118723 118843 +120
+ Misses 4121 4116 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Yun-Kim
left a comment
There was a problem hiding this comment.
small docstring suggestion but lgtm otherwise
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ction (#9353) * refactor(llmobs): centralize session_id injection in handleLLMObsInjection Session_id was propagated via a separate path from the other LLMObs propagated values (parent_id, ml_app): it was stored on _trace.tags as a `_dd.p.*` tag and injected implicitly by the standard propagator, while the others are injected explicitly in handleLLMObsInjection. Per review feedback, handle all of them in one place. The in-process trace-level default now lives under an internal, non-`_dd.p.` key (_ml_obs.trace_session_id) for sibling inheritance only, and handleLLMObsInjection emits `_dd.p.llmobs_sid` alongside parent_id/ml_app. Session is now handled the same way as ml_app rather than as a standard-propagator special case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(llmobs): mention session id in handleLLMObsInjection docstring Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ction (#9353) * refactor(llmobs): centralize session_id injection in handleLLMObsInjection Session_id was propagated via a separate path from the other LLMObs propagated values (parent_id, ml_app): it was stored on _trace.tags as a `_dd.p.*` tag and injected implicitly by the standard propagator, while the others are injected explicitly in handleLLMObsInjection. Per review feedback, handle all of them in one place. The in-process trace-level default now lives under an internal, non-`_dd.p.` key (_ml_obs.trace_session_id) for sibling inheritance only, and handleLLMObsInjection emits `_dd.p.llmobs_sid` alongside parent_id/ml_app. Session is now handled the same way as ml_app rather than as a standard-propagator special case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(llmobs): mention session id in handleLLMObsInjection docstring Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ction (#9353) * refactor(llmobs): centralize session_id injection in handleLLMObsInjection Session_id was propagated via a separate path from the other LLMObs propagated values (parent_id, ml_app): it was stored on _trace.tags as a `_dd.p.*` tag and injected implicitly by the standard propagator, while the others are injected explicitly in handleLLMObsInjection. Per review feedback, handle all of them in one place. The in-process trace-level default now lives under an internal, non-`_dd.p.` key (_ml_obs.trace_session_id) for sibling inheritance only, and handleLLMObsInjection emits `_dd.p.llmobs_sid` alongside parent_id/ml_app. Session is now handled the same way as ml_app rather than as a standard-propagator special case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(llmobs): mention session id in handleLLMObsInjection docstring Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ction (#9353) * refactor(llmobs): centralize session_id injection in handleLLMObsInjection Session_id was propagated via a separate path from the other LLMObs propagated values (parent_id, ml_app): it was stored on _trace.tags as a `_dd.p.*` tag and injected implicitly by the standard propagator, while the others are injected explicitly in handleLLMObsInjection. Per review feedback, handle all of them in one place. The in-process trace-level default now lives under an internal, non-`_dd.p.` key (_ml_obs.trace_session_id) for sibling inheritance only, and handleLLMObsInjection emits `_dd.p.llmobs_sid` alongside parent_id/ml_app. Session is now handled the same way as ml_app rather than as a standard-propagator special case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(llmobs): mention session id in handleLLMObsInjection docstring Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
What does this PR do?
Centralizes
session_idcross-service injection intohandleLLMObsInjection, so all four propagated LLMObs values (parent_id,ml_app,session_id, sampling) are emitted in one place.Motivation
Follow-up to the session-propagation work (#9279). Session was handled on a different path from the other propagated values: it was stored on
_trace.tagsunder the_dd.p.llmobs_sidkey and injected implicitly by the standard propagator's_injectTags, whileparent_id/ml_appare injected explicitly inhandleLLMObsInjection.It was also a subtle correctness gap:
_injectTagsonly runs when thedatadoginject propagation style is enabled, whereashandleLLMObsInjectionruns regardless. So with a non-datadoginject style, session would silently stop propagating whileparent_id/ml_appstill did.Changes
_dd.p.key_ml_obs.trace_session_id(constantSESSION_ID_TRACE_DEFAULT_KEY). It is used only for in-process sibling inheritance, so the standard propagator no longer auto-injects it.handleLLMObsInjectionnow emits_dd.p.llmobs_sidalongsideparent_id/ml_app, reading the active span's session (mlObsSpanTags[SESSION_ID]) with fallbacks to the trace default and the extracted_dd.p.llmobs_sid.registerLLMObsSpanresolves a new span's session as explicit → parent → in-process trace default → cross-service propagated._setTagseeds the internal trace-default key (first-writer-wins).Testing
tagger.spec.js: trace-default establishment/inheritance/override updated to the internal key; added a case for inheriting an upstream-propagated session.index.spec.js: added injection cases for session from the active span and from the trace-level default.packages/dd-trace/test/llmobs/{tagger,index,sdk/index}.spec.jsall pass (133 + 100).Claude session:
3b93fe65-18d2-413f-b53e-2d95f370e1edResume:
claude --resume 3b93fe65-18d2-413f-b53e-2d95f370e1ed🤖 Generated with Claude Code