From 51acc5015a75646e14f7381ce146222c8d76fefb Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Wed, 23 Dec 2020 21:05:17 -0500 Subject: [PATCH 1/5] Add back retry_attempts to botocore --- .../src/opentelemetry/instrumentation/botocore/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index 713a1e6a61..a537f2f201 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -153,6 +153,11 @@ def _patched_api_call(self, original_func, instance, args, kwargs): "aws.request_id", req_id, ) + if "RetryAttempts" in metadata: + span.set_attribute( + "aws.retry_attempts", metadata["RetryAttempts"], + ) + if "HTTPStatusCode" in metadata: span.set_attribute( "http.status_code", metadata["HTTPStatusCode"], From b11c0163bfc3aad18d3fa8aa966dea2a441a7233 Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Wed, 23 Dec 2020 21:45:48 -0500 Subject: [PATCH 2/5] Add retry_attempts into tests --- .../tests/test_botocore_instrumentation.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 23dc32d2dc..a79ef9ccf9 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -69,6 +69,7 @@ def test_traced_client(self): "aws.region": "us-west-2", "aws.request_id": "fdcdcab1-ae5c-489e-9c33-4637c5dda355", "aws.service": "ec2", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -116,6 +117,7 @@ def test_s3_client(self): "aws.operation": "ListBuckets", "aws.region": "us-west-2", "aws.service": "s3", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -159,6 +161,7 @@ def test_s3_put(self): "aws.operation": "CreateBucket", "aws.region": "us-west-2", "aws.service": "s3", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -169,6 +172,7 @@ def test_s3_put(self): "aws.operation": "PutObject", "aws.region": "us-west-2", "aws.service": "s3", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -180,6 +184,7 @@ def test_s3_put(self): "aws.operation": "GetObject", "aws.region": "us-west-2", "aws.service": "s3", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -203,6 +208,7 @@ def test_sqs_client(self): "aws.operation": "ListQueues", "aws.region": "us-east-1", "aws.service": "sqs", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -233,6 +239,7 @@ def test_sqs_send_message(self): "aws.operation": "CreateQueue", "aws.region": "us-east-1", "aws.service": "sqs", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -248,6 +255,7 @@ def test_sqs_send_message(self): "aws.queue_url": response["QueueUrl"], "aws.region": "us-east-1", "aws.service": "sqs", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -270,6 +278,7 @@ def test_kinesis_client(self): "aws.operation": "ListStreams", "aws.region": "us-east-1", "aws.service": "kinesis", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -315,6 +324,7 @@ def test_lambda_client(self): "aws.operation": "ListFunctions", "aws.region": "us-east-1", "aws.service": "lambda", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -335,6 +345,7 @@ def test_kms_client(self): "aws.operation": "ListKeys", "aws.region": "us-east-1", "aws.service": "kms", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -359,6 +370,7 @@ def test_sts_client(self): "aws.region": "us-east-1", "aws.request_id": "c6104cbe-af31-11e0-8154-cbc7ccf896c7", "aws.service": "sts", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -395,6 +407,7 @@ def check_headers(**kwargs): "aws.region": "us-west-2", "aws.request_id": "fdcdcab1-ae5c-489e-9c33-4637c5dda355", "aws.service": "ec2", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -463,6 +476,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -478,6 +492,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) @@ -493,6 +508,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", + "aws.retry_attempts": 0, "http.status_code": 200, }, ) From ebe9afa3484fd6badb0336583b8c70b8b5f9816b Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Sat, 26 Dec 2020 10:48:53 -0500 Subject: [PATCH 3/5] fixup! Add back retry_attempts to botocore --- .../src/opentelemetry/instrumentation/botocore/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index a537f2f201..3ba8af1c02 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -155,7 +155,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs): if "RetryAttempts" in metadata: span.set_attribute( - "aws.retry_attempts", metadata["RetryAttempts"], + "retry_attempts", metadata["RetryAttempts"], ) if "HTTPStatusCode" in metadata: From 8c74b6a14039e51b15a7d0265b7c1ad82b29dc12 Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Sat, 26 Dec 2020 10:48:53 -0500 Subject: [PATCH 4/5] fixup! Add retry_attempts into tests --- .../tests/test_botocore_instrumentation.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index a79ef9ccf9..72f5f5fea9 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -69,7 +69,7 @@ def test_traced_client(self): "aws.region": "us-west-2", "aws.request_id": "fdcdcab1-ae5c-489e-9c33-4637c5dda355", "aws.service": "ec2", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -117,7 +117,7 @@ def test_s3_client(self): "aws.operation": "ListBuckets", "aws.region": "us-west-2", "aws.service": "s3", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -161,7 +161,7 @@ def test_s3_put(self): "aws.operation": "CreateBucket", "aws.region": "us-west-2", "aws.service": "s3", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -172,7 +172,7 @@ def test_s3_put(self): "aws.operation": "PutObject", "aws.region": "us-west-2", "aws.service": "s3", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -184,7 +184,7 @@ def test_s3_put(self): "aws.operation": "GetObject", "aws.region": "us-west-2", "aws.service": "s3", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -208,7 +208,7 @@ def test_sqs_client(self): "aws.operation": "ListQueues", "aws.region": "us-east-1", "aws.service": "sqs", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -239,7 +239,7 @@ def test_sqs_send_message(self): "aws.operation": "CreateQueue", "aws.region": "us-east-1", "aws.service": "sqs", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -255,7 +255,7 @@ def test_sqs_send_message(self): "aws.queue_url": response["QueueUrl"], "aws.region": "us-east-1", "aws.service": "sqs", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -278,7 +278,7 @@ def test_kinesis_client(self): "aws.operation": "ListStreams", "aws.region": "us-east-1", "aws.service": "kinesis", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -324,7 +324,7 @@ def test_lambda_client(self): "aws.operation": "ListFunctions", "aws.region": "us-east-1", "aws.service": "lambda", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -345,7 +345,7 @@ def test_kms_client(self): "aws.operation": "ListKeys", "aws.region": "us-east-1", "aws.service": "kms", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -370,7 +370,7 @@ def test_sts_client(self): "aws.region": "us-east-1", "aws.request_id": "c6104cbe-af31-11e0-8154-cbc7ccf896c7", "aws.service": "sts", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -407,7 +407,7 @@ def check_headers(**kwargs): "aws.region": "us-west-2", "aws.request_id": "fdcdcab1-ae5c-489e-9c33-4637c5dda355", "aws.service": "ec2", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -476,7 +476,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -492,7 +492,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) @@ -508,7 +508,7 @@ def test_dynamodb_client(self): "aws.region": "us-west-2", "aws.service": "dynamodb", "aws.table_name": "test_table_name", - "aws.retry_attempts": 0, + "retry_attempts": 0, "http.status_code": 200, }, ) From 880f6438d2b6fba9d0ad660ed916bceb6c47c106 Mon Sep 17 00:00:00 2001 From: Thomas Desrosiers Date: Tue, 5 Jan 2021 20:01:47 -0500 Subject: [PATCH 5/5] Changelog :D --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c76278bc..d0a1e80a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#236](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/236)) - Add README and example app for Prometheus Remote Write Exporter ([#227](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/227])) +- `opentelemetry-instrumentation-botocore` Adds a field to report the number of retries it take to complete an API call + ([#275](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/275)) ### Changed - `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-wsgi` Return `None` for `CarrierGetter` if key not found