File tree Expand file tree Collapse file tree 5 files changed +21
-2
lines changed Expand file tree Collapse file tree 5 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ endif::[]
3939 * Add support for instrumenting the Elasticsearch 8 Python client {pull}1642[#1642]
4040 * Add `*principal*` to default `sanitize_field_names` configuration {pull}1664[#1664]
4141 * Add docs and better support for custom metrics, including in AWS Lambda {pull}1643[#1643]
42+ * Add support for capturing span links from AWS SQS in AWS Lambda {pull}1662[#1662]
4243
4344[float]
4445===== Bug fixes
Original file line number Diff line number Diff line change @@ -302,6 +302,7 @@ def begin_transaction(
302302 :param trace_parent: an optional TraceParent object for distributed tracing
303303 :param start: override the start timestamp, mostly useful for testing
304304 :param auto_activate: whether to set this transaction in execution_context
305+ :param links: a sequence of traceparent objects to causally link this transaction with
305306 :return: the started transaction object
306307 """
307308 if self .config .is_recording :
Original file line number Diff line number Diff line change @@ -184,7 +184,16 @@ def __enter__(self):
184184 transaction_type = "messaging"
185185 transaction_name = "RECEIVE {}" .format (record ["eventSourceARN" ].split (":" )[5 ])
186186
187- self .transaction = self .client .begin_transaction (transaction_type , trace_parent = trace_parent )
187+ if "Records" in self .event :
188+ links = [
189+ TraceParent .from_string (record ["messageAttributes" ]["traceparent" ]["stringValue" ])
190+ for record in self .event ["Records" ][:1000 ]
191+ if "messageAttributes" in record and "traceparent" in record ["messageAttributes" ]
192+ ]
193+ else :
194+ links = []
195+
196+ self .transaction = self .client .begin_transaction (transaction_type , trace_parent = trace_parent , links = links )
188197 elasticapm .set_transaction_name (transaction_name , override = False )
189198 if self .source in SERVERLESS_HTTP_REQUEST :
190199 elasticapm .set_context (
Original file line number Diff line number Diff line change 2828 "stringListValues" : [],
2929 "binaryListValues" : [],
3030 "dataType" : " String"
31+ },
32+ "traceparent" : {
33+ "stringValue" : " 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00" ,
34+ "stringListValues" : [],
35+ "binaryListValues" : [],
36+ "dataType" : " String"
3137 }
3238 },
3339 "md5OfBody" : " 5eb63bbbe01eeed093cb22bb8f5acdc3" ,
3642 "awsRegion" : " us-east-1"
3743 }
3844 ]
39- }
45+ }
Original file line number Diff line number Diff line change @@ -324,6 +324,8 @@ def test_func(event, context):
324324 assert transaction ["span_count" ]["started" ] == 1
325325 assert transaction ["context" ]["message" ]["headers" ]["Population" ] == "1250800"
326326 assert transaction ["context" ]["message" ]["headers" ]["City" ] == "Any City"
327+ assert len (transaction ["links" ]) == 1
328+ assert transaction ["links" ][0 ] == {"trace_id" : "0af7651916cd43dd8448eb211c80319c" , "span_id" : "b7ad6b7169203331" }
327329
328330
329331def test_capture_serverless_s3_batch (event_s3_batch , context , elasticapm_client ):
You can’t perform that action at this time.
0 commit comments