Skip to content

Commit b23507c

Browse files
authored
Cleanup op and description mapping (#4560)
The main change is that `op` is now optional and `name` and `description` are basically interchangeable and map to each other as best as possible. Preference is given to explicitly set values (`SentrySpanAttribute`) and if not (in the case of pure otel spans), we try to derive them. The entire flow is **much** cleaner now instead of repeated calls to the same attributes. (For the main mapping changes in `opentelemetry/test_utils` I'd recommend reading the new code instead of the diff.)
1 parent 03659a4 commit b23507c

File tree

13 files changed

+231
-294
lines changed

13 files changed

+231
-294
lines changed

sentry_sdk/_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,3 @@ class SDKInfo(TypedDict):
262262
)
263263

264264
HttpStatusCodeRange = Union[int, Container[int]]
265-
266-
OtelExtractedSpanData = tuple[str, str, Optional[str], Optional[int], Optional[str]]

sentry_sdk/consts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ class OP:
674674
HTTP_CLIENT = "http.client"
675675
HTTP_CLIENT_STREAM = "http.client.stream"
676676
HTTP_SERVER = "http.server"
677+
HTTP = "http"
678+
MESSAGE = "message"
677679
MIDDLEWARE_DJANGO = "middleware.django"
678680
MIDDLEWARE_LITESTAR = "middleware.litestar"
679681
MIDDLEWARE_LITESTAR_RECEIVE = "middleware.litestar.receive"
@@ -705,6 +707,7 @@ class OP:
705707
QUEUE_TASK_HUEY = "queue.task.huey"
706708
QUEUE_SUBMIT_RAY = "queue.submit.ray"
707709
QUEUE_TASK_RAY = "queue.task.ray"
710+
RPC = "rpc"
708711
SUBPROCESS = "subprocess"
709712
SUBPROCESS_WAIT = "subprocess.wait"
710713
SUBPROCESS_COMMUNICATE = "subprocess.communicate"

sentry_sdk/opentelemetry/span_processor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,16 @@ def _root_span_to_transaction_event(self, span: ReadableSpan) -> Optional[Event]
219219
if profile_context:
220220
contexts["profile"] = profile_context
221221

222-
(_, description, _, http_status, _) = span_data
223-
224-
if http_status:
225-
contexts["response"] = {"status_code": http_status}
222+
if span_data.http_status:
223+
contexts["response"] = {"status_code": span_data.http_status}
226224

227225
if span.resource.attributes:
228226
contexts[OTEL_SENTRY_CONTEXT] = {"resource": dict(span.resource.attributes)}
229227

230228
event.update(
231229
{
232230
"type": "transaction",
233-
"transaction": transaction_name or description,
231+
"transaction": transaction_name or span_data.description,
234232
"transaction_info": {"source": transaction_source or "custom"},
235233
"contexts": contexts,
236234
}
@@ -257,19 +255,21 @@ def _span_to_json(self, span: ReadableSpan) -> Optional[dict[str, Any]]:
257255
span_id = format_span_id(span.context.span_id)
258256
parent_span_id = format_span_id(span.parent.span_id) if span.parent else None
259257

260-
(op, description, status, _, origin) = extract_span_data(span)
258+
span_data = extract_span_data(span)
261259

262260
span_json.update(
263261
{
264262
"trace_id": trace_id,
265263
"span_id": span_id,
266-
"op": op,
267-
"description": description,
268-
"status": status,
269-
"origin": origin or DEFAULT_SPAN_ORIGIN,
264+
"description": span_data.description,
265+
"origin": span_data.origin or DEFAULT_SPAN_ORIGIN,
270266
}
271267
)
272268

269+
if span_data.op:
270+
span_json["op"] = span_data.op
271+
if span_data.status:
272+
span_json["status"] = span_data.status
273273
if parent_span_id:
274274
span_json["parent_span_id"] = parent_span_id
275275

0 commit comments

Comments
 (0)