Skip to content

Commit f7ab39b

Browse files
ericapisaniclaude
andauthored
feat(consts): Add updated span convention constants to SPANDATA (#6093)
## Summary Aligns `sentry_sdk.consts.SPANDATA` with the current Sentry conventions at https://getsentry.github.io/sentry-conventions/attributes/. Several attribute names the SDK exposed as the canonical constants have been deprecated upstream, and several active replacements had no SDK constant. Changes are purely additive: - Adds a `.. deprecated::` docstring note (matching the existing `AI_*` pattern) to 15 existing `SPANDATA` constants, naming the replacement. - Adds 13 new constants for the replacement attributes, with descriptions/examples grounded in the conventions page. - Existing string values are preserved byte-for-byte, so current emitters and consumers are unaffected. ### Deprecation + replacement map | Deprecated constant | Value | New constant | Value | |---|---|---|---| | `CODE_FILEPATH` | `code.filepath` | `CODE_FILE_PATH` | `code.file.path` | | `CODE_FUNCTION` | `code.function` | `CODE_FUNCTION_NAME` | `code.function.name` | | `CODE_LINENO` | `code.lineno` | `CODE_LINE_NUMBER` | `code.line.number` | | `CODE_NAMESPACE` | `code.namespace` | `CODE_FUNCTION_NAME` (consolidated) | `code.function.name` | | `DB_NAME` | `db.name` | `DB_NAMESPACE` | `db.namespace` | | `DB_OPERATION` | `db.operation` | `DB_OPERATION_NAME` | `db.operation.name` | | `DB_SYSTEM` | `db.system` | `DB_SYSTEM_NAME` | `db.system.name` | | `HTTP_METHOD` | `http.method` | `HTTP_REQUEST_METHOD` | `http.request.method` | | `GEN_AI_REQUEST_AVAILABLE_TOOLS` | `gen_ai.request.available_tools` | `GEN_AI_TOOL_DEFINITIONS` | `gen_ai.tool.definitions` | | `GEN_AI_REQUEST_MESSAGES` | `gen_ai.request.messages` | `GEN_AI_INPUT_MESSAGES` | `gen_ai.input.messages` | | `GEN_AI_RESPONSE_TEXT` | `gen_ai.response.text` | `GEN_AI_OUTPUT_MESSAGES` | `gen_ai.output.messages` | | `GEN_AI_RESPONSE_TOOL_CALLS` | `gen_ai.response.tool_calls` | `GEN_AI_OUTPUT_MESSAGES` | `gen_ai.output.messages` | | `GEN_AI_SYSTEM` | `gen_ai.system` | `GEN_AI_PROVIDER_NAME` | `gen_ai.provider.name` | | `GEN_AI_TOOL_INPUT` | `gen_ai.tool.input` | `GEN_AI_TOOL_CALL_ARGUMENTS` | `gen_ai.tool.call.arguments` | | `GEN_AI_TOOL_OUTPUT` | `gen_ai.tool.output` | `GEN_AI_TOOL_CALL_RESULT` | `gen_ai.tool.call.result` | ### Follow-up (not in this PR) Integration call sites still reference the deprecated constants; migrating emitters to the new ones is scoped for follow-up PRs. `CODE_NAMESPACE` in particular is a non-1:1 rename (the namespace should be merged into the function name string at the producer side). ## Test plan - [x] `tox -e ruff` passes - [x] `tox -e mypy` passes - [ ] No behavioral change — existing string values preserved, so no additional runtime tests required Fixes PY-2380 Fixes #6092 Co-authored-by: Claude Opus 4.7 <[email protected]>
1 parent 96ccabe commit f7ab39b

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

sentry_sdk/consts.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,54 @@ class SPANDATA:
406406

407407
CODE_FILEPATH = "code.filepath"
408408
"""
409+
.. deprecated::
410+
This attribute is deprecated. Use CODE_FILE_PATH instead.
411+
412+
The source code file name that identifies the code unit as uniquely as possible (preferably an absolute file path).
413+
Example: "/app/myapplication/http/handler/server.py"
414+
"""
415+
416+
CODE_FILE_PATH = "code.file.path"
417+
"""
409418
The source code file name that identifies the code unit as uniquely as possible (preferably an absolute file path).
410419
Example: "/app/myapplication/http/handler/server.py"
411420
"""
412421

413422
CODE_FUNCTION = "code.function"
414423
"""
424+
.. deprecated::
425+
This attribute is deprecated. Use CODE_FUNCTION_NAME instead.
426+
427+
The method or function name, or equivalent (usually rightmost part of the code unit's name).
428+
Example: "server_request"
429+
"""
430+
431+
CODE_FUNCTION_NAME = "code.function.name"
432+
"""
415433
The method or function name, or equivalent (usually rightmost part of the code unit's name).
416434
Example: "server_request"
417435
"""
418436

419437
CODE_LINENO = "code.lineno"
420438
"""
439+
.. deprecated::
440+
This attribute is deprecated. Use CODE_LINE_NUMBER instead.
441+
421442
The line number in `code.filepath` best representing the operation. It SHOULD point within the code unit named in `code.function`.
422443
Example: 42
423444
"""
424445

446+
CODE_LINE_NUMBER = "code.line.number"
447+
"""
448+
The line number in `code.file.path` best representing the operation. It SHOULD point within the code unit named in `code.function.name`.
449+
Example: 42
450+
"""
451+
425452
CODE_NAMESPACE = "code.namespace"
426453
"""
454+
.. deprecated::
455+
This attribute is deprecated. Use CODE_FUNCTION_NAME instead; the namespace should be included within the function name.
456+
427457
The "namespace" within which `code.function` is defined. Usually the qualified class or module name, such that `code.namespace` + some separator + `code.function` form a unique identifier for the code unit.
428458
Example: "http.handler"
429459
"""
@@ -437,10 +467,19 @@ class SPANDATA:
437467

438468
DB_NAME = "db.name"
439469
"""
470+
.. deprecated::
471+
This attribute is deprecated. Use DB_NAMESPACE instead.
472+
440473
The name of the database being accessed. For commands that switch the database, this should be set to the target database (even if the command fails).
441474
Example: myDatabase
442475
"""
443476

477+
DB_NAMESPACE = "db.namespace"
478+
"""
479+
The name of the database being accessed.
480+
Example: "customers"
481+
"""
482+
444483
DB_DRIVER_NAME = "db.driver.name"
445484
"""
446485
The name of the database driver being used for the connection.
@@ -449,18 +488,36 @@ class SPANDATA:
449488

450489
DB_OPERATION = "db.operation"
451490
"""
491+
.. deprecated::
492+
This attribute is deprecated. Use DB_OPERATION_NAME instead.
493+
452494
The name of the operation being executed, e.g. the MongoDB command name such as findAndModify, or the SQL keyword.
453495
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
454496
Example: findAndModify, HMSET, SELECT
455497
"""
456498

499+
DB_OPERATION_NAME = "db.operation.name"
500+
"""
501+
The name of the operation being executed.
502+
Example: "SELECT"
503+
"""
504+
457505
DB_SYSTEM = "db.system"
458506
"""
507+
.. deprecated::
508+
This attribute is deprecated. Use DB_SYSTEM_NAME instead.
509+
459510
An identifier for the database management system (DBMS) product being used.
460511
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
461512
Example: postgresql
462513
"""
463514

515+
DB_SYSTEM_NAME = "db.system.name"
516+
"""
517+
An identifier for the database management system (DBMS) product being used. See OpenTelemetry's list of well-known DBMS identifiers.
518+
Example: "postgresql"
519+
"""
520+
464521
DB_USER = "db.user"
465522
"""
466523
The name of the database user used for connecting to the database.
@@ -530,10 +587,19 @@ class SPANDATA:
530587

531588
GEN_AI_RESPONSE_TEXT = "gen_ai.response.text"
532589
"""
590+
.. deprecated::
591+
This attribute is deprecated. Use GEN_AI_OUTPUT_MESSAGES instead.
592+
533593
The model's response text messages.
534594
Example: ["The weather in Paris is rainy and overcast, with temperatures around 57°F", "The weather in London is sunny and warm, with temperatures around 65°F"]
535595
"""
536596

597+
GEN_AI_OUTPUT_MESSAGES = "gen_ai.output.messages"
598+
"""
599+
The model's response messages. It has to be a stringified version of an array of message objects, which can include text responses and tool calls.
600+
Example: [{"role": "assistant", "parts": [{"type": "text", "content": "The weather in Paris is currently rainy with a temperature of 57°F."}], "finish_reason": "stop"}]
601+
"""
602+
537603
GEN_AI_RESPONSE_TIME_TO_FIRST_TOKEN = "gen_ai.response.time_to_first_token"
538604
"""
539605
The time it took to receive the first token from the model.
@@ -542,16 +608,28 @@ class SPANDATA:
542608

543609
GEN_AI_RESPONSE_TOOL_CALLS = "gen_ai.response.tool_calls"
544610
"""
611+
.. deprecated::
612+
This attribute is deprecated. Use GEN_AI_OUTPUT_MESSAGES instead.
613+
545614
The tool calls in the model's response.
546615
Example: [{"name": "get_weather", "arguments": {"location": "Paris"}}]
547616
"""
548617

549618
GEN_AI_REQUEST_AVAILABLE_TOOLS = "gen_ai.request.available_tools"
550619
"""
620+
.. deprecated::
621+
This attribute is deprecated. Use GEN_AI_TOOL_DEFINITIONS instead.
622+
551623
The available tools for the model.
552624
Example: [{"name": "get_weather", "description": "Get the weather for a given location"}, {"name": "get_news", "description": "Get the news for a given topic"}]
553625
"""
554626

627+
GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions"
628+
"""
629+
The list of source system tool definitions available to the GenAI agent or model.
630+
Example: [{"type": "function", "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}}, "required": ["location", "unit"]}}]
631+
"""
632+
555633
GEN_AI_REQUEST_FREQUENCY_PENALTY = "gen_ai.request.frequency_penalty"
556634
"""
557635
The frequency penalty parameter used to reduce repetitiveness of generated tokens.
@@ -572,10 +650,19 @@ class SPANDATA:
572650

573651
GEN_AI_REQUEST_MESSAGES = "gen_ai.request.messages"
574652
"""
653+
.. deprecated::
654+
This attribute is deprecated. Use GEN_AI_INPUT_MESSAGES instead.
655+
575656
The messages passed to the model. The "content" can be a string or an array of objects.
576657
Example: [{role: "system", "content: "Generate a random number."}, {"role": "user", "content": [{"text": "Generate a random number between 0 and 10.", "type": "text"}]}]
577658
"""
578659

660+
GEN_AI_INPUT_MESSAGES = "gen_ai.input.messages"
661+
"""
662+
The messages passed to the model. It has to be a stringified version of an array of objects. Role values must be "user", "assistant", "tool", or "system".
663+
Example: [{"role": "user", "parts": [{"type": "text", "content": "Weather in Paris?"}]}, {"role": "assistant", "parts": [{"type": "tool_call", "id": "call_VSPygqKTWdrhaFErNvMV18Yl", "name": "get_weather", "arguments": {"location": "Paris"}}]}, {"role": "tool", "parts": [{"type": "tool_call_response", "id": "call_VSPygqKTWdrhaFErNvMV18Yl", "result": "rainy, 57°F"}]}]
664+
"""
665+
579666
GEN_AI_REQUEST_MODEL = "gen_ai.request.model"
580667
"""
581668
The model identifier being used for the request.
@@ -614,10 +701,19 @@ class SPANDATA:
614701

615702
GEN_AI_SYSTEM = "gen_ai.system"
616703
"""
704+
.. deprecated::
705+
This attribute is deprecated. Use GEN_AI_PROVIDER_NAME instead.
706+
617707
The name of the AI system being used.
618708
Example: "openai"
619709
"""
620710

711+
GEN_AI_PROVIDER_NAME = "gen_ai.provider.name"
712+
"""
713+
The Generative AI provider as identified by the client or server instrumentation.
714+
Example: "openai"
715+
"""
716+
621717
GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description"
622718
"""
623719
The description of the tool being used.
@@ -626,10 +722,19 @@ class SPANDATA:
626722

627723
GEN_AI_TOOL_INPUT = "gen_ai.tool.input"
628724
"""
725+
.. deprecated::
726+
This attribute is deprecated. Use GEN_AI_TOOL_CALL_ARGUMENTS instead.
727+
629728
The input of the tool being used.
630729
Example: {"location": "Paris"}
631730
"""
632731

732+
GEN_AI_TOOL_CALL_ARGUMENTS = "gen_ai.tool.call.arguments"
733+
"""
734+
The arguments of the tool call. It has to be a stringified version of the arguments to the tool.
735+
Example: {"location": "Paris"}
736+
"""
737+
633738
GEN_AI_TOOL_NAME = "gen_ai.tool.name"
634739
"""
635740
The name of the tool being used.
@@ -638,10 +743,19 @@ class SPANDATA:
638743

639744
GEN_AI_TOOL_OUTPUT = "gen_ai.tool.output"
640745
"""
746+
.. deprecated::
747+
This attribute is deprecated. Use GEN_AI_TOOL_CALL_RESULT instead.
748+
641749
The output of the tool being used.
642750
Example: "rainy, 57°F"
643751
"""
644752

753+
GEN_AI_TOOL_CALL_RESULT = "gen_ai.tool.call.result"
754+
"""
755+
The result of the tool call. It has to be a stringified version of the result of the tool.
756+
Example: "rainy, 57°F"
757+
"""
758+
645759
GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens"
646760
"""
647761
The number of tokens in the input.
@@ -692,6 +806,15 @@ class SPANDATA:
692806

693807
HTTP_METHOD = "http.method"
694808
"""
809+
.. deprecated::
810+
This attribute is deprecated. Use HTTP_REQUEST_METHOD instead.
811+
812+
The HTTP method used.
813+
Example: GET
814+
"""
815+
816+
HTTP_REQUEST_METHOD = "http.request.method"
817+
"""
695818
The HTTP method used.
696819
Example: GET
697820
"""

0 commit comments

Comments
 (0)