diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index c2e34a795b..f4929ef1a7 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -1113,6 +1113,9 @@ def span_decorator(f: "Any") -> "Any": """ Decorator to create a span for the given function. """ + new_attributes = dict(attributes) if attributes else {} + if "sentry.op" not in new_attributes: + new_attributes["sentry.op"] = OP.FUNCTION @functools.wraps(f) async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any": @@ -1127,7 +1130,7 @@ async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any": span_name = name or qualname_from_function(f) or "" with start_streaming_span( - name=span_name, attributes=attributes, active=active + name=span_name, attributes=new_attributes, active=active ): result = await f(*args, **kwargs) return result @@ -1150,7 +1153,7 @@ def sync_wrapper(*args: "Any", **kwargs: "Any") -> "Any": span_name = name or qualname_from_function(f) or "" with start_streaming_span( - name=span_name, attributes=attributes, active=active + name=span_name, attributes=new_attributes, active=active ): return f(*args, **kwargs) diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index d6f6ca87ed..9852d950ab 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -110,6 +110,7 @@ def traced_function(): span["name"] == "test_decorator.test_trace_decorator_span_streaming..traced_function" ) + assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok" @@ -136,6 +137,7 @@ def traced_function(): assert span["name"] == "traced" assert span["attributes"]["traced.attribute"] == 123 + assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok" @@ -193,6 +195,7 @@ async def traced_function(): span["name"] == "test_decorator.test_trace_decorator_async_span_streaming..traced_function" ) + assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok" @@ -222,6 +225,7 @@ async def traced_function(): assert span["name"] == "traced" assert span["attributes"]["traced.attribute"] == 123 + assert span["attributes"]["sentry.op"] == "function" assert span["status"] == "ok"