Skip to content

Commit

Permalink
Set up typing for OTel (#3168)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana authored Jun 26, 2024
1 parent 4a9556b commit 7c1685e
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 107 deletions.
1 change: 1 addition & 0 deletions requirements-linting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ types-greenlet
types-redis
types-setuptools
types-webob
opentelemetry-distro
pymongo # There is no separate types module.
loguru # There is no separate types module.
flake8-bugbear
Expand Down
5 changes: 2 additions & 3 deletions sentry_sdk/integrations/opentelemetry/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from opentelemetry.context import ( # type: ignore
create_key,
)
from opentelemetry.context import create_key


SENTRY_TRACE_KEY = create_key("sentry-trace")
SENTRY_BAGGAGE_KEY = create_key("sentry-baggage")
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/opentelemetry/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from sentry_sdk._types import TYPE_CHECKING

try:
from opentelemetry import trace # type: ignore
from opentelemetry.instrumentation.distro import BaseDistro # type: ignore
from opentelemetry.propagate import set_global_textmap # type: ignore
from opentelemetry.sdk.trace import TracerProvider # type: ignore
from opentelemetry import trace
from opentelemetry.instrumentation.distro import BaseDistro # type: ignore[attr-defined]
from opentelemetry.propagate import set_global_textmap
from opentelemetry.sdk.trace import TracerProvider
except ImportError:
raise DidNotEnable("opentelemetry not installed")

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/opentelemetry/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sentry_sdk._types import TYPE_CHECKING

try:
from opentelemetry.instrumentation.auto_instrumentation._load import ( # type: ignore
from opentelemetry.instrumentation.auto_instrumentation._load import (
_load_instrumentors,
)
except ImportError:
Expand Down
14 changes: 7 additions & 7 deletions sentry_sdk/integrations/opentelemetry/propagator.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from opentelemetry import trace # type: ignore
from opentelemetry.context import ( # type: ignore
from opentelemetry import trace
from opentelemetry.context import (
Context,
get_current,
set_value,
)
from opentelemetry.propagators.textmap import ( # type: ignore
from opentelemetry.propagators.textmap import (
CarrierT,
Getter,
Setter,
TextMapPropagator,
default_getter,
default_setter,
)
from opentelemetry.trace import ( # type: ignore
from opentelemetry.trace import (
NonRecordingSpan,
SpanContext,
TraceFlags,
Expand All @@ -37,13 +37,13 @@
from typing import Set


class SentryPropagator(TextMapPropagator): # type: ignore
class SentryPropagator(TextMapPropagator):
"""
Propagates tracing headers for Sentry's tracing system in a way OTel understands.
"""

def extract(self, carrier, context=None, getter=default_getter):
# type: (CarrierT, Optional[Context], Getter) -> Context
# type: (CarrierT, Optional[Context], Getter[CarrierT]) -> Context
if context is None:
context = get_current()

Expand Down Expand Up @@ -85,7 +85,7 @@ def extract(self, carrier, context=None, getter=default_getter):
return modified_context

def inject(self, carrier, context=None, setter=default_setter):
# type: (CarrierT, Optional[Context], Setter) -> None
# type: (CarrierT, Optional[Context], Setter[CarrierT]) -> None
if context is None:
context = get_current()

Expand Down
Loading

0 comments on commit 7c1685e

Please sign in to comment.