1616
1717from lmnr .opentelemetry_lib .tracing .attributes import (
1818ASSOCIATION_PROPERTIES ,
19+ METADATA ,
20+ SESSION_ID ,
1921SPAN_IDS_PATH ,
2022SPAN_INPUT ,
2123SPAN_OUTPUT ,
2224SPAN_PATH ,
25+ TRACE_TYPE ,
26+ USER_ID ,
2327)
2428from lmnr .opentelemetry_lib .tracing .context import (
2529detach_context ,
@@ -79,9 +83,28 @@ def get_laminar_span_context(self) -> LaminarSpanContext:
7983if hasattr (self .span ,"attributes" ):
8084span_path = list (self .span .attributes .get (SPAN_PATH ,tuple ()))
8185span_ids_path = list (self .span .attributes .get (SPAN_IDS_PATH ,tuple ()))
86+ user_id = self .span .attributes .get (
87+ f"{ ASSOCIATION_PROPERTIES } .{ USER_ID } " ,None
88+ )
89+ session_id = self .span .attributes .get (
90+ f"{ ASSOCIATION_PROPERTIES } .{ SESSION_ID } " ,None
91+ )
92+ trace_type = self .span .attributes .get (
93+ f"{ ASSOCIATION_PROPERTIES } .{ TRACE_TYPE } " ,None
94+ )
95+ metadata = {
96+ k .replace (f"{ ASSOCIATION_PROPERTIES } .{ METADATA } ." ,"" ):v
97+ for k ,v in self .span .attributes .items ()
98+ if k .startswith (f"{ ASSOCIATION_PROPERTIES } .{ METADATA } ." )
99+ }
100+ for k ,v in metadata .items ():
101+ try :
102+ metadata [k ]= orjson .loads (v )
103+ except Exception :
104+ metadata [k ]= v
82105else :
83106self .logger .warning (
84- "Attributes object is not available. Most likely the span is not a LaminarSpan " ,
107+ "Attributes object is not available. Most likely the span is not a LaminarSpan "
85108"and not an OpenTelemetry default SDK span. Span path and ids path will be empty." ,
86109 )
87110return LaminarSpanContext (
@@ -90,6 +113,10 @@ def get_laminar_span_context(self) -> LaminarSpanContext:
90113is_remote = self .span .get_span_context ().is_remote ,
91114span_path = span_path ,
92115span_ids_path = span_ids_path ,
116+ user_id = user_id ,
117+ session_id = session_id ,
118+ trace_type = trace_type ,
119+ metadata = metadata ,
93120 )
94121
95122def span_id (self ,format :Literal ["int" ,"uuid" ]= "int" )-> int | uuid .UUID :
@@ -172,7 +199,7 @@ def tags(self) -> list[str]:
172199self .logger .debug (
173200"[LaminarSpan.tags] WARNING. Current span does not have attributes object. "
174201"Perhaps, the span was created with a custom OTel SDK. Returning an empty list."
175- "Help: OpenTelemetry API does not guarantee reading attributes from a span, but OTel SDK " ,
202+ "Help: OpenTelemetry API does not guarantee reading attributes from a span, but OTel SDK "
176203"allows it by default. Laminar SDK allows to read attributes too." ,
177204 )
178205return []