Skip to content

Commit 24da389

Browse files
committed
fix: use public dsm checkpoint for eventbridge
1 parent ff42108 commit 24da389

2 files changed

Lines changed: 35 additions & 56 deletions

File tree

datadog_lambda/tracing.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,12 @@ def _dsm_set_checkpoint(context_json, event_type, arn):
8585
def _dsm_set_eventbridge_checkpoint(context_json, detail_type):
8686
"""Set a DSM consume checkpoint for an EventBridge event.
8787
88-
Unlike the SQS/SNS/Kinesis helper, the EventBridge edge tags include an
89-
`exchange` tag (the bus name) to mirror the produce-side tags so the
90-
consume node pairs with the produce node. The bus name is not present in
91-
the inbound event, so it is sourced from `DD_DSM_EXCHANGE_NAME` when set.
92-
The public `set_consume_checkpoint` helper cannot emit an `exchange` tag,
93-
so the lower-level processor API is used directly.
88+
Temporary note: richer EventBridge consume checkpoint tagging is being
89+
upstreamed into dd-trace-py. Until that lands, keep this on the same
90+
public consume checkpoint API used by SQS/SNS/Kinesis and omit the
91+
EventBridge exchange tag for now.
9492
"""
95-
if not config.data_streams_enabled:
96-
return
97-
98-
if not detail_type:
99-
return
100-
101-
try:
102-
from ddtrace.data_streams import PROPAGATION_KEY_BASE_64
103-
from ddtrace.data_streams import ddtrace as ddtrace_data_streams
104-
105-
processor = getattr(ddtrace_data_streams.tracer, "data_streams_processor", None)
106-
if not processor:
107-
return
108-
109-
processor.decode_pathway_b64(
110-
context_json.get(PROPAGATION_KEY_BASE_64) if context_json else None
111-
)
112-
113-
tags = ["direction:in", "topic:" + detail_type, "type:eventbridge"]
114-
if config.dsm_exchange_name:
115-
tags.append("exchange:" + config.dsm_exchange_name)
116-
processor.set_checkpoint(tags)
117-
except Exception as e:
118-
logger.debug(
119-
f"DSM:Failed to set consume checkpoint for eventbridge {detail_type}: {e}"
120-
)
93+
_dsm_set_checkpoint(context_json, "eventbridge", detail_type)
12194

12295

12396
def _convert_xray_trace_id(xray_trace_id):

tests/test_tracing.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,13 +3831,9 @@ def test_eventbridge_sqs_data_streams_disabled(self):
38313831
class TestEventBridgeDSMLogic(unittest.TestCase):
38323832
def setUp(self):
38333833
self.lambda_context = get_mock_context()
3834-
self.mock_processor = Mock()
3835-
tracer_patcher = patch(
3836-
"ddtrace.data_streams.ddtrace.tracer",
3837-
new=SimpleNamespace(data_streams_processor=self.mock_processor),
3838-
)
3839-
tracer_patcher.start()
3840-
self.addCleanup(tracer_patcher.stop)
3834+
checkpoint_patcher = patch("ddtrace.data_streams.set_consume_checkpoint")
3835+
self.mock_checkpoint = checkpoint_patcher.start()
3836+
self.addCleanup(checkpoint_patcher.stop)
38413837
config_patcher = patch(
38423838
"datadog_lambda.config.Config.data_streams_enabled", True
38433839
)
@@ -3857,51 +3853,61 @@ def test_eventbridge_context_propagated(self):
38573853

38583854
extract_context_from_eventbridge_event(event, self.lambda_context)
38593855

3860-
self.mock_processor.decode_pathway_b64.assert_called_once_with("12345")
3861-
self.mock_processor.set_checkpoint.assert_called_once()
3862-
(tags,), _ = self.mock_processor.set_checkpoint.call_args
3863-
self.assertIn("direction:in", tags)
3864-
self.assertIn("type:eventbridge", tags)
3865-
self.assertIn("topic:MyDetailType", tags)
3866-
self.assertFalse(any(t.startswith("exchange:") for t in tags))
3856+
self.mock_checkpoint.assert_called_once()
3857+
args, kwargs = self.mock_checkpoint.call_args
3858+
self.assertEqual(args[0], "eventbridge")
3859+
self.assertEqual(args[1], "MyDetailType")
3860+
carrier_get = args[2]
3861+
self.assertEqual(carrier_get("dd-pathway-ctx-base64"), "12345")
3862+
self.assertEqual(kwargs, {"manual_checkpoint": False})
38673863

38683864
@patch("datadog_lambda.config.Config.dsm_exchange_name", "my-event-bus")
3869-
def test_eventbridge_exchange_tag_from_env(self):
3865+
def test_eventbridge_exchange_name_ignored_until_upstream_support_lands(self):
38703866
event = self._eventbridge_event()
38713867

38723868
extract_context_from_eventbridge_event(event, self.lambda_context)
38733869

3874-
(tags,), _ = self.mock_processor.set_checkpoint.call_args
3875-
self.assertIn("exchange:my-event-bus", tags)
3876-
self.assertIn("topic:MyDetailType", tags)
3877-
self.assertIn("type:eventbridge", tags)
3870+
self.mock_checkpoint.assert_called_once()
3871+
args, kwargs = self.mock_checkpoint.call_args
3872+
self.assertEqual(args[0], "eventbridge")
3873+
self.assertEqual(args[1], "MyDetailType")
3874+
carrier_get = args[2]
3875+
self.assertEqual(carrier_get("dd-pathway-ctx-base64"), "12345")
3876+
self.assertEqual(kwargs, {"manual_checkpoint": False})
38783877

38793878
def test_eventbridge_no_detail_type_skips_checkpoint(self):
38803879
event = self._eventbridge_event(detail_type=None)
38813880

38823881
extract_context_from_eventbridge_event(event, self.lambda_context)
38833882

3884-
self.mock_processor.set_checkpoint.assert_not_called()
3883+
self.mock_checkpoint.assert_not_called()
38853884

38863885
def test_eventbridge_no_dd_context_still_checkpoints(self):
38873886
event = {"detail-type": "MyDetailType", "detail": {}}
38883887

38893888
extract_context_from_eventbridge_event(event, self.lambda_context)
38903889

3891-
self.mock_processor.decode_pathway_b64.assert_called_once_with(None)
3892-
self.mock_processor.set_checkpoint.assert_called_once()
3890+
self.mock_checkpoint.assert_called_once()
3891+
args, kwargs = self.mock_checkpoint.call_args
3892+
carrier_get = args[2]
3893+
self.assertIsNone(carrier_get("dd-pathway-ctx-base64"))
3894+
self.assertEqual(kwargs, {"manual_checkpoint": False})
38933895

38943896
def test_eventbridge_missing_detail_still_checkpoints(self):
38953897
event = {"detail-type": "MyDetailType"}
38963898

38973899
extract_context_from_eventbridge_event(event, self.lambda_context)
38983900

3899-
self.mock_processor.set_checkpoint.assert_called_once()
3901+
self.mock_checkpoint.assert_called_once()
3902+
args, kwargs = self.mock_checkpoint.call_args
3903+
carrier_get = args[2]
3904+
self.assertIsNone(carrier_get("dd-pathway-ctx-base64"))
3905+
self.assertEqual(kwargs, {"manual_checkpoint": False})
39003906

39013907
@patch("datadog_lambda.config.Config.data_streams_enabled", False)
39023908
def test_eventbridge_data_streams_disabled(self):
39033909
event = self._eventbridge_event()
39043910

39053911
extract_context_from_eventbridge_event(event, self.lambda_context)
39063912

3907-
self.mock_processor.set_checkpoint.assert_not_called()
3913+
self.mock_checkpoint.assert_not_called()

0 commit comments

Comments
 (0)