-
Notifications
You must be signed in to change notification settings - Fork 514
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
c62d515
commit 0afad75
Showing
4 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
from opentelemetry.context.contextvars_context import ContextVarsRuntimeContext | ||
|
||
|
||
class SentryContextVarsRuntimeContext(ContextVarsRuntimeContext): | ||
def attach(self, context): | ||
# TODO-neel-potel do scope management | ||
super().attach(context) | ||
|
||
def detach(self, token): | ||
# 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
19 changes: 19 additions & 0 deletions
19
sentry_sdk/integrations/opentelemetry/potel_span_exporter.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,19 @@ | ||
from opentelemetry.trace import Span | ||
|
||
|
||
class PotelSentrySpanExporter: | ||
""" | ||
A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions. | ||
""" | ||
|
||
def __init__(self): | ||
# type: () -> None | ||
pass | ||
|
||
def export(self, span): | ||
# type: (Span) -> None | ||
pass | ||
|
||
def flush(self, timeout_millis): | ||
# type: (int) -> bool | ||
return True |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
from opentelemetry.sdk.trace import SpanProcessor # type: ignore | ||
from opentelemetry.context import Context # type: ignore | ||
from opentelemetry.trace import Span | ||
|
||
from sentry_sdk.integrations.opentelemetry.potel_span_exporter import ( | ||
PotelSentrySpanExporter, | ||
) | ||
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 | ||
self._exporter = PotelSentrySpanExporter() | ||
|
||
def on_start(self, span, parent_context=None): | ||
# type: (Span, Optional[Context]) -> None | ||
pass | ||
|
||
def on_end(self, span): | ||
# type: (Span) -> None | ||
self._exporter.export(span) | ||
|
||
# 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 | ||
self._exporter.flush(timeout_millis) |