-
-
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
|
Comment on lines
+28
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| ``` | ||
|
|
||
| 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 | | ||
| |---|---| | ||
| | Conversation | `sentry.span_group.conversation_id` | | ||
| | Session | `sentry.span_group.session_id` | | ||
|
|
||
| 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") | ||
| ``` | ||
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.