Skip to content

Commit 89ae39e

Browse files
committed
move to opentelemetry/
2 parents f34b066 + 5d6e318 commit 89ae39e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+478
-170
lines changed

MIGRATION_GUIDE.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
99
### Changed
1010

1111
- The SDK now supports Python 3.7 and higher.
12+
- 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
1213
- `sentry_sdk.start_span` now only takes keyword arguments.
1314
- `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`.
1415
- You can no longer change the sampled status of a span with `span.sampled = False` after starting it.
@@ -131,7 +132,6 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
131132

132133
### Removed
133134

134-
- Spans no longer have a `description`. Use `name` instead.
135135
- Dropped support for Python 3.6.
136136
- The `enable_tracing` `init` option has been removed. Configure `traces_sample_rate` directly.
137137
- The `propagate_traces` `init` option has been removed. Use `trace_propagation_targets` instead.
@@ -157,18 +157,23 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
157157
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
158158
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
159159
- Function transports are no longer supported. Subclass the `Transport` instead.
160+
- `start_transaction` (`start_span`) no longer takes the following arguments:
161+
- `trace_id`, `baggage`: use `continue_trace` for propagation from headers or environment variables
162+
- `same_process_as_parent`
163+
- `span_id`
164+
- `parent_span_id`: you can supply a `parent_span` instead
160165
- Setting `Scope.transaction` directly is no longer supported. Use `Scope.set_transaction_name()` instead.
161166
- Passing a list or `None` for `failed_request_status_codes` in the Starlette integration is no longer supported. Pass a set of integers instead.
162167
- The `span` argument of `Scope.trace_propagation_meta` is no longer supported.
163168
- Setting `Scope.user` directly is no longer supported. Use `Scope.set_user()` instead.
164-
- `start_transaction` (`start_span`) no longer takes a `baggage` argument. Use the `continue_trace()` context manager instead to propagate baggage.
165169
- Dropped support for Django versions below 2.0.
166170
- Dropped support for trytond versions below 5.0.
167171
- Dropped support for Falcon versions below 3.0.
168172

169173
### Deprecated
170174

171-
- `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.
172177

173178
## Upgrading to 2.0
174179

sentry_sdk/ai/monitoring.py

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def __init__(
511511
debug=None, # type: Optional[bool]
512512
attach_stacktrace=False, # type: bool
513513
ca_certs=None, # type: Optional[str]
514-
traces_sample_rate=None, # type: Optional[float]
514+
traces_sample_rate=0, # type: Optional[float]
515515
traces_sampler=None, # type: Optional[TracesSampler]
516516
profiles_sample_rate=None, # type: Optional[float]
517517
profiles_sampler=None, # type: Optional[TracesSampler]

sentry_sdk/integrations/aiohttp.py

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 9 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 6 additions & 6 deletions
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

0 commit comments

Comments
 (0)