diff --git a/CHANGELOG.md b/CHANGELOG.md index 22eaa4a017..52b8b0e331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,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 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..3ba8af1c02 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( + "retry_attempts", metadata["RetryAttempts"], + ) + if "HTTPStatusCode" in metadata: span.set_attribute( "http.status_code", metadata["HTTPStatusCode"], diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 23dc32d2dc..72f5f5fea9 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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "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", + "retry_attempts": 0, "http.status_code": 200, }, )