fix(llmobs): set session ID on span if annotated as a tag #13220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes a fix to how session ID is set on a LLM Obs span.
Session ID (for session tracking) can be explicitly set when starting a span via
LLMObs._start_span(session_id=...)
. We then set this both as the span'ssession_id
field and as a tag on the span,"session_id:..."
.However, currently session ID can also be set by using
LLMObs.annotate/annotation_context()
as a tag. This is meant for use cases where the session ID may not be immediately available. The issue here is that when setting as a tag, we don't actually set that value on the span's top levelsession_id
field and only set it as a tag. This means that our backend and other event queries made by other products (like RUM/APM) can't 100% rely on that top level event field even if a user did indeed set it as a tag. (queries based on tags are also slower/more expensive than top-level queries)This fixes the issue by adding a step when setting tags via
LLMObs.annotate/annotation_context()
that we also add asession_id
tag as the span's top-levelsession_id
field.Checklist
Reviewer Checklist