Skip to content

Commit cfd6e23

Browse files
committed
feat(test-callback-typing): Enable span streaming
Turn on top-level trace_lifecycle="stream" and swap the before_send_transaction callback for before_send_span, matching the new streamed-span callback API. Bump the sentry-sdk dependency floor to >=2.68.1, the version that introduced trace_lifecycle.
1 parent 5ee845a commit cfd6e23

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

test-callback-typing/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
from typing import Any
34

45
import sentry_sdk
56
from sentry_sdk.types import Event, Hint, SamplingContext, Breadcrumb, BreadcrumbHint, MonitorConfig
@@ -22,8 +23,12 @@ def my_before_send(event: Event, hint: Hint) -> Event | None:
2223
return event
2324

2425

25-
def my_before_send_transaction(event: Event, hint: Hint) -> Event | None:
26-
return event
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]:
31+
return span
2732

2833

2934
def my_before_breadcrumb(crumb: Breadcrumb, hint: BreadcrumbHint) -> Breadcrumb | None:
@@ -37,14 +42,15 @@ async def main() -> None:
3742
dsn=os.getenv("SENTRY_DSN", None),
3843
environment=os.getenv("ENV", "local"),
3944
traces_sample_rate=1.0,
45+
trace_lifecycle="stream",
4046
profiles_sample_rate=1.0,
4147
send_default_pii=True,
4248
debug=True,
4349
error_sampler=my_error_sampler,
4450
traces_sampler=my_traces_sampler,
4551
profiles_sampler=my_profiles_sampler,
4652
before_send=my_before_send,
47-
before_send_transaction=my_before_send_transaction,
53+
before_send_span=my_before_send_span,
4854
before_breadcrumb=my_before_breadcrumb,
4955
)
5056

test-callback-typing/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies = [
77
"ipdb>=0.13.13",
88
"mypy>=1.15.0",
99
"ruff>=0.11.5",
10-
"sentry-sdk",
10+
"sentry-sdk>=2.68.1",
1111
"typing-extensions>=4.13.2",
1212
]
1313

0 commit comments

Comments
 (0)