Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Dec 3, 2024
1 parent c2d0d56 commit 82c8b6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
20 changes: 18 additions & 2 deletions sentry_sdk/integrations/opentelemetry/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from opentelemetry.trace.span import TraceState

import sentry_sdk
from sentry_sdk.tracing_utils import create_sampling_context, has_tracing_enabled
from sentry_sdk.tracing_utils import has_tracing_enabled
from sentry_sdk.utils import is_valid_sample_rate, logger
from sentry_sdk.integrations.opentelemetry.consts import (
TRACESTATE_SAMPLED_KEY,
Expand All @@ -17,7 +17,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional, Sequence, Union
from typing import Any, Optional, Sequence, Union
from opentelemetry.context import Context
from opentelemetry.trace import Link, SpanKind
from opentelemetry.trace.span import SpanContext
Expand Down Expand Up @@ -187,3 +187,19 @@ def should_sample(

def get_description(self) -> str:
return self.__class__.__name__


def create_sampling_context(name, attributes, parent_context, trace_id):
# type: (str, Attributes, Context, str) -> dict[str, Any]
sampling_context = {
"transaction_context": {
"name": name,
"op": attributes.get(SentrySpanAttribute.OP),
"source": attributes.get(SentrySpanAttribute.SOURCE),
},
"parent_sampled": get_parent_sampled(parent_context, trace_id),
}

sampling_context.update(attributes)

return sampling_context
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import sentry_sdk
from sentry_sdk.consts import SPANDATA
from sentry_sdk.tracing import DEFAULT_SPAN_ORIGIN
from sentry_sdk.tracing_utils import create_sampling_context
from sentry_sdk.utils import get_current_thread_meta
from sentry_sdk.profiler.continuous_profiler import (
try_autostart_continuous_profiler,
get_profiler_id,
)
from sentry_sdk.profiler.transaction_profiler import Profile
from sentry_sdk.integrations.opentelemetry.sampler import create_sampling_context
from sentry_sdk.integrations.opentelemetry.utils import (
is_sentry_span,
convert_from_otel_timestamp,
Expand Down
20 changes: 0 additions & 20 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
from sentry_sdk.integrations.opentelemetry.sampler import get_parent_sampled
from sentry_sdk.utils import (
capture_internal_exceptions,
filename_for_module,
Expand All @@ -36,8 +34,6 @@
from typing import Optional
from typing import Union
from types import FrameType
from opentelemetry.context import Context
from opentelemetry.util.types import Attributes


SENTRY_TRACE_REGEX = re.compile(
Expand Down Expand Up @@ -728,22 +724,6 @@ def get_current_span(scope=None):
return current_span


def create_sampling_context(name, attributes, parent_context, trace_id):
# type: (str, Attributes, Context, str) -> dict[str, Any]
sampling_context = {
"transaction_context": {
"name": name,
"op": attributes.get(SentrySpanAttribute.OP),
"source": attributes.get(SentrySpanAttribute.SOURCE),
},
"parent_sampled": get_parent_sampled(parent_context, trace_id),
}

sampling_context.update(attributes)

return sampling_context


# Circular imports
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
Expand Down

0 comments on commit 82c8b6e

Please sign in to comment.