Skip to content

Commit 82c8b6e

Browse files
committed
.
1 parent c2d0d56 commit 82c8b6e

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from opentelemetry.trace.span import TraceState
77

88
import sentry_sdk
9-
from sentry_sdk.tracing_utils import create_sampling_context, has_tracing_enabled
9+
from sentry_sdk.tracing_utils import has_tracing_enabled
1010
from sentry_sdk.utils import is_valid_sample_rate, logger
1111
from sentry_sdk.integrations.opentelemetry.consts import (
1212
TRACESTATE_SAMPLED_KEY,
@@ -17,7 +17,7 @@
1717
from typing import TYPE_CHECKING
1818

1919
if TYPE_CHECKING:
20-
from typing import Optional, Sequence, Union
20+
from typing import Any, Optional, Sequence, Union
2121
from opentelemetry.context import Context
2222
from opentelemetry.trace import Link, SpanKind
2323
from opentelemetry.trace.span import SpanContext
@@ -187,3 +187,19 @@ def should_sample(
187187

188188
def get_description(self) -> str:
189189
return self.__class__.__name__
190+
191+
192+
def create_sampling_context(name, attributes, parent_context, trace_id):
193+
# type: (str, Attributes, Context, str) -> dict[str, Any]
194+
sampling_context = {
195+
"transaction_context": {
196+
"name": name,
197+
"op": attributes.get(SentrySpanAttribute.OP),
198+
"source": attributes.get(SentrySpanAttribute.SOURCE),
199+
},
200+
"parent_sampled": get_parent_sampled(parent_context, trace_id),
201+
}
202+
203+
sampling_context.update(attributes)
204+
205+
return sampling_context

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import sentry_sdk
1515
from sentry_sdk.consts import SPANDATA
1616
from sentry_sdk.tracing import DEFAULT_SPAN_ORIGIN
17-
from sentry_sdk.tracing_utils import create_sampling_context
1817
from sentry_sdk.utils import get_current_thread_meta
1918
from sentry_sdk.profiler.continuous_profiler import (
2019
try_autostart_continuous_profiler,
2120
get_profiler_id,
2221
)
2322
from sentry_sdk.profiler.transaction_profiler import Profile
23+
from sentry_sdk.integrations.opentelemetry.sampler import create_sampling_context
2424
from sentry_sdk.integrations.opentelemetry.utils import (
2525
is_sentry_span,
2626
convert_from_otel_timestamp,

sentry_sdk/tracing_utils.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
import sentry_sdk
1313
from sentry_sdk.consts import OP, SPANDATA
14-
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
15-
from sentry_sdk.integrations.opentelemetry.sampler import get_parent_sampled
1614
from sentry_sdk.utils import (
1715
capture_internal_exceptions,
1816
filename_for_module,
@@ -36,8 +34,6 @@
3634
from typing import Optional
3735
from typing import Union
3836
from types import FrameType
39-
from opentelemetry.context import Context
40-
from opentelemetry.util.types import Attributes
4137

4238

4339
SENTRY_TRACE_REGEX = re.compile(
@@ -728,22 +724,6 @@ def get_current_span(scope=None):
728724
return current_span
729725

730726

731-
def create_sampling_context(name, attributes, parent_context, trace_id):
732-
# type: (str, Attributes, Context, str) -> dict[str, Any]
733-
sampling_context = {
734-
"transaction_context": {
735-
"name": name,
736-
"op": attributes.get(SentrySpanAttribute.OP),
737-
"source": attributes.get(SentrySpanAttribute.SOURCE),
738-
},
739-
"parent_sampled": get_parent_sampled(parent_context, trace_id),
740-
}
741-
742-
sampling_context.update(attributes)
743-
744-
return sampling_context
745-
746-
747727
# Circular imports
748728
from sentry_sdk.tracing import (
749729
BAGGAGE_HEADER_NAME,

0 commit comments

Comments
 (0)