Skip to content

Commit cf54da0

Browse files
committed
.
1 parent df95074 commit cf54da0

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

sentry_sdk/integrations/opentelemetry/potel_span_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ def _root_span_to_transaction_event(self, span):
179179

180180
transaction_name, transaction_source = extract_transaction_name_source(span)
181181
span_data = extract_span_data(span)
182-
(_, description, status, http_status, _) = span_data
183-
184182
trace_context = get_trace_context(span, span_data=span_data)
185183
contexts = {"trace": trace_context}
186184

187185
profile_context = get_profile_context(span)
188186
if profile_context:
189187
contexts["profile"] = profile_context
190188

189+
(_, description, _, http_status, _) = span_data
190+
191191
if http_status:
192192
contexts["response"] = {"status_code": http_status}
193193

sentry_sdk/integrations/opentelemetry/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def extract_span_data(span):
114114
description = span.name
115115
status, http_status = extract_span_status(span)
116116
origin = None
117-
118117
if span.attributes is None:
119118
return (op, description, status, http_status, origin)
120119

@@ -133,11 +132,23 @@ def extract_span_data(span):
133132

134133
rpc_service = span.attributes.get(SpanAttributes.RPC_SERVICE)
135134
if rpc_service:
136-
return ("rpc", description, status, http_status, origin)
135+
return (
136+
span.attributes.get(SentrySpanAttribute.OP) or "rpc",
137+
description,
138+
status,
139+
http_status,
140+
origin,
141+
)
137142

138143
messaging_system = span.attributes.get(SpanAttributes.MESSAGING_SYSTEM)
139144
if messaging_system:
140-
return ("message", description, status, http_status, origin)
145+
return (
146+
span.attributes.get(SentrySpanAttribute.OP) or "message",
147+
description,
148+
status,
149+
http_status,
150+
origin,
151+
)
141152

142153
faas_trigger = span.attributes.get(SpanAttributes.FAAS_TRIGGER)
143154
if faas_trigger:

sentry_sdk/integrations/rq.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sentry_sdk.integrations.logging import ignore_logger
77
from sentry_sdk.tracing import TRANSACTION_SOURCE_TASK
88
from sentry_sdk.utils import (
9+
_serialize_span_attribute,
910
capture_internal_exceptions,
1011
ensure_integration_enabled,
1112
event_from_exception,
@@ -192,4 +193,10 @@ def _prepopulate_attributes(job, queue):
192193
if getattr(queue, prop, None) is not None:
193194
attributes[attr] = getattr(queue, prop)
194195

196+
try:
197+
attributes["rq.job.args"] = _serialize_span_attribute(job.args)
198+
attributes["rq.job.kwargs"] = _serialize_span_attribute(job.kwargs)
199+
except Exception:
200+
pass
201+
195202
return attributes

tests/integrations/rq/test_rq.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ def test_transaction_with_error(
118118
)
119119

120120
assert envelope["type"] == "transaction"
121-
assert envelope["contexts"]["trace"] == error_event["contexts"]["trace"]
121+
assert envelope["contexts"]["trace"] == DictionaryContaining(
122+
error_event["contexts"]["trace"]
123+
)
122124
assert envelope["transaction"] == error_event["transaction"]
123125
assert envelope["extra"]["rq-job"] == DictionaryContaining(
124126
{
@@ -148,10 +150,7 @@ def test_error_has_trace_context_if_tracing_disabled(
148150
assert error_event["contexts"]["trace"]
149151

150152

151-
def test_tracing_enabled(
152-
sentry_init,
153-
capture_events,
154-
):
153+
def test_tracing_enabled(sentry_init, capture_events, DictionaryContaining):
155154
sentry_init(integrations=[RqIntegration()], traces_sample_rate=1.0)
156155
events = capture_events()
157156

@@ -165,12 +164,10 @@ def test_tracing_enabled(
165164

166165
assert error_event["transaction"] == "tests.integrations.rq.test_rq.crashing_job"
167166
assert transaction["transaction"] == "tests.integrations.rq.test_rq.crashing_job"
168-
for trace_key in error_event["contexts"]["trace"]:
169-
assert trace_key in transaction["contexts"]["trace"]
170-
assert (
171-
error_event["contexts"]["trace"][trace_key]
172-
== transaction["contexts"]["trace"][trace_key]
173-
)
167+
assert (
168+
DictionaryContaining(error_event["contexts"]["trace"])
169+
== transaction["contexts"]["trace"]
170+
)
174171

175172

176173
def test_tracing_disabled(
@@ -223,9 +220,7 @@ def test_transaction_no_error(
223220
)
224221

225222

226-
def test_traces_sampler_gets_correct_values_in_sampling_context(
227-
sentry_init, DictionaryContaining, ObjectDescribedBy # noqa:N803
228-
):
223+
def test_traces_sampler_gets_correct_values_in_sampling_context(sentry_init):
229224
traces_sampler = mock.Mock(return_value=True)
230225
sentry_init(integrations=[RqIntegration()], traces_sampler=traces_sampler)
231226

@@ -235,22 +230,12 @@ def test_traces_sampler_gets_correct_values_in_sampling_context(
235230
queue.enqueue(do_trick, "Bodhi", trick="roll over")
236231
worker.work(burst=True)
237232

238-
traces_sampler.assert_any_call(
239-
DictionaryContaining(
240-
{
241-
"rq_job": ObjectDescribedBy(
242-
type=rq.job.Job,
243-
attrs={
244-
"description": "tests.integrations.rq.test_rq.do_trick('Bodhi', trick='roll over')",
245-
"result": "Bodhi, can you roll over? Good dog!",
246-
"func_name": "tests.integrations.rq.test_rq.do_trick",
247-
"args": ("Bodhi",),
248-
"kwargs": {"trick": "roll over"},
249-
},
250-
),
251-
}
252-
)
253-
)
233+
sampling_context = traces_sampler.call_args_list[0][0][0]
234+
assert sampling_context["messaging.system"] == "rq"
235+
assert sampling_context["rq.job.args"] == ["Bodhi"]
236+
assert sampling_context["rq.job.kwargs"] == '{"trick": "roll over"}'
237+
assert sampling_context["messaging.message.id"]
238+
assert sampling_context["messaging.destination.name"] == "default"
254239

255240

256241
@pytest.mark.skipif(

0 commit comments

Comments
 (0)