Suppress botocore downstream instrumentation like urllib3 (#563)
This commit is contained in:
parent
3a1746a3bf
commit
7e8b5bb178
|
|
@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
([#562](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/562))
|
([#562](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/562))
|
||||||
- `opentelemetry-instrumentation-django` Fix AttributeError: ResolverMatch object has no attribute route
|
- `opentelemetry-instrumentation-django` Fix AttributeError: ResolverMatch object has no attribute route
|
||||||
([#581](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581))
|
([#581](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581))
|
||||||
|
- `opentelemetry-instrumentation-botocore` Suppress botocore downstream instrumentation like urllib3
|
||||||
|
([#563](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/563))
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- `opentelemetry-instrumentation-httpx` Add `httpx` instrumentation
|
- `opentelemetry-instrumentation-httpx` Add `httpx` instrumentation
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,13 @@ from opentelemetry.trace import SpanKind, get_tracer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# A key to a context variable to avoid creating duplicate spans when instrumenting
|
||||||
|
# both botocore.client and urllib3.connectionpool.HTTPConnectionPool.urlopen since
|
||||||
|
# botocore calls urlopen
|
||||||
|
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context_api.create_key(
|
||||||
|
"suppress_http_instrumentation"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def _patched_endpoint_prepare_request(wrapped, instance, args, kwargs):
|
def _patched_endpoint_prepare_request(wrapped, instance, args, kwargs):
|
||||||
|
|
@ -161,10 +168,16 @@ class BotocoreInstrumentor(BaseInstrumentor):
|
||||||
"aws.table_name", api_params["TableName"]
|
"aws.table_name", api_params["TableName"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
token = context_api.attach(
|
||||||
|
context_api.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = original_func(*args, **kwargs)
|
result = original_func(*args, **kwargs)
|
||||||
except ClientError as ex:
|
except ClientError as ex:
|
||||||
error = ex
|
error = ex
|
||||||
|
finally:
|
||||||
|
context_api.detach(token)
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
result = error.response
|
result = error.response
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue