Skip to content

Commit fda5465

Browse files
author
Colton Myers
committed
Add AWS Request ID to botocore span context
1 parent b4edea3 commit fda5465

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

‎elasticapm/instrumentation/packages/asyncio/aiobotocore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs):
5353
result = await wrapped(*args, **kwargs)
5454
if service in post_span_modifiers:
5555
post_span_modifiers[service](span, args, kwargs, result)
56+
request_id = result.get("ResponseMetadata", {}).get("RequestId")
57+
if request_id:
58+
span.update_context("http", {"request": {"id": request_id}})
5659
return result

‎elasticapm/instrumentation/packages/botocore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def call(self, module, method, wrapped, instance, args, kwargs):
106106
result = wrapped(*args, **kwargs)
107107
if service in post_span_modifiers:
108108
post_span_modifiers[service](span, args, kwargs, result)
109+
request_id = result.get("ResponseMetadata", {}).get("RequestId")
110+
if request_id:
111+
span.update_context("http", {"request": {"id": request_id}})
109112
return result
110113

111114

‎tests/instrumentation/botocore_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_botocore_instrumentation(instrument, elasticapm_client):
9797
assert span["type"] == "aws"
9898
assert span["subtype"] == "ec2"
9999
assert span["action"] == "DescribeInstances"
100+
assert span["context"]["http"]["request"]["id"]
100101

101102

102103
def test_s3(instrument, elasticapm_client):
@@ -117,6 +118,7 @@ def test_s3(instrument, elasticapm_client):
117118
assert span["context"]["destination"]["service"]["name"] == "s3"
118119
assert span["context"]["destination"]["service"]["resource"] == "xyz"
119120
assert span["context"]["destination"]["service"]["type"] == "storage"
121+
assert span["context"]["http"]["request"]["id"]
120122
assert spans[0]["name"] == "S3 CreateBucket xyz"
121123
assert spans[0]["action"] == "CreateBucket"
122124
assert spans[1]["name"] == "S3 PutObject xyz"
@@ -175,6 +177,7 @@ def test_dynamodb(instrument, elasticapm_client, dynamodb):
175177
assert span["context"]["destination"]["service"]["name"] == "dynamodb"
176178
assert span["context"]["destination"]["service"]["resource"] == "Movies"
177179
assert span["context"]["destination"]["service"]["type"] == "db"
180+
assert span["context"]["http"]["request"]["id"]
178181
assert spans[0]["name"] == "DynamoDB PutItem Movies"
179182
assert spans[1]["name"] == "DynamoDB Query Movies"
180183
assert spans[1]["context"]["db"]["statement"] == "title = :v1 and #y = :v2"
@@ -200,6 +203,7 @@ def test_sns(instrument, elasticapm_client):
200203
assert spans[2]["context"]["destination"]["service"]["name"] == "sns"
201204
assert spans[2]["context"]["destination"]["service"]["resource"] == "sns/mytopic"
202205
assert spans[2]["context"]["destination"]["service"]["type"] == "messaging"
206+
assert spans[2]["context"]["http"]["request"]["id"]
203207

204208

205209
def test_sqs_send(instrument, elasticapm_client, sqs_client_and_queue):
@@ -222,6 +226,7 @@ def test_sqs_send(instrument, elasticapm_client, sqs_client_and_queue):
222226
assert span["context"]["destination"]["service"]["name"] == "sqs"
223227
assert span["context"]["destination"]["service"]["resource"] == "sqs/myqueue"
224228
assert span["context"]["destination"]["service"]["type"] == "messaging"
229+
assert span["context"]["http"]["request"]["id"]
225230

226231
messages = sqs.receive_message(
227232
QueueUrl=queue_url,

0 commit comments

Comments
 (0)