Skip to content

Commit 9254d35

Browse files
committed
Merge branch 'master' into ivana/traceparent-test
2 parents d173796 + ef9a569 commit 9254d35

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
@@ -1121,6 +1121,9 @@ def span_decorator(f: "Any") -> "Any":
11211121
"""
11221122
Decorator to create a span for the given function.
11231123
"""
1124+
new_attributes = dict(attributes) if attributes else {}
1125+
if "sentry.op" not in new_attributes:
1126+
new_attributes["sentry.op"] = OP.FUNCTION
11241127

11251128
@functools.wraps(f)
11261129
async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
@@ -1135,7 +1138,7 @@ async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
11351138
span_name = name or qualname_from_function(f) or ""
11361139

11371140
with start_streaming_span(
1138-
name=span_name, attributes=attributes, active=active
1141+
name=span_name, attributes=new_attributes, active=active
11391142
):
11401143
result = await f(*args, **kwargs)
11411144
return result
@@ -1158,7 +1161,7 @@ def sync_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
11581161
span_name = name or qualname_from_function(f) or ""
11591162

11601163
with start_streaming_span(
1161-
name=span_name, attributes=attributes, active=active
1164+
name=span_name, attributes=new_attributes, active=active
11621165
):
11631166
return f(*args, **kwargs)
11641167

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)