Skip to content

Commit d307fe1

Browse files
committed
Merge branch 'potel-base' into ivana/sampling-context
2 parents ce815e8 + 3f638f7 commit d307fe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+157
-76
lines changed

sentry_sdk/ai/monitoring.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def sync_wrapped(*args, **kwargs):
3333
curr_pipeline = _ai_pipeline_name.get()
3434
op = span_kwargs.get("op", "ai.run" if curr_pipeline else "ai.pipeline")
3535

36-
with start_span(name=description, op=op, **span_kwargs) as span:
36+
with start_span(
37+
name=description, op=op, only_if_parent=True, **span_kwargs
38+
) as span:
3739
for k, v in kwargs.pop("sentry_tags", {}).items():
3840
span.set_tag(k, v)
3941
for k, v in kwargs.pop("sentry_data", {}).items():
@@ -62,7 +64,9 @@ async def async_wrapped(*args, **kwargs):
6264
curr_pipeline = _ai_pipeline_name.get()
6365
op = span_kwargs.get("op", "ai.run" if curr_pipeline else "ai.pipeline")
6466

65-
with start_span(name=description, op=op, **span_kwargs) as span:
67+
with start_span(
68+
name=description, op=op, only_if_parent=True, **span_kwargs
69+
) as span:
6670
for k, v in kwargs.pop("sentry_tags", {}).items():
6771
span.set_tag(k, v)
6872
for k, v in kwargs.pop("sentry_data", {}).items():

sentry_sdk/integrations/aiohttp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ async def on_request_start(session, trace_config_ctx, params):
228228
name="%s %s"
229229
% (method, parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE),
230230
origin=AioHttpIntegration.origin,
231+
only_if_parent=True,
231232
)
232233

233234
data = {

sentry_sdk/integrations/anthropic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _sentry_patched_create_common(f, *args, **kwargs):
151151
op=OP.ANTHROPIC_MESSAGES_CREATE,
152152
description="Anthropic messages create",
153153
origin=AnthropicIntegration.origin,
154+
only_if_parent=True,
154155
)
155156
span.__enter__()
156157

sentry_sdk/integrations/arq.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.integrations import DidNotEnable, Integration
66
from sentry_sdk.integrations.logging import ignore_logger
77
from sentry_sdk.scope import should_send_default_pii
8-
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_TASK
8+
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
99
from sentry_sdk.utils import (
1010
capture_internal_exceptions,
1111
ensure_integration_enabled,
@@ -37,6 +37,8 @@
3737

3838
ARQ_CONTROL_FLOW_EXCEPTIONS = (JobExecutionFailed, Retry, RetryJob)
3939

40+
DEFAULT_TRANSACTION_NAME = "unknown arq task"
41+
4042

4143
class ArqIntegration(Integration):
4244
identifier = "arq"
@@ -79,7 +81,10 @@ async def _sentry_enqueue_job(self, function, *args, **kwargs):
7981
return await old_enqueue_job(self, function, *args, **kwargs)
8082

8183
with sentry_sdk.start_span(
82-
op=OP.QUEUE_SUBMIT_ARQ, name=function, origin=ArqIntegration.origin
84+
op=OP.QUEUE_SUBMIT_ARQ,
85+
name=function,
86+
origin=ArqIntegration.origin,
87+
only_if_parent=True,
8388
):
8489
return await old_enqueue_job(self, function, *args, **kwargs)
8590

@@ -98,18 +103,21 @@ async def _sentry_run_job(self, job_id, score):
98103

99104
with sentry_sdk.isolation_scope() as scope:
100105
scope._name = "arq"
106+
scope.set_transaction_name(
107+
DEFAULT_TRANSACTION_NAME,
108+
source=TRANSACTION_SOURCE_TASK,
109+
)
101110
scope.clear_breadcrumbs()
102111

103-
transaction = Transaction(
104-
name="unknown arq task",
105-
status="ok",
112+
with sentry_sdk.start_span(
106113
op=OP.QUEUE_TASK_ARQ,
114+
name=DEFAULT_TRANSACTION_NAME,
107115
source=TRANSACTION_SOURCE_TASK,
108116
origin=ArqIntegration.origin,
109-
)
110-
111-
with sentry_sdk.start_transaction(transaction):
112-
return await old_run_job(self, job_id, score)
117+
) as span:
118+
return_value = await old_run_job(self, job_id, score)
119+
span.set_status(SPANSTATUS.OK)
120+
return return_value
113121

114122
Worker.run_job = _sentry_run_job
115123

sentry_sdk/integrations/asyncio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async def _coro_creating_hub_and_span():
4848
op=OP.FUNCTION,
4949
name=get_name(coro),
5050
origin=AsyncioIntegration.origin,
51+
only_if_parent=True,
5152
):
5253
try:
5354
result = await coro

sentry_sdk/integrations/asyncpg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
169169
op=OP.DB,
170170
name="connect",
171171
origin=AsyncPGIntegration.origin,
172+
only_if_parent=True,
172173
) as span:
173174
data = _get_db_data(
174175
addr=kwargs.get("addr"),

sentry_sdk/integrations/boto3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _sentry_request_created(service_id, request, operation_name, **kwargs):
7272
op=OP.HTTP_CLIENT,
7373
name=description,
7474
origin=Boto3Integration.origin,
75+
only_if_parent=True,
7576
)
7677

7778
data = {

sentry_sdk/integrations/celery/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ def sentry_publish(self, *args, **kwargs):
495495
op=OP.QUEUE_PUBLISH,
496496
name=task_name,
497497
origin=CeleryIntegration.origin,
498+
only_if_parent=True,
498499
) as span:
499500
if task_id is not None:
500501
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task_id)

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _inner(*args: P.args, **kwargs: P.kwargs) -> T:
8989
op=OP.DB,
9090
name=query,
9191
origin=ClickhouseDriverIntegration.origin,
92+
only_if_parent=True,
9293
)
9394

9495
connection._sentry_span = span # type: ignore[attr-defined]

sentry_sdk/integrations/cohere.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def new_chat(*args, **kwargs):
147147
op=consts.OP.COHERE_CHAT_COMPLETIONS_CREATE,
148148
name="cohere.client.Chat",
149149
origin=CohereIntegration.origin,
150+
only_if_parent=True,
150151
)
151152
span.__enter__()
152153
try:
@@ -233,6 +234,7 @@ def new_embed(*args, **kwargs):
233234
op=consts.OP.COHERE_EMBEDDINGS_CREATE,
234235
name="Cohere Embedding Creation",
235236
origin=CohereIntegration.origin,
237+
only_if_parent=True,
236238
) as span:
237239
if "texts" in kwargs and (
238240
should_send_default_pii() and integration.include_prompts

0 commit comments

Comments
 (0)