Skip to content

Commit 7e5f771

Browse files
committed
fix(tracing): Set sentry.op to function in new trace decorator
1 parent b9899f8 commit 7e5f771

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

sentry_sdk/tracing_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@ def span_decorator(f: "Any") -> "Any":
11131113
"""
11141114
Decorator to create a span for the given function.
11151115
"""
1116+
new_attributes = attributes or {}
1117+
if "sentry.op" not in new_attributes:
1118+
new_attributes["sentry.op"] = OP.FUNCTION
11161119

11171120
@functools.wraps(f)
11181121
async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
@@ -1127,7 +1130,7 @@ async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
11271130
span_name = name or qualname_from_function(f) or ""
11281131

11291132
with start_streaming_span(
1130-
name=span_name, attributes=attributes, active=active
1133+
name=span_name, attributes=new_attributes, active=active
11311134
):
11321135
result = await f(*args, **kwargs)
11331136
return result
@@ -1150,7 +1153,7 @@ def sync_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
11501153
span_name = name or qualname_from_function(f) or ""
11511154

11521155
with start_streaming_span(
1153-
name=span_name, attributes=attributes, active=active
1156+
name=span_name, attributes=new_attributes, active=active
11541157
):
11551158
return f(*args, **kwargs)
11561159

tests/tracing/test_decorator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def traced_function():
110110
span["name"]
111111
== "test_decorator.test_trace_decorator_span_streaming.<locals>.traced_function"
112112
)
113+
assert span["attributes"]["sentry.op"] == "function"
113114
assert span["status"] == "ok"
114115

115116

@@ -136,6 +137,7 @@ def traced_function():
136137

137138
assert span["name"] == "traced"
138139
assert span["attributes"]["traced.attribute"] == 123
140+
assert span["attributes"]["sentry.op"] == "function"
139141
assert span["status"] == "ok"
140142

141143

@@ -193,6 +195,7 @@ async def traced_function():
193195
span["name"]
194196
== "test_decorator.test_trace_decorator_async_span_streaming.<locals>.traced_function"
195197
)
198+
assert span["attributes"]["sentry.op"] == "function"
196199
assert span["status"] == "ok"
197200

198201

@@ -222,6 +225,7 @@ async def traced_function():
222225

223226
assert span["name"] == "traced"
224227
assert span["attributes"]["traced.attribute"] == 123
228+
assert span["attributes"]["sentry.op"] == "function"
225229
assert span["status"] == "ok"
226230

227231

0 commit comments

Comments
 (0)