Skip to content

Commit fb3a49c

Browse files
committed
refactor(span): Use of thekind parameter.
To maintain OpenTelemetry API compliance, this commit changes the `InstanaSpan` to use OTel's `SpanKind` as a parameter during the span creation. This commit fixes #813. Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
1 parent 1748ffc commit fb3a49c

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/instana/span/readable_span.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# (c) Copyright IBM Corp. 2024
22

33
from time import time_ns
4-
from typing import Optional, Sequence, List
4+
from typing import List, Optional, Sequence
55

6+
from opentelemetry.trace import SpanKind
67
from opentelemetry.trace.status import Status, StatusCode
78
from opentelemetry.util import types
89

@@ -56,6 +57,7 @@ def __init__(
5657
events: Sequence[Event] = [],
5758
status: Optional[Status] = Status(StatusCode.UNSET),
5859
stack: Optional[List] = None,
60+
kind: SpanKind = SpanKind.INTERNAL,
5961
) -> None:
6062
self._name = name
6163
self._context = context
@@ -74,6 +76,7 @@ def __init__(
7476
self.synthetic = False
7577
if context.synthetic:
7678
self.synthetic = True
79+
self._kind = kind
7780

7881
@property
7982
def name(self) -> str:
@@ -110,3 +113,7 @@ def status(self) -> Status:
110113
@property
111114
def parent_id(self) -> int:
112115
return self._parent_id
116+
117+
@property
118+
def kind(self) -> SpanKind:
119+
return self._kind

src/instana/span/span.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
INVALID_SPAN_ID,
2828
INVALID_TRACE_ID,
2929
Span,
30+
SpanKind,
3031
)
3132
from opentelemetry.trace.span import NonRecordingSpan
3233
from opentelemetry.trace.status import Status, StatusCode
@@ -52,6 +53,7 @@ def __init__(
5253
attributes: types.Attributes = {},
5354
events: Sequence[Event] = [],
5455
status: Optional[Status] = Status(StatusCode.UNSET),
56+
kind: SpanKind = SpanKind.INTERNAL,
5557
) -> None:
5658
super().__init__(
5759
name=name,
@@ -62,7 +64,7 @@ def __init__(
6264
attributes=attributes,
6365
events=events,
6466
status=status,
65-
# kind=kind,
67+
kind=kind,
6668
)
6769
self._span_processor = span_processor
6870
self._lock = Lock()
@@ -190,7 +192,7 @@ def _readable_span(self) -> ReadableSpan:
190192
events=self.events,
191193
status=self.status,
192194
stack=self.stack,
193-
# kind=self.kind,
195+
kind=self.kind,
194196
)
195197

196198
def end(self, end_time: Optional[int] = None) -> None:

src/instana/tracer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def start_span(
131131
parent_id=(None if parent_context is None else parent_context.span_id),
132132
start_time=(time.time_ns() if start_time is None else start_time),
133133
attributes=attributes,
134+
kind=kind,
134135
# events: Sequence[Event] = None,
135136
)
136137

0 commit comments

Comments
 (0)