-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
852cdc7
commit 16f9341
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
sentry_sdk/integrations/opentelemetry/contextvars_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from opentelemetry.context.context import Context # type: ignore | ||
from opentelemetry.context.contextvars_context import ContextVarsRuntimeContext # type: ignore | ||
|
||
|
||
class SentryContextVarsRuntimeContext(ContextVarsRuntimeContext): # type: ignore | ||
def attach(self, context): | ||
# type: (Context) -> object | ||
# TODO-neel-potel do scope management | ||
return super().attach(context) | ||
|
||
def detach(self, token): | ||
# type: (object) -> None | ||
# TODO-neel-potel not sure if we need anything here, see later | ||
super().detach(token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
sentry_sdk/integrations/opentelemetry/potel_span_processor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from opentelemetry.sdk.trace import SpanProcessor # type: ignore | ||
from opentelemetry.context import Context # type: ignore | ||
from opentelemetry.trace import Span # type: ignore | ||
|
||
from sentry_sdk._types import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Optional | ||
|
||
|
||
class PotelSentrySpanProcessor(SpanProcessor): # type: ignore | ||
""" | ||
Converts OTel spans into Sentry spans so they can be sent to the Sentry backend. | ||
""" | ||
|
||
def __new__(cls): | ||
# type: () -> PotelSentrySpanProcessor | ||
if not hasattr(cls, "instance"): | ||
cls.instance = super().__new__(cls) | ||
|
||
return cls.instance | ||
|
||
def __init__(self): | ||
# type: () -> None | ||
pass | ||
|
||
def on_start(self, span, parent_context=None): | ||
# type: (Span, Optional[Context]) -> None | ||
pass | ||
|
||
def on_end(self, span): | ||
# type: (Span) -> None | ||
pass | ||
|
||
# TODO-neel-potel not sure we need a clear like JS | ||
def shutdown(self): | ||
# type: () -> None | ||
pass | ||
|
||
# TODO-neel-potel change default? this is 30 sec | ||
# TODO-neel-potel call this in client.flush | ||
def force_flush(self, timeout_millis=30000): | ||
# type: (int) -> bool | ||
return True |