@@ -33,6 +33,7 @@ use fastrace::prelude::*;
3333use opentelemetry:: InstrumentationScope ;
3434use opentelemetry:: KeyValue ;
3535use opentelemetry:: trace:: Event ;
36+ use opentelemetry:: trace:: Link ;
3637use opentelemetry:: trace:: SpanContext as OtelSpanContext ;
3738use opentelemetry:: trace:: SpanKind ;
3839use opentelemetry:: trace:: Status ;
@@ -139,7 +140,6 @@ static OTEL_PROPERTIES: LazyLock<HashSet<&str>> = LazyLock::new(|| {
139140 ] )
140141} ) ;
141142
142- /// Convert a list of properties to a list of key-value pairs.
143143fn map_props_to_kvs ( props : Vec < ( Cow < ' static , str > , Cow < ' static , str > ) > ) -> Vec < KeyValue > {
144144 props
145145 . into_iter ( )
@@ -148,7 +148,6 @@ fn map_props_to_kvs(props: Vec<(Cow<'static, str>, Cow<'static, str>)>) -> Vec<K
148148 . collect ( )
149149}
150150
151- /// Convert a list of [`EventRecord`] to OpenTelemetry [`SpanEvents`].
152151fn map_events ( events : Vec < EventRecord > ) -> SpanEvents {
153152 let mut queue = SpanEvents :: default ( ) ;
154153 queue. events . reserve ( events. len ( ) ) ;
@@ -167,6 +166,31 @@ fn map_events(events: Vec<EventRecord>) -> SpanEvents {
167166 queue
168167}
169168
169+ fn map_links ( links : Vec < SpanContext > ) -> SpanLinks {
170+ let links = links
171+ . into_iter ( )
172+ . map ( |link| {
173+ let trace_flags = if link. sampled {
174+ TraceFlags :: SAMPLED
175+ } else {
176+ TraceFlags :: default ( )
177+ } ;
178+ let span_context = OtelSpanContext :: new (
179+ link. trace_id . 0 . into ( ) ,
180+ link. span_id . 0 . into ( ) ,
181+ trace_flags,
182+ false ,
183+ TraceState :: default ( ) ,
184+ ) ;
185+ Link :: with_context ( span_context)
186+ } )
187+ . collect ( ) ;
188+
189+ let mut span_links = SpanLinks :: default ( ) ;
190+ span_links. links = links;
191+ span_links
192+ }
193+
170194trait DynSpanExporter : Send + Sync + Debug {
171195 fn export (
172196 & self ,
@@ -209,6 +233,7 @@ impl OpenTelemetryReporter {
209233 name,
210234 properties,
211235 events,
236+ links,
212237 } | {
213238 let parent_span_id = parent_id. 0 . into ( ) ;
214239 let span_kind = span_kind ( & properties) ;
@@ -221,6 +246,7 @@ impl OpenTelemetryReporter {
221246 + Duration :: from_nanos ( begin_time_unix_ns + duration_ns) ;
222247 let attributes = map_props_to_kvs ( properties) ;
223248 let events = map_events ( events) ;
249+ let links = map_links ( links) ;
224250
225251 SpanData {
226252 span_context : OtelSpanContext :: new (
@@ -239,7 +265,7 @@ impl OpenTelemetryReporter {
239265 attributes,
240266 dropped_attributes_count : 0 ,
241267 events,
242- links : SpanLinks :: default ( ) ,
268+ links,
243269 status,
244270 instrumentation_scope,
245271 }
0 commit comments