Skip to content

Commit eb5dff0

Browse files
committed
ref(test-callback-typing): Type before_send_span with public SpanJSON
Uses the SpanJSON type now exported from sentry_sdk.types by getsentry/sentry-python#7331, replacing the dict[str, Any] placeholder and the comment explaining why no public span type was available. Verified with mypy against the local sentry-python checkout: SpanJSON resolves to the real TypedDict (not Any) and invalid keys are rejected.
1 parent cfd6e23 commit eb5dff0

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

test-callback-typing/main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
22
import os
3-
from typing import Any
43

54
import sentry_sdk
6-
from sentry_sdk.types import Event, Hint, SamplingContext, Breadcrumb, BreadcrumbHint, MonitorConfig
5+
from sentry_sdk.types import Event, Hint, SamplingContext, Breadcrumb, BreadcrumbHint, MonitorConfig, SpanJSON
76
from sentry_sdk.crons import MonitorStatus, capture_checkin
87

98

@@ -23,11 +22,7 @@ def my_before_send(event: Event, hint: Hint) -> Event | None:
2322
return event
2423

2524

26-
# NOTE: sentry_sdk.types has no public span type to annotate this callback with.
27-
# `SpanJSON` exists only in the private `sentry_sdk._types` module, which is not
28-
# re-exported publicly, so `dict[str, Any]` is the best available annotation here.
29-
# Spans cannot be dropped by this callback, so the return type is not Optional.
30-
def my_before_send_span(span: dict[str, Any], hint: Hint) -> dict[str, Any]:
25+
def my_before_send_span(span: SpanJSON, hint: Hint) -> SpanJSON:
3126
return span
3227

3328

0 commit comments

Comments
 (0)