Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
sentrivana marked this conversation as resolved.

@functools.wraps(f)
async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
Expand All @@ -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
Expand All @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions tests/tracing/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def traced_function():
span["name"]
== "test_decorator.test_trace_decorator_span_streaming.<locals>.traced_function"
)
assert span["attributes"]["sentry.op"] == "function"
assert span["status"] == "ok"


Expand All @@ -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"


Expand Down Expand Up @@ -193,6 +195,7 @@ async def traced_function():
span["name"]
== "test_decorator.test_trace_decorator_async_span_streaming.<locals>.traced_function"
)
assert span["attributes"]["sentry.op"] == "function"
assert span["status"] == "ok"


Expand Down Expand Up @@ -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"


Expand Down
Loading