-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(sdk): Add sentry.span_group develop docs #17277
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
vgrozdanic
wants to merge
2
commits into
master
Choose a base branch
from
docs/span-groups
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| title: Span Groups | ||
| --- | ||
|
|
||
| <Alert level="info"> | ||
| This document uses key words such as "MUST", "SHOULD", and "MAY" as defined | ||
| in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) to indicate requirement | ||
| levels. | ||
| </Alert> | ||
|
|
||
| Span groups provide logical grouping of spans that can cross trace boundaries. While traces represent a single causal chain of operations, span groups connect spans that share a logical relationship — such as belonging to the same AI conversation or user session — even when those spans live in different traces. | ||
|
|
||
| ## Motivation | ||
|
|
||
| Traces are the only built-in grouping mechanism in OpenTelemetry, but many real-world concepts don't map cleanly to a single trace: | ||
|
|
||
| - **AI conversations** can span multiple sessions and traces, and multiple conversations can exist within the same trace. | ||
| - **User sessions** (e.g. a single visit to a webpage) may produce multiple traces, or a single trace may cover multiple sessions. | ||
|
|
||
| These relationships require a lightweight, extensible grouping concept that works across trace boundaries without infrastructure changes. | ||
|
|
||
| ## Protocol | ||
|
|
||
| Span groups are regular span attributes under the `sentry.span_group` namespace. Each group is identified by a key (the concept) and a value (the group ID): | ||
|
|
||
| ```json | ||
| { | ||
| "sentry.span_group.conversation_id": "conv_88234", | ||
| "sentry.span_group.session_id": "sess_00192" | ||
| } | ||
| ``` | ||
|
|
||
| A span **MAY** belong to multiple groups simultaneously. | ||
|
|
||
| ### Attribute Format | ||
|
|
||
| In the Span v2 wire format, span group attributes follow the standard [attribute encoding](/sdk/foundations/state-management/scopes/attributes/): | ||
|
|
||
| ```json | ||
| { | ||
| "attributes": { | ||
| "sentry.span_group.conversation_id": { | ||
| "type": "string", | ||
| "value": "conv_88234" | ||
| }, | ||
| "sentry.span_group.session_id": { | ||
| "type": "string", | ||
| "value": "sess_00192" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Naming Convention | ||
|
|
||
| New span group concepts **MUST** use a `<concept>_id` suffix under the `sentry.span_group` namespace. For example: | ||
|
|
||
| | Concept | Attribute Key | Notes | | ||
| |---|---|---| | ||
| | Conversation | `sentry.span_group.conversation_id` | The conversation ID originates from the model provider and can be any type. It **MUST** be stringified before being set as an attribute. | | ||
| | Session | `sentry.span_group.session_id` | Session grouping is still in an early phase. It is listed here as an example of how the namespace extends, not as a formal definition of what a session is. | | ||
|
|
||
| Values **MUST** be non-empty strings. | ||
|
|
||
| ## Propagation | ||
|
|
||
| Span groups **SHOULD** be propagated between services via the `baggage` header, following the same mechanism as [trace propagation](/sdk/telemetry/spans/span-trace-propagation/): | ||
|
|
||
| ``` | ||
| baggage: sentry.span_group.conversation_id=conv_88234,sentry.span_group.session_id=sess_00192 | ||
| ``` | ||
|
|
||
| When a downstream service receives span group entries in baggage, it **SHOULD** apply them to all spans created within that context. | ||
|
|
||
| ## SDK Implementation | ||
|
|
||
| SDKs **MUST** allow users to set span group attributes via the standard span attributes API. No dedicated public API is required — span groups are just attributes. | ||
|
|
||
| ```js {tabTitle:JavaScript} | ||
| Sentry.startSpan( | ||
| { | ||
| name: "ai.chat", | ||
| attributes: { | ||
| "sentry.span_group.conversation_id": "conv_88234", | ||
| "sentry.span_group.session_id": "sess_00192", | ||
| }, | ||
| }, | ||
| () => { | ||
| // ... | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ```python {tabTitle:Python} | ||
| with sentry_sdk.start_span(name="ai.chat") as span: | ||
| span.set_attribute("sentry.span_group.conversation_id", "conv_88234") | ||
| span.set_attribute("sentry.span_group.session_id", "sess_00192") | ||
| ``` | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should likely specify the value used here, using uuids as for trace ids would work well, imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conversation id can be anything because it usually comes from the model provider (I believe OpenAI has ints as conversationId). I'll mention it.
For sessions, I'd rather not specify the exact value because that concept still requires more thinking and it is not yet fully defined how it will work, here I named it more as an example of how it would work under
sentry.span_group, and until we have more details on it, I'd keep the value as vague/open as possible.