diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index b784cb2a1a..027600a765 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -172,7 +172,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh ### Deprecated -- `sentry_sdk.start_transaction` is deprecated. Use `sentry_sdk.start_span` instead. +- `sentry_sdk.start_transaction()` is deprecated. Use `sentry_sdk.start_span()` instead. +- `Span.set_data()` is deprecated. Use `Span.set_attribute()` instead. ## Upgrading to 2.0 diff --git a/sentry_sdk/ai/monitoring.py b/sentry_sdk/ai/monitoring.py index e149ebe7df..08b6482da5 100644 --- a/sentry_sdk/ai/monitoring.py +++ b/sentry_sdk/ai/monitoring.py @@ -39,9 +39,9 @@ def sync_wrapped(*args, **kwargs): for k, v in kwargs.pop("sentry_tags", {}).items(): span.set_tag(k, v) for k, v in kwargs.pop("sentry_data", {}).items(): - span.set_data(k, v) + span.set_attribute(k, v) if curr_pipeline: - span.set_data("ai.pipeline.name", curr_pipeline) + span.set_attribute("ai.pipeline.name", curr_pipeline) return f(*args, **kwargs) else: _ai_pipeline_name.set(description) @@ -70,9 +70,9 @@ async def async_wrapped(*args, **kwargs): for k, v in kwargs.pop("sentry_tags", {}).items(): span.set_tag(k, v) for k, v in kwargs.pop("sentry_data", {}).items(): - span.set_data(k, v) + span.set_attribute(k, v) if curr_pipeline: - span.set_data("ai.pipeline.name", curr_pipeline) + span.set_attribute("ai.pipeline.name", curr_pipeline) return await f(*args, **kwargs) else: _ai_pipeline_name.set(description) @@ -104,7 +104,7 @@ def record_token_usage( # type: (Span, Optional[int], Optional[int], Optional[int]) -> None ai_pipeline_name = get_ai_pipeline_name() if ai_pipeline_name: - span.set_data("ai.pipeline.name", ai_pipeline_name) + span.set_attribute("ai.pipeline.name", ai_pipeline_name) if prompt_tokens is not None: span.set_measurement("ai_prompt_tokens_used", value=prompt_tokens) if completion_tokens is not None: diff --git a/sentry_sdk/ai/utils.py b/sentry_sdk/ai/utils.py index ed3494f679..5868606940 100644 --- a/sentry_sdk/ai/utils.py +++ b/sentry_sdk/ai/utils.py @@ -29,4 +29,4 @@ def _normalize_data(data): def set_data_normalized(span, key, value): # type: (Span, str, Any) -> None normalized = _normalize_data(value) - span.set_data(key, normalized) + span.set_attribute(key, normalized) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 62af0406cb..8115063c9c 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -245,7 +245,7 @@ async def on_request_start(session, trace_config_ctx, params): data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment for key, value in data.items(): - span.set_data(key, value) + span.set_attribute(key, value) client = sentry_sdk.get_client() @@ -291,7 +291,7 @@ async def on_request_end(session, trace_config_ctx, params): span = trace_config_ctx.span span.set_http_status(int(params.response.status)) - span.set_data("reason", params.response.reason) + span.set_attribute("reason", params.response.reason) span.finish() trace_config = TraceConfig() diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 148b978b40..454b6f93ca 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -121,13 +121,13 @@ def _add_ai_data_to_span( with capture_internal_exceptions(): if should_send_default_pii() and integration.include_prompts: complete_message = "".join(content_blocks) - span.set_data( + span.set_attribute( SPANDATA.AI_RESPONSES, [{"type": "text", "text": complete_message}], ) total_tokens = input_tokens + output_tokens record_token_usage(span, input_tokens, output_tokens, total_tokens) - span.set_data(SPANDATA.AI_STREAMING, True) + span.set_attribute(SPANDATA.AI_STREAMING, True) def _sentry_patched_create_common(f, *args, **kwargs): @@ -159,15 +159,17 @@ def _sentry_patched_create_common(f, *args, **kwargs): model = kwargs.get("model") with capture_internal_exceptions(): - span.set_data(SPANDATA.AI_MODEL_ID, model) - span.set_data(SPANDATA.AI_STREAMING, False) + span.set_attribute(SPANDATA.AI_MODEL_ID, model) + span.set_attribute(SPANDATA.AI_STREAMING, False) if should_send_default_pii() and integration.include_prompts: - span.set_data(SPANDATA.AI_INPUT_MESSAGES, messages) + span.set_attribute(SPANDATA.AI_INPUT_MESSAGES, messages) if hasattr(result, "content"): if should_send_default_pii() and integration.include_prompts: - span.set_data(SPANDATA.AI_RESPONSES, _get_responses(result.content)) + span.set_attribute( + SPANDATA.AI_RESPONSES, _get_responses(result.content) + ) _calculate_token_usage(result, span) span.__exit__(None, None, None) @@ -215,7 +217,7 @@ async def new_iterator_async(): result._iterator = new_iterator() else: - span.set_data("unknown_response", True) + span.set_attribute("unknown_response", True) span.__exit__(None, None, None) return result diff --git a/sentry_sdk/integrations/boto3.py b/sentry_sdk/integrations/boto3.py index 936d15639d..65239b7548 100644 --- a/sentry_sdk/integrations/boto3.py +++ b/sentry_sdk/integrations/boto3.py @@ -77,7 +77,7 @@ def _sentry_request_created(service_id, request, operation_name, **kwargs): data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment for key, value in data.items(): - span.set_data(key, value) + span.set_attribute(key, value) span.set_tag("aws.service_id", service_id) span.set_tag("aws.operation_name", operation_name) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 238704fa68..bbaf3aec77 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -343,7 +343,7 @@ def _set_messaging_destination_name(task, span): if delivery_info.get("exchange") == "" and routing_key is not None: # Empty exchange indicates the default exchange, meaning the tasks # are sent to the queue with the same name as the routing key. - span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) + span.set_attribute(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) def _wrap_task_call(task, f): @@ -380,18 +380,20 @@ def _inner(*args, **kwargs): ) if latency is not None: - span.set_data(SPANDATA.MESSAGING_MESSAGE_RECEIVE_LATENCY, latency) + span.set_attribute( + SPANDATA.MESSAGING_MESSAGE_RECEIVE_LATENCY, latency + ) with capture_internal_exceptions(): - span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id) + span.set_attribute(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id) with capture_internal_exceptions(): - span.set_data( + span.set_attribute( SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, task.request.retries ) with capture_internal_exceptions(): - span.set_data( + span.set_attribute( SPANDATA.MESSAGING_SYSTEM, task.app.connection().transport.driver_type, ) @@ -499,18 +501,18 @@ def sentry_publish(self, *args, **kwargs): only_if_parent=True, ) as span: if task_id is not None: - span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task_id) + span.set_attribute(SPANDATA.MESSAGING_MESSAGE_ID, task_id) if exchange == "" and routing_key is not None: # Empty exchange indicates the default exchange, meaning messages are # routed to the queue with the same name as the routing key. - span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) + span.set_attribute(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) if retries is not None: - span.set_data(SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, retries) + span.set_attribute(SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, retries) with capture_internal_exceptions(): - span.set_data( + span.set_attribute( SPANDATA.MESSAGING_SYSTEM, self.connection.transport.driver_type ) diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 27b53e52a8..a82cef2000 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -679,7 +679,7 @@ def _set_db_data(span, cursor_or_db): # type: (Span, Any) -> None db = cursor_or_db.db if hasattr(cursor_or_db, "db") else cursor_or_db vendor = db.vendor - span.set_data(SPANDATA.DB_SYSTEM, vendor) + span.set_attribute(SPANDATA.DB_SYSTEM, vendor) # Some custom backends override `__getattr__`, making it look like `cursor_or_db` # actually has a `connection` and the `connection` has a `get_dsn_parameters` @@ -712,16 +712,16 @@ def _set_db_data(span, cursor_or_db): db_name = connection_params.get("dbname") or connection_params.get("database") if db_name is not None: - span.set_data(SPANDATA.DB_NAME, db_name) + span.set_attribute(SPANDATA.DB_NAME, db_name) server_address = connection_params.get("host") if server_address is not None: - span.set_data(SPANDATA.SERVER_ADDRESS, server_address) + span.set_attribute(SPANDATA.SERVER_ADDRESS, server_address) server_port = connection_params.get("port") if server_port is not None: - span.set_data(SPANDATA.SERVER_PORT, str(server_port)) + span.set_attribute(SPANDATA.SERVER_PORT, str(server_port)) server_socket_address = connection_params.get("unix_socket") if server_socket_address is not None: - span.set_data(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address) + span.set_attribute(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address) diff --git a/sentry_sdk/integrations/django/caching.py b/sentry_sdk/integrations/django/caching.py index 562aec6e02..236da9f749 100644 --- a/sentry_sdk/integrations/django/caching.py +++ b/sentry_sdk/integrations/django/caching.py @@ -60,22 +60,22 @@ def _instrument_call( with capture_internal_exceptions(): if address is not None: - span.set_data(SPANDATA.NETWORK_PEER_ADDRESS, address) + span.set_attribute(SPANDATA.NETWORK_PEER_ADDRESS, address) if port is not None: - span.set_data(SPANDATA.NETWORK_PEER_PORT, port) + span.set_attribute(SPANDATA.NETWORK_PEER_PORT, port) key = _get_safe_key(method_name, args, kwargs) if key is not None: - span.set_data(SPANDATA.CACHE_KEY, key) + span.set_attribute(SPANDATA.CACHE_KEY, key) item_size = None if is_get_operation: if value: item_size = len(str(value)) - span.set_data(SPANDATA.CACHE_HIT, True) + span.set_attribute(SPANDATA.CACHE_HIT, True) else: - span.set_data(SPANDATA.CACHE_HIT, False) + span.set_attribute(SPANDATA.CACHE_HIT, False) else: # TODO: We don't handle `get_or_set` which we should arg_count = len(args) if arg_count >= 2: @@ -86,7 +86,7 @@ def _instrument_call( item_size = len(str(args[0])) if item_size is not None: - span.set_data(SPANDATA.CACHE_ITEM_SIZE, item_size) + span.set_attribute(SPANDATA.CACHE_ITEM_SIZE, item_size) return value diff --git a/sentry_sdk/integrations/django/signals_handlers.py b/sentry_sdk/integrations/django/signals_handlers.py index 69c1a3cdfb..6e398ddfc3 100644 --- a/sentry_sdk/integrations/django/signals_handlers.py +++ b/sentry_sdk/integrations/django/signals_handlers.py @@ -71,7 +71,7 @@ def wrapper(*args, **kwargs): origin=DjangoIntegration.origin, only_if_parent=True, ) as span: - span.set_data("signal", signal_name) + span.set_attribute("signal", signal_name) return receiver(*args, **kwargs) return wrapper diff --git a/sentry_sdk/integrations/django/templates.py b/sentry_sdk/integrations/django/templates.py index 53ccc60fc6..fd6e56b515 100644 --- a/sentry_sdk/integrations/django/templates.py +++ b/sentry_sdk/integrations/django/templates.py @@ -69,7 +69,7 @@ def rendered_content(self): ) as span: if isinstance(self.context_data, dict): for k, v in self.context_data.items(): - span.set_data(f"context.{k}", v) + span.set_attribute(f"context.{k}", v) return real_rendered_content.fget(self) SimpleTemplateResponse.rendered_content = rendered_content @@ -97,7 +97,7 @@ def render(request, template_name, context=None, *args, **kwargs): only_if_parent=True, ) as span: for k, v in context.items(): - span.set_data(f"context.{k}", v) + span.set_attribute(f"context.{k}", v) return real_render(request, template_name, context, *args, **kwargs) django.shortcuts.render = render diff --git a/sentry_sdk/integrations/graphene.py b/sentry_sdk/integrations/graphene.py index 877ebd0a7e..9269a4403c 100644 --- a/sentry_sdk/integrations/graphene.py +++ b/sentry_sdk/integrations/graphene.py @@ -138,7 +138,7 @@ def graphql_span(schema, source, kwargs): with sentry_sdk.start_span( op=op, name=operation_name, only_if_parent=True ) as graphql_span: - graphql_span.set_data("graphql.document", source) - graphql_span.set_data("graphql.operation.name", operation_name) - graphql_span.set_data("graphql.operation.type", operation_type) + graphql_span.set_attribute("graphql.document", source) + graphql_span.set_attribute("graphql.operation.name", operation_name) + graphql_span.set_attribute("graphql.operation.type", operation_type) yield diff --git a/sentry_sdk/integrations/grpc/aio/client.py b/sentry_sdk/integrations/grpc/aio/client.py index 2fd9f70bed..a8ea94276f 100644 --- a/sentry_sdk/integrations/grpc/aio/client.py +++ b/sentry_sdk/integrations/grpc/aio/client.py @@ -53,8 +53,8 @@ async def intercept_unary_unary( origin=SPAN_ORIGIN, only_if_parent=True, ) as span: - span.set_data("type", "unary unary") - span.set_data("method", method) + span.set_attribute("type", "unary unary") + span.set_attribute("method", method) client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details @@ -62,7 +62,7 @@ async def intercept_unary_unary( response = await continuation(client_call_details, request) status_code = await response.code() - span.set_data("code", status_code.name) + span.set_attribute("code", status_code.name) return response @@ -86,8 +86,8 @@ async def intercept_unary_stream( origin=SPAN_ORIGIN, only_if_parent=True, ) as span: - span.set_data("type", "unary stream") - span.set_data("method", method) + span.set_attribute("type", "unary stream") + span.set_attribute("method", method) client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details @@ -95,6 +95,6 @@ async def intercept_unary_stream( response = await continuation(client_call_details, request) # status_code = await response.code() - # span.set_data("code", status_code) + # span.set_attribute("code", status_code) return response diff --git a/sentry_sdk/integrations/grpc/client.py b/sentry_sdk/integrations/grpc/client.py index cb456fc9b4..b7a1ddd85e 100644 --- a/sentry_sdk/integrations/grpc/client.py +++ b/sentry_sdk/integrations/grpc/client.py @@ -33,15 +33,15 @@ def intercept_unary_unary(self, continuation, client_call_details, request): origin=SPAN_ORIGIN, only_if_parent=True, ) as span: - span.set_data("type", "unary unary") - span.set_data("method", method) + span.set_attribute("type", "unary unary") + span.set_attribute("method", method) client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details ) response = continuation(client_call_details, request) - span.set_data("code", response.code().name) + span.set_attribute("code", response.code().name) return response @@ -55,8 +55,8 @@ def intercept_unary_stream(self, continuation, client_call_details, request): origin=SPAN_ORIGIN, only_if_parent=True, ) as span: - span.set_data("type", "unary stream") - span.set_data("method", method) + span.set_attribute("type", "unary stream") + span.set_attribute("method", method) client_call_details = self._update_client_call_details_metadata_from_scope( client_call_details @@ -66,7 +66,7 @@ def intercept_unary_stream(self, continuation, client_call_details, request): client_call_details, request ) # type: UnaryStreamCall # Setting code on unary-stream leads to execution getting stuck - # span.set_data("code", response.code().name) + # span.set_attribute("code", response.code().name) return response diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 1ac2708f32..a7c391851c 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -72,7 +72,7 @@ def send(self, request, **kwargs): data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment for key, value in data.items(): - span.set_data(key, value) + span.set_attribute(key, value) if should_propagate_trace(sentry_sdk.get_client(), str(request.url)): for ( @@ -93,7 +93,7 @@ def send(self, request, **kwargs): rv = real_send(self, request, **kwargs) span.set_http_status(rv.status_code) - span.set_data("reason", rv.reason_phrase) + span.set_attribute("reason", rv.reason_phrase) data[SPANDATA.HTTP_STATUS_CODE] = rv.status_code data["reason"] = rv.reason_phrase @@ -142,7 +142,7 @@ async def send(self, request, **kwargs): data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment for key, value in data.items(): - span.set_data(key, value) + span.set_attribute(key, value) if should_propagate_trace(sentry_sdk.get_client(), str(request.url)): for ( @@ -165,7 +165,7 @@ async def send(self, request, **kwargs): rv = await real_send(self, request, **kwargs) span.set_http_status(rv.status_code) - span.set_data("reason", rv.reason_phrase) + span.set_attribute("reason", rv.reason_phrase) data[SPANDATA.HTTP_STATUS_CODE] = rv.status_code data["reason"] = rv.reason_phrase diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index c775f9d92b..3d40ff1dbc 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -229,7 +229,7 @@ def on_chat_model_start(self, serialized, messages, *, run_id, **kwargs): if not model and "anthropic" in all_params.get("_type"): model = "claude-2" if model: - span.set_data(SPANDATA.AI_MODEL_ID, model) + span.set_attribute(SPANDATA.AI_MODEL_ID, model) if should_send_default_pii() and self.include_prompts: set_data_normalized( span, diff --git a/sentry_sdk/integrations/redis/utils.py b/sentry_sdk/integrations/redis/utils.py index 9eb16c5bc4..58130582ce 100644 --- a/sentry_sdk/integrations/redis/utils.py +++ b/sentry_sdk/integrations/redis/utils.py @@ -36,7 +36,7 @@ def _update_span(span, *data_bags): if key in TAG_KEYS: span.set_tag(key, value) else: - span.set_data(key, value) + span.set_attribute(key, value) def _create_breadcrumb(message, *data_bags): diff --git a/sentry_sdk/integrations/rust_tracing.py b/sentry_sdk/integrations/rust_tracing.py index 9b5a83197e..acfe9bd7f4 100644 --- a/sentry_sdk/integrations/rust_tracing.py +++ b/sentry_sdk/integrations/rust_tracing.py @@ -214,9 +214,9 @@ def on_new_span(self, attrs: str, span_id: str) -> Optional[Span]: fields = metadata.get("fields", []) for field in fields: if self._include_tracing_fields(): - span.set_data(field, attrs.get(field)) + span.set_attribute(field, attrs.get(field)) else: - span.set_data(field, SENSITIVE_DATA_SUBSTITUTE) + span.set_attribute(field, SENSITIVE_DATA_SUBSTITUTE) return span @@ -229,9 +229,9 @@ def on_record(self, span_id: str, values: str, span: Optional[Span]) -> None: deserialized_values = json.loads(values) for key, value in deserialized_values.items(): if self._include_tracing_fields(): - span.set_data(key, value) + span.set_attribute(key, value) else: - span.set_data(key, SENSITIVE_DATA_SUBSTITUTE) + span.set_attribute(key, SENSITIVE_DATA_SUBSTITUTE) class RustTracingIntegration(Integration): diff --git a/sentry_sdk/integrations/socket.py b/sentry_sdk/integrations/socket.py index 08fd4a8f13..544a63c0f0 100644 --- a/sentry_sdk/integrations/socket.py +++ b/sentry_sdk/integrations/socket.py @@ -64,10 +64,10 @@ def create_connection( only_if_parent=True, ) as span: host, port = address - span.set_data("address.host", host) - span.set_data("address.port", port) - span.set_data("timeout", timeout) - span.set_data("source_address", source_address) + span.set_attribute("address.host", host) + span.set_attribute("address.port", port) + span.set_attribute("timeout", timeout) + span.set_attribute("source_address", source_address) return real_create_connection( address=address, timeout=timeout, source_address=source_address @@ -92,8 +92,8 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0): origin=SocketIntegration.origin, only_if_parent=True, ) as span: - span.set_data("host", host) - span.set_data("port", port) + span.set_attribute("host", host) + span.set_attribute("port", port) return real_getaddrinfo(host, port, family, type, proto, flags) diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py index b00c6b7551..4c4d8fde8c 100644 --- a/sentry_sdk/integrations/sqlalchemy.py +++ b/sentry_sdk/integrations/sqlalchemy.py @@ -128,19 +128,19 @@ def _set_db_data(span, conn): # type: (Span, Any) -> None db_system = _get_db_system(conn.engine.name) if db_system is not None: - span.set_data(SPANDATA.DB_SYSTEM, db_system) + span.set_attribute(SPANDATA.DB_SYSTEM, db_system) if conn.engine.url is None: return db_name = conn.engine.url.database if db_name is not None: - span.set_data(SPANDATA.DB_NAME, db_name) + span.set_attribute(SPANDATA.DB_NAME, db_name) server_address = conn.engine.url.host if server_address is not None: - span.set_data(SPANDATA.SERVER_ADDRESS, server_address) + span.set_attribute(SPANDATA.SERVER_ADDRESS, server_address) server_port = conn.engine.url.port if server_port is not None: - span.set_data(SPANDATA.SERVER_PORT, server_port) + span.set_attribute(SPANDATA.SERVER_PORT, server_port) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 49313bb0a5..adc0de4f28 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -108,7 +108,7 @@ def putrequest(self, method, url, *args, **kwargs): data[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment for key, value in data.items(): - span.set_data(key, value) + span.set_attribute(key, value) rv = real_putrequest(self, method, url, *args, **kwargs) @@ -147,7 +147,7 @@ def getresponse(self, *args, **kwargs): status_code = int(rv.status) span.set_http_status(status_code) - span.set_data("reason", rv.reason) + span.set_attribute("reason", rv.reason) sentry_sdk.add_breadcrumb( type="http", @@ -246,7 +246,7 @@ def sentry_patched_popen_init(self, *a, **kw): env["SUBPROCESS_" + k.upper().replace("-", "_")] = v if cwd: - span.set_data("subprocess.cwd", cwd) + span.set_attribute("subprocess.cwd", cwd) rv = old_popen_init(self, *a, **kw) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 608dfcbb8c..274ae8d1c9 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -182,9 +182,9 @@ def on_operation(self): origin=StrawberryIntegration.origin, only_if_parent=True, ) as graphql_span: - graphql_span.set_data("graphql.operation.type", operation_type) - graphql_span.set_data("graphql.document", self.execution_context.query) - graphql_span.set_data("graphql.resource_name", self._resource_name) + graphql_span.set_attribute("graphql.operation.type", operation_type) + graphql_span.set_attribute("graphql.document", self.execution_context.query) + graphql_span.set_attribute("graphql.resource_name", self._resource_name) yield @@ -192,7 +192,9 @@ def on_operation(self): self._operation_name = self.execution_context.operation_name if self._operation_name is not None: - graphql_span.set_data("graphql.operation.name", self._operation_name) + graphql_span.set_attribute( + "graphql.operation.name", self._operation_name + ) sentry_sdk.get_current_scope().set_transaction_name( self._operation_name, @@ -246,10 +248,10 @@ async def resolve(self, _next, root, info, *args, **kwargs): name="resolving {}".format(field_path), origin=StrawberryIntegration.origin, ) as span: - span.set_data("graphql.field_name", info.field_name) - span.set_data("graphql.parent_type", info.parent_type.name) - span.set_data("graphql.field_path", field_path) - span.set_data("graphql.path", ".".join(map(str, info.path.as_list()))) + span.set_attribute("graphql.field_name", info.field_name) + span.set_attribute("graphql.parent_type", info.parent_type.name) + span.set_attribute("graphql.field_path", field_path) + span.set_attribute("graphql.path", ".".join(map(str, info.path.as_list()))) return await self._resolve(_next, root, info, *args, **kwargs) @@ -267,10 +269,10 @@ def resolve(self, _next, root, info, *args, **kwargs): name="resolving {}".format(field_path), origin=StrawberryIntegration.origin, ) as span: - span.set_data("graphql.field_name", info.field_name) - span.set_data("graphql.parent_type", info.parent_type.name) - span.set_data("graphql.field_path", field_path) - span.set_data("graphql.path", ".".join(map(str, info.path.as_list()))) + span.set_attribute("graphql.field_name", info.field_name) + span.set_attribute("graphql.parent_type", info.parent_type.name) + span.set_attribute("graphql.field_path", field_path) + span.set_attribute("graphql.path", ".".join(map(str, info.path.as_list()))) return _next(root, info, *args, **kwargs) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 5a06d704ee..587b7dbe9b 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -596,6 +596,12 @@ def set_tag(self, key, value): def set_data(self, key, value): # type: (str, Any) -> None + warnings.warn( + "`Span.set_data` is deprecated. Please use `Span.set_attribute` instead.", + DeprecationWarning, + stacklevel=2, + ) + # TODO-neel-potel we cannot add dicts here self.set_attribute(key, value) @@ -662,10 +668,10 @@ def set_measurement(self, name, value, unit=""): def set_thread(self, thread_id, thread_name): # type: (Optional[int], Optional[str]) -> None if thread_id is not None: - self.set_data(SPANDATA.THREAD_ID, str(thread_id)) + self.set_attribute(SPANDATA.THREAD_ID, str(thread_id)) if thread_name is not None: - self.set_data(SPANDATA.THREAD_NAME, thread_name) + self.set_attribute(SPANDATA.THREAD_NAME, thread_name) def update_active_thread(self): # type: () -> None @@ -674,7 +680,7 @@ def update_active_thread(self): def set_http_status(self, http_status): # type: (int) -> None - self.set_data(SPANDATA.HTTP_STATUS_CODE, http_status) + self.set_attribute(SPANDATA.HTTP_STATUS_CODE, http_status) self.set_status(get_span_status_from_http_code(http_status)) def is_success(self): diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 4bc7c6aeff..27320ac589 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -151,7 +151,7 @@ def record_sql_queries( only_if_parent=True, ) as span: for k, v in data.items(): - span.set_data(k, v) + span.set_attribute(k, v) yield span @@ -249,14 +249,14 @@ def add_query_source(span): except Exception: lineno = None if lineno is not None: - span.set_data(SPANDATA.CODE_LINENO, frame.f_lineno) + span.set_attribute(SPANDATA.CODE_LINENO, frame.f_lineno) try: namespace = frame.f_globals.get("__name__") except Exception: namespace = None if namespace is not None: - span.set_data(SPANDATA.CODE_NAMESPACE, namespace) + span.set_attribute(SPANDATA.CODE_NAMESPACE, namespace) filepath = _get_frame_module_abs_path(frame) if filepath is not None: @@ -266,7 +266,7 @@ def add_query_source(span): in_app_path = filepath.replace(project_root, "").lstrip(os.sep) else: in_app_path = filepath - span.set_data(SPANDATA.CODE_FILEPATH, in_app_path) + span.set_attribute(SPANDATA.CODE_FILEPATH, in_app_path) try: code_function = frame.f_code.co_name @@ -274,7 +274,7 @@ def add_query_source(span): code_function = None if code_function is not None: - span.set_data(SPANDATA.CODE_FUNCTION, frame.f_code.co_name) + span.set_attribute(SPANDATA.CODE_FUNCTION, frame.f_code.co_name) def extract_sentrytrace_data(header): diff --git a/tests/integrations/opentelemetry/test_potel.py b/tests/integrations/opentelemetry/test_potel.py index 2d1d66c6d0..753f2b4cf2 100644 --- a/tests/integrations/opentelemetry/test_potel.py +++ b/tests/integrations/opentelemetry/test_potel.py @@ -229,9 +229,9 @@ def test_span_data_started_with_sentry(capture_envelopes): envelopes = capture_envelopes() with sentry_sdk.start_span(op="http", description="request") as request_span: - request_span.set_data("foo", "bar") + request_span.set_attribute("foo", "bar") with sentry_sdk.start_span(op="db", description="statement") as db_span: - db_span.set_data("baz", 42) + db_span.set_attribute("baz", 42) (envelope,) = envelopes (item,) = envelope.items diff --git a/tests/test_scrubber.py b/tests/test_scrubber.py index 3c466de79f..ee209da4b1 100644 --- a/tests/test_scrubber.py +++ b/tests/test_scrubber.py @@ -155,8 +155,8 @@ def test_span_data_scrubbing(sentry_init, capture_events): with start_span(name="hi"): with start_span(op="foo", name="bar") as span: - span.set_data("password", "secret") - span.set_data("datafoo", "databar") + span.set_attribute("password", "secret") + span.set_attribute("datafoo", "databar") (event,) = events assert event["spans"][0]["data"] == ApproxDict( diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index a807c6eb74..5b0213d6c6 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -37,8 +37,8 @@ def test_span_data_scrubbing_and_trimming(sentry_init, capture_events): with start_span(name="hi"): with start_span(op="foo", name="bar") as span: - span.set_data("password", "secret") - span.set_data("datafoo", "databar") + span.set_attribute("password", "secret") + span.set_attribute("datafoo", "databar") for i in range(10): with start_span(op=f"foo{i}"): @@ -83,9 +83,9 @@ def test_root_span_data(sentry_init, capture_events): with start_span(name="test-root-span"): root_span = sentry_sdk.get_current_span() - root_span.set_data("foo", "bar") + root_span.set_attribute("foo", "bar") with start_span(op="test-span") as span: - span.set_data("spanfoo", "spanbar") + span.set_attribute("spanfoo", "spanbar") assert len(events) == 1