botocore: Fix uninstrument to also unpatch header injection on Endpoint (#664)

This commit is contained in:
Mario Jonke
2021-09-08 18:33:41 +02:00
committed by GitHub
parent 984f5cd2d3
commit fd5fc9a101
3 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.5.0-0.24b0...HEAD)
### Changed
- `opentelemetry-instrumentation-botocore` Unpatch botocore Endpoint.prepare_request on uninstrument
([#664](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/664))
## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26
### Added

View File

@ -51,6 +51,7 @@ import logging
from typing import Collection
from botocore.client import BaseClient
from botocore.endpoint import Endpoint
from botocore.exceptions import ClientError
from wrapt import wrap_function_wrapper
@ -114,6 +115,7 @@ class BotocoreInstrumentor(BaseInstrumentor):
def _uninstrument(self, **kwargs):
unwrap(BaseClient, "_make_api_call")
unwrap(Endpoint, "prepare_request")
@staticmethod
def _is_lambda_invoke(service_name, operation_name, api_params):

View File

@ -61,6 +61,7 @@ def lambda_handler(event, context):
return pfunc
# pylint:disable=too-many-public-methods
class TestBotocoreInstrumentor(TestBase):
"""Botocore integration testsuite"""
@ -322,6 +323,31 @@ class TestBotocoreInstrumentor(TestBase):
spans = self.memory_exporter.get_finished_spans()
assert not spans, spans
@mock_ec2
def test_uninstrument_does_not_inject_headers(self):
headers = {}
previous_propagator = get_global_textmap()
try:
set_global_textmap(MockTextMapPropagator())
def intercept_headers(**kwargs):
headers.update(kwargs["request"].headers)
ec2 = self.session.create_client("ec2", region_name="us-west-2")
BotocoreInstrumentor().uninstrument()
ec2.meta.events.register_first(
"before-send.ec2.DescribeInstances", intercept_headers
)
with self.tracer_provider.get_tracer("test").start_span("parent"):
ec2.describe_instances()
self.assertNotIn(MockTextMapPropagator.TRACE_ID_KEY, headers)
self.assertNotIn(MockTextMapPropagator.SPAN_ID_KEY, headers)
finally:
set_global_textmap(previous_propagator)
@mock_sqs
def test_double_patch(self):
sqs = self.session.create_client("sqs", region_name="us-east-1")