From 093e9962464e1bfe1599a77d3cfca0966a22864a Mon Sep 17 00:00:00 2001 From: Alan Pinkert Date: Wed, 25 May 2022 16:51:18 -0400 Subject: [PATCH 1/3] updated type hints for getters and setters --- .../src/opentelemetry/exporter/datadog/propagator.py | 4 ++-- .../src/opentelemetry/instrumentation/asgi/__init__.py | 4 ++-- .../src/opentelemetry/instrumentation/boto3sqs/__init__.py | 4 ++-- .../src/opentelemetry/instrumentation/kafka/utils.py | 4 ++-- .../src/opentelemetry/instrumentation/pika/utils.py | 2 +- .../src/opentelemetry/instrumentation/wsgi/__init__.py | 2 +- .../src/opentelemetry/propagators/aws/aws_xray_propagator.py | 4 ++-- .../src/opentelemetry/propagators/ot_trace/__init__.py | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py index 7c22827e05..a6b19d15f4 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py @@ -40,7 +40,7 @@ def extract( self, carrier: CarrierT, context: typing.Optional[Context] = None, - getter: Getter = default_getter, + getter: Getter[CarrierT] = default_getter, ) -> Context: if context is None: context = Context() @@ -88,7 +88,7 @@ def inject( self, carrier: CarrierT, context: typing.Optional[Context] = None, - setter: Setter = default_setter, + setter: Setter[CarrierT] = default_setter, ) -> None: span = get_current_span(context) span_context = span.get_span_context() diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 66891744e5..67fda5142f 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -180,7 +180,7 @@ def client_response_hook(span: Span, message: dict): _ClientResponseHookT = typing.Optional[typing.Callable[[Span, dict], None]] -class ASGIGetter(Getter): +class ASGIGetter(Getter[dict]): def get( self, carrier: dict, key: str ) -> typing.Optional[typing.List[str]]: @@ -216,7 +216,7 @@ def keys(self, carrier: dict) -> typing.List[str]: asgi_getter = ASGIGetter() -class ASGISetter(Setter): +class ASGISetter(Setter[dict]): def set( self, carrier: dict, key: str, value: str ) -> None: # pylint: disable=no-self-use diff --git a/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py b/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py index 49909088b2..fa30816350 100644 --- a/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py @@ -59,7 +59,7 @@ _OTEL_IDENTIFIER_LENGTH = len(_OPENTELEMETRY_ATTRIBUTE_IDENTIFIER) -class Boto3SQSGetter(Getter): +class Boto3SQSGetter(Getter[CarrierT]): def get(self, carrier: CarrierT, key: str) -> Optional[List[str]]: value = carrier.get(f"{_OPENTELEMETRY_ATTRIBUTE_IDENTIFIER}{key}", {}) if not value: @@ -75,7 +75,7 @@ def keys(self, carrier: CarrierT) -> List[str]: ] -class Boto3SQSSetter(Setter): +class Boto3SQSSetter(Setter[CarrierT]): def set(self, carrier: CarrierT, key: str, value: str) -> None: # This is a limitation defined by AWS for SQS MessageAttributes size if len(carrier.items()) < 10: diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py index ef55869107..52344ceaff 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py @@ -91,7 +91,7 @@ def extract_send_partition(instance, args, kwargs): ConsumeHookT = Optional[Callable[[Span, ABCRecord, List, Dict], None]] -class KafkaContextGetter(textmap.Getter): +class KafkaContextGetter(textmap.Getter[textmap.CarrierT]): def get(self, carrier: textmap.CarrierT, key: str) -> Optional[List[str]]: if carrier is None: return None @@ -108,7 +108,7 @@ def keys(self, carrier: textmap.CarrierT) -> List[str]: return [key for (key, value) in carrier] -class KafkaContextSetter(textmap.Setter): +class KafkaContextSetter(textmap.Setter[textmap.CarrierT]): def set(self, carrier: textmap.CarrierT, key: str, value: str) -> None: if carrier is None or key is None: return diff --git a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/utils.py b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/utils.py index cc6f689613..e9f819f2d6 100644 --- a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/utils.py +++ b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/utils.py @@ -17,7 +17,7 @@ _LOG = getLogger(__name__) -class _PikaGetter(Getter): # type: ignore +class _PikaGetter(Getter[CarrierT]): # type: ignore def get(self, carrier: CarrierT, key: str) -> Optional[List[str]]: value = carrier.get(key, None) if value is None: diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 64324d874e..cd0f771fc4 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -182,7 +182,7 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he _CARRIER_KEY_PREFIX_LEN = len(_CARRIER_KEY_PREFIX) -class WSGIGetter(Getter): +class WSGIGetter(Getter[dict]): def get( self, carrier: dict, key: str ) -> typing.Optional[typing.List[str]]: diff --git a/propagator/opentelemetry-propagator-aws-xray/src/opentelemetry/propagators/aws/aws_xray_propagator.py b/propagator/opentelemetry-propagator-aws-xray/src/opentelemetry/propagators/aws/aws_xray_propagator.py index bd2ba95c7a..4e4a6872ea 100644 --- a/propagator/opentelemetry-propagator-aws-xray/src/opentelemetry/propagators/aws/aws_xray_propagator.py +++ b/propagator/opentelemetry-propagator-aws-xray/src/opentelemetry/propagators/aws/aws_xray_propagator.py @@ -113,7 +113,7 @@ def extract( self, carrier: CarrierT, context: typing.Optional[Context] = None, - getter: Getter = default_getter, + getter: Getter[CarrierT] = default_getter, ) -> Context: if context is None: context = Context() @@ -275,7 +275,7 @@ def inject( self, carrier: CarrierT, context: typing.Optional[Context] = None, - setter: Setter = default_setter, + setter: Setter[CarrierT] = default_setter, ) -> None: span = trace.get_current_span(context=context) diff --git a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py index ea47ae3f57..44c00e19e4 100644 --- a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py +++ b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py @@ -53,7 +53,7 @@ def extract( self, carrier: CarrierT, context: Optional[Context] = None, - getter: Getter = default_getter, + getter: Getter[CarrierT] = default_getter, ) -> Context: if context is None: context = Context() @@ -112,7 +112,7 @@ def inject( self, carrier: CarrierT, context: Optional[Context] = None, - setter: Setter = default_setter, + setter: Setter[CarrierT] = default_setter, ) -> None: span_context = get_current_span(context).get_span_context() From 4c0114590f38f2e7e7f8b5ae905bd65d95821bbb Mon Sep 17 00:00:00 2001 From: Alan Pinkert Date: Fri, 27 May 2022 16:31:13 -0400 Subject: [PATCH 2/3] added changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e66467742..c4b9d1705e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `opentelemetry-instrumentation-grpc` narrow protobuf dependency to exclude protobuf >= 4 ([1109](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1109)) +- cleanup type hints for textmap `Getter` and `Setter` classes + ([1106](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1106)) ## [1.12.0rc1-0.31b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.12.0rc1-0.31b0) - 2022-05-17 From 2f48eb763e1cabebcd4c87aefa61b1caecb40ea7 Mon Sep 17 00:00:00 2001 From: Alan Pinkert Date: Sat, 28 May 2022 09:41:50 -0400 Subject: [PATCH 3/3] bump core repo sha --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97db8312c6..562b47bc52 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: e4494ea9cdd420390a36f6e6bbd9f15cd29873e9 + CORE_REPO_SHA: cad776a2031c84fb3c3a1af90ee2a939f3394b9a jobs: build: