Skip to content

Commit b5bc416

Browse files
committed
Replaced set_data calls with set_attributes
1 parent 92fdf78 commit b5bc416

File tree

5 files changed

+75
-70
lines changed

5 files changed

+75
-70
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
2525
- The default of `traces_sample_rate` changed to `0`. Meaning: Incoming traces will be continued by default. For example, if your frontend sends a `sentry-trace/baggage` headers pair, your SDK will create Spans and send them to Sentry. (The default used to be `None` meaning by default no Spans where created, no matter what headers the frontend sent to your project.) See also: https://docs.sentry.io/platforms/python/configuration/options/#traces_sample_rate
2626
- `sentry_sdk.start_span` now only takes keyword arguments.
2727
- `sentry_sdk.start_transaction`/`sentry_sdk.start_span` no longer takes the following arguments: `span`, `parent_sampled`, `trace_id`, `span_id` or `parent_span_id`.
28-
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
28+
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
2929

3030
- Use it to continue an upstream trace with the `sentry-trace` and `baggage` headers.
3131

sentry_sdk/integrations/anthropic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _set_output_data(
159159
) -> None:
160160
"""
161161
Set output data for the span based on the AI response."""
162-
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, model)
162+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_MODEL, model)
163163
if should_send_default_pii() and integration.include_prompts:
164164
set_data_normalized(
165165
span,

sentry_sdk/integrations/langchain.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,16 @@ def on_llm_start(
180180
span = watched_span.span
181181

182182
if model:
183-
span.set_data(
183+
span.set_attribute(
184184
SPANDATA.GEN_AI_REQUEST_MODEL,
185185
model,
186186
)
187187

188188
ai_type = all_params.get("_type", "")
189189
if "anthropic" in ai_type:
190-
span.set_data(SPANDATA.GEN_AI_SYSTEM, "anthropic")
190+
span.set_attribute(SPANDATA.GEN_AI_SYSTEM, "anthropic")
191191
elif "openai" in ai_type:
192-
span.set_data(SPANDATA.GEN_AI_SYSTEM, "openai")
192+
span.set_attribute(SPANDATA.GEN_AI_SYSTEM, "openai")
193193

194194
for key, attribute in DATA_FIELDS.items():
195195
if key in all_params and all_params[key] is not None:
@@ -230,15 +230,15 @@ def on_chat_model_start(
230230
)
231231
span = watched_span.span
232232

233-
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
233+
span.set_attribute(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
234234
if model:
235-
span.set_data(SPANDATA.GEN_AI_REQUEST_MODEL, model)
235+
span.set_attribute(SPANDATA.GEN_AI_REQUEST_MODEL, model)
236236

237237
ai_type = all_params.get("_type", "")
238238
if "anthropic" in ai_type:
239-
span.set_data(SPANDATA.GEN_AI_SYSTEM, "anthropic")
239+
span.set_attribute(SPANDATA.GEN_AI_SYSTEM, "anthropic")
240240
elif "openai" in ai_type:
241-
span.set_data(SPANDATA.GEN_AI_SYSTEM, "openai")
241+
span.set_attribute(SPANDATA.GEN_AI_SYSTEM, "openai")
242242

243243
for key, attribute in DATA_FIELDS.items():
244244
if key in all_params and all_params[key] is not None:
@@ -299,14 +299,16 @@ def on_llm_end(
299299
try:
300300
response_model = generation.generation_info.get("model_name")
301301
if response_model is not None:
302-
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response_model)
302+
span.set_attribute(
303+
SPANDATA.GEN_AI_RESPONSE_MODEL, response_model
304+
)
303305
except AttributeError:
304306
pass
305307

306308
try:
307309
finish_reason = generation.generation_info.get("finish_reason")
308310
if finish_reason is not None:
309-
span.set_data(
311+
span.set_attribute(
310312
SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, finish_reason
311313
)
312314
except AttributeError:
@@ -393,12 +395,12 @@ def on_tool_start(
393395
)
394396
span = watched_span.span
395397

396-
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "execute_tool")
397-
span.set_data(SPANDATA.GEN_AI_TOOL_NAME, tool_name)
398+
span.set_attribute(SPANDATA.GEN_AI_OPERATION_NAME, "execute_tool")
399+
span.set_attribute(SPANDATA.GEN_AI_TOOL_NAME, tool_name)
398400

399401
tool_description = serialized.get("description")
400402
if tool_description is not None:
401-
span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool_description)
403+
span.set_attribute(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool_description)
402404

403405
if should_send_default_pii() and self.include_prompts:
404406
set_data_normalized(
@@ -517,13 +519,13 @@ def _record_token_usage(span: Span, response: Any) -> None:
517519
)
518520

519521
if input_tokens is not None:
520-
span.set_data(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
522+
span.set_attribute(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
521523

522524
if output_tokens is not None:
523-
span.set_data(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)
525+
span.set_attribute(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)
524526

525527
if total_tokens is not None:
526-
span.set_data(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)
528+
span.set_attribute(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)
527529

528530

529531
def _get_request_data(
@@ -653,10 +655,10 @@ def new_invoke(self, *args: Any, **kwargs: Any) -> Any:
653655
origin=LangchainIntegration.origin,
654656
) as span:
655657
if agent_name:
656-
span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name)
658+
span.set_attribute(SPANDATA.GEN_AI_AGENT_NAME, agent_name)
657659

658-
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent")
659-
span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, False)
660+
span.set_attribute(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent")
661+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_STREAMING, False)
660662

661663
if tools:
662664
set_data_normalized(
@@ -686,7 +688,7 @@ def new_invoke(self, *args: Any, **kwargs: Any) -> Any:
686688
and should_send_default_pii()
687689
and integration.include_prompts
688690
):
689-
span.set_data(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
691+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
690692

691693
return result
692694

@@ -711,10 +713,10 @@ def new_stream(self, *args: Any, **kwargs: Any) -> Any:
711713
span.__enter__()
712714

713715
if agent_name:
714-
span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name)
716+
span.set_attribute(SPANDATA.GEN_AI_AGENT_NAME, agent_name)
715717

716-
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent")
717-
span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, True)
718+
span.set_attribute(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent")
719+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_STREAMING, True)
718720

719721
if tools:
720722
set_data_normalized(
@@ -754,7 +756,7 @@ def new_iterator() -> Iterator[Any]:
754756
and should_send_default_pii()
755757
and integration.include_prompts
756758
):
757-
span.set_data(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
759+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
758760

759761
span.__exit__(None, None, None)
760762

@@ -772,7 +774,7 @@ async def new_iterator_async() -> AsyncIterator[Any]:
772774
and should_send_default_pii()
773775
and integration.include_prompts
774776
):
775-
span.set_data(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
777+
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_TEXT, output)
776778

777779
span.__exit__(None, None, None)
778780

tests/tracing/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def test_span_set_attributes(sentry_init, capture_events):
203203

204204
with sentry_sdk.start_span(name="test-root-span"):
205205
with start_span(op="test-span", name="test-span-name") as span:
206-
span.set_data("key0", "value0")
207-
span.set_data("key1", "value1")
206+
span.set_attribute("key0", "value0")
207+
span.set_attribute("key1", "value1")
208208

209209
span.set_attributes(
210210
{

0 commit comments

Comments
 (0)