Skip to content

Commit

Permalink
Add attributes to links in subscribe_spans to nack_spans
Browse files Browse the repository at this point in the history
  • Loading branch information
mukund-ananthu committed Sep 24, 2024
1 parent 815f2a3 commit 94feeec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ def modify_ack_deadline(
): # pragma: NO COVER
nack_span_context: trace.SpanContext = nack_span.get_span_context()
for subscribe_span in subscribe_spans:
subscribe_span.add_link(nack_span_context)
subscribe_span.add_link(
context=nack_span_context,
attributes={
"messaging.operation.name": "nack",
},
)
requests_to_retry: List[requests.ModAckRequest]
requests_completed: Optional[List[requests.ModAckRequest]] = None
if default_deadline is None:
Expand Down Expand Up @@ -595,7 +600,12 @@ def _retry_modacks(self, requests_to_retry):
): # pragma: NO COVER
nack_span_context: trace.SpanContext = nack_span.get_span_context()
for subscribe_span in subscribe_spans:
subscribe_span.add_link(nack_span_context)
subscribe_span.add_link(
context=nack_span_context,
attributes={
"messaging.operation.name": "nack",
},
)
requests_completed, requests_to_retry = self._manager.send_unary_modack(
modify_deadline_ack_ids=[req.ack_id for req in requests_to_retry],
modify_deadline_seconds=[req.seconds for req in requests_to_retry],
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/pubsub_v1/subscriber/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@ def test_opentelemetry_retry_nacks(span_exporter):
# span.
assert len(spans[1].links) == 1
assert spans[1].links[0].context == nack_span.context
assert len(spans[1].links[0].attributes) == 1
assert spans[1].links[0].attributes["messaging.operation.name"] == "nack"
# This subscribe span is not sampled, so we expect it to not be linked to
# the nack span
assert len(spans[2].links) == 0
Expand Down Expand Up @@ -1040,6 +1042,8 @@ def test_opentelemetry_nack(span_exporter):
# span.
assert len(spans[1].links) == 1
assert spans[1].links[0].context == nack_span.context
assert len(spans[1].links[0].attributes) == 1
assert spans[1].links[0].attributes["messaging.operation.name"] == "nack"
# This subscribe span is not sampled, so we expect it to not be linked to
# the nack span
assert len(spans[2].links) == 0
Expand Down

0 comments on commit 94feeec

Please sign in to comment.