Skip to content

Commit cd0c8ff

Browse files
authored
Deprecate Span.set_data() (#4261)
Refs #4102
1 parent e8f99b3 commit cd0c8ff

27 files changed

+119
-106
lines changed

MIGRATION_GUIDE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
172172

173173
### Deprecated
174174

175-
- `sentry_sdk.start_transaction` is deprecated. Use `sentry_sdk.start_span` instead.
175+
- `sentry_sdk.start_transaction()` is deprecated. Use `sentry_sdk.start_span()` instead.
176+
- `Span.set_data()` is deprecated. Use `Span.set_attribute()` instead.
176177

177178
## Upgrading to 2.0
178179

sentry_sdk/ai/monitoring.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def sync_wrapped(*args, **kwargs):
3939
for k, v in kwargs.pop("sentry_tags", {}).items():
4040
span.set_tag(k, v)
4141
for k, v in kwargs.pop("sentry_data", {}).items():
42-
span.set_data(k, v)
42+
span.set_attribute(k, v)
4343
if curr_pipeline:
44-
span.set_data("ai.pipeline.name", curr_pipeline)
44+
span.set_attribute("ai.pipeline.name", curr_pipeline)
4545
return f(*args, **kwargs)
4646
else:
4747
_ai_pipeline_name.set(description)
@@ -70,9 +70,9 @@ async def async_wrapped(*args, **kwargs):
7070
for k, v in kwargs.pop("sentry_tags", {}).items():
7171
span.set_tag(k, v)
7272
for k, v in kwargs.pop("sentry_data", {}).items():
73-
span.set_data(k, v)
73+
span.set_attribute(k, v)
7474
if curr_pipeline:
75-
span.set_data("ai.pipeline.name", curr_pipeline)
75+
span.set_attribute("ai.pipeline.name", curr_pipeline)
7676
return await f(*args, **kwargs)
7777
else:
7878
_ai_pipeline_name.set(description)
@@ -104,7 +104,7 @@ def record_token_usage(
104104
# type: (Span, Optional[int], Optional[int], Optional[int]) -> None
105105
ai_pipeline_name = get_ai_pipeline_name()
106106
if ai_pipeline_name:
107-
span.set_data("ai.pipeline.name", ai_pipeline_name)
107+
span.set_attribute("ai.pipeline.name", ai_pipeline_name)
108108
if prompt_tokens is not None:
109109
span.set_measurement("ai_prompt_tokens_used", value=prompt_tokens)
110110
if completion_tokens is not None:

sentry_sdk/ai/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def _normalize_data(data):
2929
def set_data_normalized(span, key, value):
3030
# type: (Span, str, Any) -> None
3131
normalized = _normalize_data(value)
32-
span.set_data(key, normalized)
32+
span.set_attribute(key, normalized)

sentry_sdk/integrations/aiohttp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def on_request_start(session, trace_config_ctx, params):
245245
data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment
246246

247247
for key, value in data.items():
248-
span.set_data(key, value)
248+
span.set_attribute(key, value)
249249

250250
client = sentry_sdk.get_client()
251251

@@ -291,7 +291,7 @@ async def on_request_end(session, trace_config_ctx, params):
291291

292292
span = trace_config_ctx.span
293293
span.set_http_status(int(params.response.status))
294-
span.set_data("reason", params.response.reason)
294+
span.set_attribute("reason", params.response.reason)
295295
span.finish()
296296

297297
trace_config = TraceConfig()

sentry_sdk/integrations/anthropic.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ def _add_ai_data_to_span(
121121
with capture_internal_exceptions():
122122
if should_send_default_pii() and integration.include_prompts:
123123
complete_message = "".join(content_blocks)
124-
span.set_data(
124+
span.set_attribute(
125125
SPANDATA.AI_RESPONSES,
126126
[{"type": "text", "text": complete_message}],
127127
)
128128
total_tokens = input_tokens + output_tokens
129129
record_token_usage(span, input_tokens, output_tokens, total_tokens)
130-
span.set_data(SPANDATA.AI_STREAMING, True)
130+
span.set_attribute(SPANDATA.AI_STREAMING, True)
131131

132132

133133
def _sentry_patched_create_common(f, *args, **kwargs):
@@ -159,15 +159,17 @@ def _sentry_patched_create_common(f, *args, **kwargs):
159159
model = kwargs.get("model")
160160

161161
with capture_internal_exceptions():
162-
span.set_data(SPANDATA.AI_MODEL_ID, model)
163-
span.set_data(SPANDATA.AI_STREAMING, False)
162+
span.set_attribute(SPANDATA.AI_MODEL_ID, model)
163+
span.set_attribute(SPANDATA.AI_STREAMING, False)
164164

165165
if should_send_default_pii() and integration.include_prompts:
166-
span.set_data(SPANDATA.AI_INPUT_MESSAGES, messages)
166+
span.set_attribute(SPANDATA.AI_INPUT_MESSAGES, messages)
167167

168168
if hasattr(result, "content"):
169169
if should_send_default_pii() and integration.include_prompts:
170-
span.set_data(SPANDATA.AI_RESPONSES, _get_responses(result.content))
170+
span.set_attribute(
171+
SPANDATA.AI_RESPONSES, _get_responses(result.content)
172+
)
171173
_calculate_token_usage(result, span)
172174
span.__exit__(None, None, None)
173175

@@ -215,7 +217,7 @@ async def new_iterator_async():
215217
result._iterator = new_iterator()
216218

217219
else:
218-
span.set_data("unknown_response", True)
220+
span.set_attribute("unknown_response", True)
219221
span.__exit__(None, None, None)
220222

221223
return result

sentry_sdk/integrations/boto3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _sentry_request_created(service_id, request, operation_name, **kwargs):
7777
data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment
7878

7979
for key, value in data.items():
80-
span.set_data(key, value)
80+
span.set_attribute(key, value)
8181

8282
span.set_tag("aws.service_id", service_id)
8383
span.set_tag("aws.operation_name", operation_name)

sentry_sdk/integrations/celery/__init__.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def _set_messaging_destination_name(task, span):
343343
if delivery_info.get("exchange") == "" and routing_key is not None:
344344
# Empty exchange indicates the default exchange, meaning the tasks
345345
# are sent to the queue with the same name as the routing key.
346-
span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
346+
span.set_attribute(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
347347

348348

349349
def _wrap_task_call(task, f):
@@ -380,18 +380,20 @@ def _inner(*args, **kwargs):
380380
)
381381

382382
if latency is not None:
383-
span.set_data(SPANDATA.MESSAGING_MESSAGE_RECEIVE_LATENCY, latency)
383+
span.set_attribute(
384+
SPANDATA.MESSAGING_MESSAGE_RECEIVE_LATENCY, latency
385+
)
384386

385387
with capture_internal_exceptions():
386-
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id)
388+
span.set_attribute(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id)
387389

388390
with capture_internal_exceptions():
389-
span.set_data(
391+
span.set_attribute(
390392
SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, task.request.retries
391393
)
392394

393395
with capture_internal_exceptions():
394-
span.set_data(
396+
span.set_attribute(
395397
SPANDATA.MESSAGING_SYSTEM,
396398
task.app.connection().transport.driver_type,
397399
)
@@ -499,18 +501,18 @@ def sentry_publish(self, *args, **kwargs):
499501
only_if_parent=True,
500502
) as span:
501503
if task_id is not None:
502-
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task_id)
504+
span.set_attribute(SPANDATA.MESSAGING_MESSAGE_ID, task_id)
503505

504506
if exchange == "" and routing_key is not None:
505507
# Empty exchange indicates the default exchange, meaning messages are
506508
# routed to the queue with the same name as the routing key.
507-
span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
509+
span.set_attribute(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key)
508510

509511
if retries is not None:
510-
span.set_data(SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, retries)
512+
span.set_attribute(SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, retries)
511513

512514
with capture_internal_exceptions():
513-
span.set_data(
515+
span.set_attribute(
514516
SPANDATA.MESSAGING_SYSTEM, self.connection.transport.driver_type
515517
)
516518

sentry_sdk/integrations/django/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def _set_db_data(span, cursor_or_db):
679679
# type: (Span, Any) -> None
680680
db = cursor_or_db.db if hasattr(cursor_or_db, "db") else cursor_or_db
681681
vendor = db.vendor
682-
span.set_data(SPANDATA.DB_SYSTEM, vendor)
682+
span.set_attribute(SPANDATA.DB_SYSTEM, vendor)
683683

684684
# Some custom backends override `__getattr__`, making it look like `cursor_or_db`
685685
# actually has a `connection` and the `connection` has a `get_dsn_parameters`
@@ -712,16 +712,16 @@ def _set_db_data(span, cursor_or_db):
712712

713713
db_name = connection_params.get("dbname") or connection_params.get("database")
714714
if db_name is not None:
715-
span.set_data(SPANDATA.DB_NAME, db_name)
715+
span.set_attribute(SPANDATA.DB_NAME, db_name)
716716

717717
server_address = connection_params.get("host")
718718
if server_address is not None:
719-
span.set_data(SPANDATA.SERVER_ADDRESS, server_address)
719+
span.set_attribute(SPANDATA.SERVER_ADDRESS, server_address)
720720

721721
server_port = connection_params.get("port")
722722
if server_port is not None:
723-
span.set_data(SPANDATA.SERVER_PORT, str(server_port))
723+
span.set_attribute(SPANDATA.SERVER_PORT, str(server_port))
724724

725725
server_socket_address = connection_params.get("unix_socket")
726726
if server_socket_address is not None:
727-
span.set_data(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address)
727+
span.set_attribute(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address)

sentry_sdk/integrations/django/caching.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ def _instrument_call(
6060

6161
with capture_internal_exceptions():
6262
if address is not None:
63-
span.set_data(SPANDATA.NETWORK_PEER_ADDRESS, address)
63+
span.set_attribute(SPANDATA.NETWORK_PEER_ADDRESS, address)
6464

6565
if port is not None:
66-
span.set_data(SPANDATA.NETWORK_PEER_PORT, port)
66+
span.set_attribute(SPANDATA.NETWORK_PEER_PORT, port)
6767

6868
key = _get_safe_key(method_name, args, kwargs)
6969
if key is not None:
70-
span.set_data(SPANDATA.CACHE_KEY, key)
70+
span.set_attribute(SPANDATA.CACHE_KEY, key)
7171

7272
item_size = None
7373
if is_get_operation:
7474
if value:
7575
item_size = len(str(value))
76-
span.set_data(SPANDATA.CACHE_HIT, True)
76+
span.set_attribute(SPANDATA.CACHE_HIT, True)
7777
else:
78-
span.set_data(SPANDATA.CACHE_HIT, False)
78+
span.set_attribute(SPANDATA.CACHE_HIT, False)
7979
else: # TODO: We don't handle `get_or_set` which we should
8080
arg_count = len(args)
8181
if arg_count >= 2:
@@ -86,7 +86,7 @@ def _instrument_call(
8686
item_size = len(str(args[0]))
8787

8888
if item_size is not None:
89-
span.set_data(SPANDATA.CACHE_ITEM_SIZE, item_size)
89+
span.set_attribute(SPANDATA.CACHE_ITEM_SIZE, item_size)
9090

9191
return value
9292

sentry_sdk/integrations/django/signals_handlers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def wrapper(*args, **kwargs):
7171
origin=DjangoIntegration.origin,
7272
only_if_parent=True,
7373
) as span:
74-
span.set_data("signal", signal_name)
74+
span.set_attribute("signal", signal_name)
7575
return receiver(*args, **kwargs)
7676

7777
return wrapper

sentry_sdk/integrations/django/templates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def rendered_content(self):
6969
) as span:
7070
if isinstance(self.context_data, dict):
7171
for k, v in self.context_data.items():
72-
span.set_data(f"context.{k}", v)
72+
span.set_attribute(f"context.{k}", v)
7373
return real_rendered_content.fget(self)
7474

7575
SimpleTemplateResponse.rendered_content = rendered_content
@@ -97,7 +97,7 @@ def render(request, template_name, context=None, *args, **kwargs):
9797
only_if_parent=True,
9898
) as span:
9999
for k, v in context.items():
100-
span.set_data(f"context.{k}", v)
100+
span.set_attribute(f"context.{k}", v)
101101
return real_render(request, template_name, context, *args, **kwargs)
102102

103103
django.shortcuts.render = render

sentry_sdk/integrations/graphene.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def graphql_span(schema, source, kwargs):
138138
with sentry_sdk.start_span(
139139
op=op, name=operation_name, only_if_parent=True
140140
) as graphql_span:
141-
graphql_span.set_data("graphql.document", source)
142-
graphql_span.set_data("graphql.operation.name", operation_name)
143-
graphql_span.set_data("graphql.operation.type", operation_type)
141+
graphql_span.set_attribute("graphql.document", source)
142+
graphql_span.set_attribute("graphql.operation.name", operation_name)
143+
graphql_span.set_attribute("graphql.operation.type", operation_type)
144144
yield

sentry_sdk/integrations/grpc/aio/client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ async def intercept_unary_unary(
5353
origin=SPAN_ORIGIN,
5454
only_if_parent=True,
5555
) as span:
56-
span.set_data("type", "unary unary")
57-
span.set_data("method", method)
56+
span.set_attribute("type", "unary unary")
57+
span.set_attribute("method", method)
5858

5959
client_call_details = self._update_client_call_details_metadata_from_scope(
6060
client_call_details
6161
)
6262

6363
response = await continuation(client_call_details, request)
6464
status_code = await response.code()
65-
span.set_data("code", status_code.name)
65+
span.set_attribute("code", status_code.name)
6666

6767
return response
6868

@@ -86,15 +86,15 @@ async def intercept_unary_stream(
8686
origin=SPAN_ORIGIN,
8787
only_if_parent=True,
8888
) as span:
89-
span.set_data("type", "unary stream")
90-
span.set_data("method", method)
89+
span.set_attribute("type", "unary stream")
90+
span.set_attribute("method", method)
9191

9292
client_call_details = self._update_client_call_details_metadata_from_scope(
9393
client_call_details
9494
)
9595

9696
response = await continuation(client_call_details, request)
9797
# status_code = await response.code()
98-
# span.set_data("code", status_code)
98+
# span.set_attribute("code", status_code)
9999

100100
return response

sentry_sdk/integrations/grpc/client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def intercept_unary_unary(self, continuation, client_call_details, request):
3333
origin=SPAN_ORIGIN,
3434
only_if_parent=True,
3535
) as span:
36-
span.set_data("type", "unary unary")
37-
span.set_data("method", method)
36+
span.set_attribute("type", "unary unary")
37+
span.set_attribute("method", method)
3838

3939
client_call_details = self._update_client_call_details_metadata_from_scope(
4040
client_call_details
4141
)
4242

4343
response = continuation(client_call_details, request)
44-
span.set_data("code", response.code().name)
44+
span.set_attribute("code", response.code().name)
4545

4646
return response
4747

@@ -55,8 +55,8 @@ def intercept_unary_stream(self, continuation, client_call_details, request):
5555
origin=SPAN_ORIGIN,
5656
only_if_parent=True,
5757
) as span:
58-
span.set_data("type", "unary stream")
59-
span.set_data("method", method)
58+
span.set_attribute("type", "unary stream")
59+
span.set_attribute("method", method)
6060

6161
client_call_details = self._update_client_call_details_metadata_from_scope(
6262
client_call_details
@@ -66,7 +66,7 @@ def intercept_unary_stream(self, continuation, client_call_details, request):
6666
client_call_details, request
6767
) # type: UnaryStreamCall
6868
# Setting code on unary-stream leads to execution getting stuck
69-
# span.set_data("code", response.code().name)
69+
# span.set_attribute("code", response.code().name)
7070

7171
return response
7272

sentry_sdk/integrations/httpx.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def send(self, request, **kwargs):
7272
data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment
7373

7474
for key, value in data.items():
75-
span.set_data(key, value)
75+
span.set_attribute(key, value)
7676

7777
if should_propagate_trace(sentry_sdk.get_client(), str(request.url)):
7878
for (
@@ -93,7 +93,7 @@ def send(self, request, **kwargs):
9393
rv = real_send(self, request, **kwargs)
9494

9595
span.set_http_status(rv.status_code)
96-
span.set_data("reason", rv.reason_phrase)
96+
span.set_attribute("reason", rv.reason_phrase)
9797

9898
data[SPANDATA.HTTP_STATUS_CODE] = rv.status_code
9999
data["reason"] = rv.reason_phrase
@@ -142,7 +142,7 @@ async def send(self, request, **kwargs):
142142
data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment
143143

144144
for key, value in data.items():
145-
span.set_data(key, value)
145+
span.set_attribute(key, value)
146146

147147
if should_propagate_trace(sentry_sdk.get_client(), str(request.url)):
148148
for (
@@ -165,7 +165,7 @@ async def send(self, request, **kwargs):
165165
rv = await real_send(self, request, **kwargs)
166166

167167
span.set_http_status(rv.status_code)
168-
span.set_data("reason", rv.reason_phrase)
168+
span.set_attribute("reason", rv.reason_phrase)
169169

170170
data[SPANDATA.HTTP_STATUS_CODE] = rv.status_code
171171
data["reason"] = rv.reason_phrase

0 commit comments

Comments
 (0)