Skip to content

Add AWS Request ID to botocore span context #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ endif::[]
===== Features

* Add redis query to context data for redis instrumentation {pull}1406[#1406]
* Add AWS request ID to all botocore spans (at `span.context.http.request.id`) {pull}1625[#1625]

[float]
===== Bug fixes
Expand Down
3 changes: 3 additions & 0 deletions elasticapm/instrumentation/packages/asyncio/aiobotocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs):
result = await wrapped(*args, **kwargs)
if service in post_span_modifiers:
post_span_modifiers[service](span, args, kwargs, result)
request_id = result.get("ResponseMetadata", {}).get("RequestId")
if request_id:
span.update_context("http", {"request": {"id": request_id}})
return result
3 changes: 3 additions & 0 deletions elasticapm/instrumentation/packages/botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def call(self, module, method, wrapped, instance, args, kwargs):
result = wrapped(*args, **kwargs)
if service in post_span_modifiers:
post_span_modifiers[service](span, args, kwargs, result)
request_id = result.get("ResponseMetadata", {}).get("RequestId")
if request_id:
span.update_context("http", {"request": {"id": request_id}})
return result


Expand Down
5 changes: 5 additions & 0 deletions tests/instrumentation/botocore_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_botocore_instrumentation(instrument, elasticapm_client):
assert span["type"] == "aws"
assert span["subtype"] == "ec2"
assert span["action"] == "DescribeInstances"
assert span["context"]["http"]["request"]["id"]


def test_s3(instrument, elasticapm_client):
Expand All @@ -117,6 +118,7 @@ def test_s3(instrument, elasticapm_client):
assert span["context"]["destination"]["service"]["name"] == "s3"
assert span["context"]["destination"]["service"]["resource"] == "xyz"
assert span["context"]["destination"]["service"]["type"] == "storage"
assert span["context"]["http"]["request"]["id"]
assert spans[0]["name"] == "S3 CreateBucket xyz"
assert spans[0]["action"] == "CreateBucket"
assert spans[1]["name"] == "S3 PutObject xyz"
Expand Down Expand Up @@ -175,6 +177,7 @@ def test_dynamodb(instrument, elasticapm_client, dynamodb):
assert span["context"]["destination"]["service"]["name"] == "dynamodb"
assert span["context"]["destination"]["service"]["resource"] == "Movies"
assert span["context"]["destination"]["service"]["type"] == "db"
assert span["context"]["http"]["request"]["id"]
assert spans[0]["name"] == "DynamoDB PutItem Movies"
assert spans[1]["name"] == "DynamoDB Query Movies"
assert spans[1]["context"]["db"]["statement"] == "title = :v1 and #y = :v2"
Expand All @@ -200,6 +203,7 @@ def test_sns(instrument, elasticapm_client):
assert spans[2]["context"]["destination"]["service"]["name"] == "sns"
assert spans[2]["context"]["destination"]["service"]["resource"] == "sns/mytopic"
assert spans[2]["context"]["destination"]["service"]["type"] == "messaging"
assert spans[2]["context"]["http"]["request"]["id"]


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

messages = sqs.receive_message(
QueueUrl=queue_url,
Expand Down