Skip to content

Commit

Permalink
updated type hints for getters and setters (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanisaac authored May 29, 2022
1 parent f7409b8 commit 100ecfe
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: e4494ea9cdd420390a36f6e6bbd9f15cd29873e9
CORE_REPO_SHA: cad776a2031c84fb3c3a1af90ee2a939f3394b9a

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 100ecfe

Please sign in to comment.