File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# (c) Copyright IBM Corp. 2024
22
33from 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
67from opentelemetry .trace .status import Status , StatusCode
78from 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
Original file line number Diff line number Diff line change @@ -24,18 +24,22 @@ def __init__(
2424 # pylint: disable=invalid-name
2525 super (RegisteredSpan , self ).__init__ (span , source , ** kwargs )
2626 self .n = span .name
27- self .k = SpanKind .SERVER # entry -> Server span represents a synchronous incoming remote call such as an incoming HTTP request
28-
27+ self .k = span .kind
2928 self .data ["service" ] = service_name
29+
3030 if span .name in ENTRY_SPANS :
31- # entry
31+ # Entry spans - Server span represents a synchronous incoming remote call such as an incoming HTTP request.
32+ self .k = SpanKind .SERVER
3233 self ._populate_entry_span_data (span )
3334 self ._populate_extra_span_attributes (span )
3435 elif span .name in EXIT_SPANS :
35- self .k = SpanKind .CLIENT # exit -> Client span represents a synchronous outgoing remote call such as an outgoing HTTP request or database call
36+ # Exit spans - Client span represents a synchronous outgoing remote call such as an outgoing HTTP request
37+ # or a database call.
38+ self .k = SpanKind .CLIENT
3639 self ._populate_exit_span_data (span )
3740 elif span .name in LOCAL_SPANS :
38- self .k = SpanKind .INTERNAL # intermediate -> Internal span represents an internal operation within an application
41+ # Intermediate or SDK spans - Internal span represents an internal operation within an application.
42+ self .k = SpanKind .INTERNAL
3943 self ._populate_local_span_data (span )
4044
4145 if "rabbitmq" in self .data and self .data ["rabbitmq" ]["sort" ] == "publish" :
Original file line number Diff line number Diff line change 2727 INVALID_SPAN_ID ,
2828 INVALID_TRACE_ID ,
2929 Span ,
30+ SpanKind ,
3031)
3132from opentelemetry .trace .span import NonRecordingSpan
3233from 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 :
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments