Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [SVLS-5262] move private Span Pointers to a new file #10684

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions ddtrace/_trace/_span_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@

import dataclasses
from enum import Enum
from typing import Any
from typing import Dict
from typing import Optional

from ddtrace.internal.logger import get_logger
from ddtrace.internal.utils.formats import flatten_key_value


log = get_logger(__name__)


class SpanLinkKind(Enum):
"""
A collection of standard SpanLink kinds. It's possible to use others, but these should be used when possible.
Expand Down Expand Up @@ -132,41 +126,3 @@ def __str__(self) -> str:
f"trace_id={self.trace_id} span_id={self.span_id} attributes={attrs_str} "
f"tracestate={self.tracestate} flags={self.flags} dropped_attributes={self._dropped_attributes}"
)


# Span Pointers are currently private, so let's put them here for now


_SPAN_POINTER_SPAN_LINK_TRACE_ID = 0
_SPAN_POINTER_SPAN_LINK_SPAN_ID = 0


class _SpanPointerDirection(Enum):
UPSTREAM = "u"
DOWNSTREAM = "d"


class _SpanPointer(SpanLink):
def __init__(
self,
pointer_kind: str,
pointer_direction: _SpanPointerDirection,
pointer_hash: str,
extra_attributes: Optional[Dict[str, Any]] = None,
):
super().__init__(
trace_id=_SPAN_POINTER_SPAN_LINK_TRACE_ID,
span_id=_SPAN_POINTER_SPAN_LINK_SPAN_ID,
attributes={
"ptr.kind": pointer_kind,
"ptr.dir": pointer_direction.value,
"ptr.hash": pointer_hash,
**(extra_attributes or {}),
},
)

self.kind = SpanLinkKind.SPAN_POINTER.value

def __post_init__(self):
# Do not want to do the trace_id and span_id checks that SpanLink does.
pass
43 changes: 43 additions & 0 deletions ddtrace/_trace/_span_pointer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# A Private API for now.
apiarian-datadog marked this conversation as resolved.
Show resolved Hide resolved
from enum import Enum
from typing import Any
from typing import Dict
from typing import Optional

from ddtrace._trace._span_link import SpanLink
from ddtrace._trace._span_link import SpanLinkKind


_SPAN_POINTER_SPAN_LINK_TRACE_ID = 0
_SPAN_POINTER_SPAN_LINK_SPAN_ID = 0


class _SpanPointerDirection(Enum):
UPSTREAM = "u"
DOWNSTREAM = "d"


class _SpanPointer(SpanLink):
def __init__(
self,
pointer_kind: str,
pointer_direction: _SpanPointerDirection,
pointer_hash: str,
extra_attributes: Optional[Dict[str, Any]] = None,
):
super().__init__(
trace_id=_SPAN_POINTER_SPAN_LINK_TRACE_ID,
span_id=_SPAN_POINTER_SPAN_LINK_SPAN_ID,
attributes={
"ptr.kind": pointer_kind,
"ptr.dir": pointer_direction.value,
"ptr.hash": pointer_hash,
**(extra_attributes or {}),
},
)

self.kind = SpanLinkKind.SPAN_POINTER.value

def __post_init__(self):
# Do not want to do the trace_id and span_id checks that SpanLink does.
pass
4 changes: 2 additions & 2 deletions ddtrace/_trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from ddtrace import config
from ddtrace._trace._span_link import SpanLink
from ddtrace._trace._span_link import SpanLinkKind
from ddtrace._trace._span_link import _SpanPointer
from ddtrace._trace._span_link import _SpanPointerDirection
from ddtrace._trace._span_pointer import _SpanPointer
from ddtrace._trace._span_pointer import _SpanPointerDirection
from ddtrace._trace.context import Context
from ddtrace._trace.types import _MetaDictType
from ddtrace._trace.types import _MetricDictType
Expand Down
2 changes: 1 addition & 1 deletion tests/tracer/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest

from ddtrace._trace._span_link import SpanLink
from ddtrace._trace._span_link import _SpanPointerDirection
from ddtrace._trace._span_pointer import _SpanPointerDirection
from ddtrace._trace.context import Context
from ddtrace._trace.span import Span
from ddtrace.constants import ORIGIN_KEY
Expand Down
2 changes: 1 addition & 1 deletion tests/tracer/test_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

from ddtrace._trace._span_link import SpanLink
from ddtrace._trace._span_link import _SpanPointerDirection
from ddtrace._trace._span_pointer import _SpanPointerDirection
from ddtrace._trace.span import Span
from ddtrace.constants import ENV_KEY
from ddtrace.constants import ERROR_MSG
Expand Down
Loading