@@ -3,7 +3,11 @@ mod host;
3
3
use std:: sync:: { Arc , RwLock } ;
4
4
5
5
use indexmap:: IndexMap ;
6
- use opentelemetry:: { global:: ObjectSafeSpan , trace:: TraceContextExt , Context } ;
6
+ use opentelemetry:: {
7
+ global:: { self , BoxedTracer , ObjectSafeSpan } ,
8
+ trace:: TraceContextExt ,
9
+ Context ,
10
+ } ;
7
11
use spin_factors:: { Factor , SelfInstanceBuilder } ;
8
12
use tracing_opentelemetry:: OpenTelemetrySpanExt ;
9
13
@@ -32,14 +36,18 @@ impl Factor for ObserveFactor {
32
36
33
37
fn prepare < T : spin_factors:: RuntimeFactors > (
34
38
& self ,
35
- _ctx : spin_factors:: PrepareContext < Self > ,
39
+ ctx : spin_factors:: PrepareContext < Self > ,
36
40
_builders : & mut spin_factors:: InstanceBuilders < T > ,
37
41
) -> anyhow:: Result < Self :: InstanceBuilder > {
42
+ // TODO(Lann): Is it fine that we're using BoxedTracer and BoxedSpan? Are there perf tradeoffs?
43
+ // TODO(Lann): Would it make sense to put the tracer on the app state and just hold a reference to it in the instance state?
44
+ let tracer = global:: tracer ( ctx. app_component ( ) . app . id ( ) . to_string ( ) ) ;
38
45
Ok ( InstanceState {
39
46
state : Arc :: new ( RwLock :: new ( State {
40
47
guest_spans : table:: Table :: new ( 1024 ) ,
41
48
active_spans : Default :: default ( ) ,
42
49
} ) ) ,
50
+ tracer,
43
51
} )
44
52
}
45
53
}
@@ -52,6 +60,7 @@ impl ObserveFactor {
52
60
53
61
pub struct InstanceState {
54
62
pub ( crate ) state : Arc < RwLock < State > > ,
63
+ pub ( crate ) tracer : BoxedTracer ,
55
64
}
56
65
57
66
impl SelfInstanceBuilder for InstanceState { }
@@ -65,7 +74,10 @@ impl InstanceState {
65
74
}
66
75
}
67
76
68
- /// Internal state of the observe factor.
77
+ /// Internal state of the ObserveFactor instance state.
78
+ ///
79
+ /// This data lives here rather than directly on InstanceState so that we can have multiple things
80
+ /// take Arc references to it.
69
81
pub ( crate ) struct State {
70
82
/// A resource table that holds the guest spans.
71
83
pub guest_spans : table:: Table < GuestSpan > ,
@@ -78,10 +90,10 @@ pub(crate) struct State {
78
90
pub active_spans : IndexMap < String , u32 > ,
79
91
}
80
92
81
- /// The WIT resource Span. Effectively wraps an [opentelemetry_sdk::trace::Span ].
93
+ /// The WIT resource Span. Effectively wraps an [opentelemetry::global::BoxedSpan ].
82
94
pub struct GuestSpan {
83
- /// The [opentelemetry_sdk::trace::Span ] we use to do the actual tracing work.
84
- pub inner : opentelemetry_sdk :: trace :: Span ,
95
+ /// The [opentelemetry::global::BoxedSpan ] we use to do the actual tracing work.
96
+ pub inner : opentelemetry :: global :: BoxedSpan ,
85
97
}
86
98
87
99
/// TODO comment
0 commit comments