Skip to content

Commit 7e8b5bb

Browse files
authored
Suppress botocore downstream instrumentation like urllib3 (open-telemetry#563)
1 parent 3a1746a commit 7e8b5bb

File tree

2 files changed

+15
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4545
([#562](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/562))
4646
- `opentelemetry-instrumentation-django` Fix AttributeError: ResolverMatch object has no attribute route
4747
([#581](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581))
48+
- `opentelemetry-instrumentation-botocore` Suppress botocore downstream instrumentation like urllib3
49+
([#563](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/563))
4850

4951
### Added
5052
- `opentelemetry-instrumentation-httpx` Add `httpx` instrumentation

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868

6969
logger = logging.getLogger(__name__)
7070

71+
# A key to a context variable to avoid creating duplicate spans when instrumenting
72+
# both botocore.client and urllib3.connectionpool.HTTPConnectionPool.urlopen since
73+
# botocore calls urlopen
74+
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context_api.create_key(
75+
"suppress_http_instrumentation"
76+
)
77+
7178

7279
# pylint: disable=unused-argument
7380
def _patched_endpoint_prepare_request(wrapped, instance, args, kwargs):
@@ -161,10 +168,16 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
161168
"aws.table_name", api_params["TableName"]
162169
)
163170

171+
token = context_api.attach(
172+
context_api.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
173+
)
174+
164175
try:
165176
result = original_func(*args, **kwargs)
166177
except ClientError as ex:
167178
error = ex
179+
finally:
180+
context_api.detach(token)
168181

169182
if error:
170183
result = error.response

0 commit comments

Comments
 (0)