@@ -2,7 +2,6 @@ mod host;
2
2
3
3
use std:: {
4
4
sync:: { Arc , RwLock } ,
5
- time:: Duration ,
6
5
} ;
7
6
8
7
use anyhow:: bail;
@@ -13,28 +12,24 @@ use opentelemetry::{
13
12
} ;
14
13
use opentelemetry_sdk:: {
15
14
resource:: { EnvResourceDetector , TelemetryResourceDetector } ,
16
- runtime:: Tokio ,
17
15
trace:: { BatchSpanProcessor , SpanProcessor } ,
18
16
Resource ,
19
17
} ;
20
- use spin_factors:: { Factor , PrepareContext , RuntimeFactors , SelfInstanceBuilder } ;
18
+ use spin_factors:: { Factor , FactorData , PrepareContext , RuntimeFactors , SelfInstanceBuilder } ;
21
19
use spin_telemetry:: { detector:: SpinResourceDetector , env:: OtlpProtocol } ;
22
20
use tracing_opentelemetry:: OpenTelemetrySpanExt ;
23
21
24
22
pub struct OtelFactor {
25
- processor : Arc < BatchSpanProcessor < Tokio > > ,
23
+ processor : Arc < BatchSpanProcessor > ,
26
24
}
27
25
28
26
impl Factor for OtelFactor {
29
27
type RuntimeConfig = ( ) ;
30
28
type AppState = ( ) ;
31
29
type InstanceBuilder = InstanceState ;
32
30
33
- fn init < T : Send + ' static > (
34
- & mut self ,
35
- mut ctx : spin_factors:: InitContext < T , Self > ,
36
- ) -> anyhow:: Result < ( ) > {
37
- ctx. link_bindings ( spin_world:: wasi:: otel:: tracing:: add_to_linker) ?;
31
+ fn init ( & mut self , ctx : & mut impl spin_factors:: InitContext < Self > ) -> anyhow:: Result < ( ) > {
32
+ ctx. link_bindings ( spin_world:: wasi:: otel:: tracing:: add_to_linker :: < _ , FactorData < Self > > ) ?;
38
33
Ok ( ( ) )
39
34
}
40
35
@@ -71,25 +66,24 @@ impl OtelFactor {
71
66
. build ( ) ?,
72
67
OtlpProtocol :: HttpJson => bail ! ( "http/json OTLP protocol is not supported" ) ,
73
68
} ;
74
- let mut processor = opentelemetry_sdk:: trace:: BatchSpanProcessor :: builder (
75
- exporter,
76
- opentelemetry_sdk:: runtime:: Tokio ,
77
- )
78
- . build ( ) ;
69
+
70
+ let mut processor = opentelemetry_sdk:: trace:: BatchSpanProcessor :: builder ( exporter) . build ( ) ;
71
+
79
72
// This is a hack b/c we know the version of this crate will be the same as the version of Spin
80
73
let spin_version = env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ;
81
- processor. set_resource ( & Resource :: from_detectors (
82
- Duration :: from_secs ( 5 ) ,
83
- vec ! [
74
+
75
+ let detectors: & [ Box < dyn opentelemetry_sdk:: resource:: ResourceDetector > ; 3 ] = & [
84
76
// Set service.name from env OTEL_SERVICE_NAME > env OTEL_RESOURCE_ATTRIBUTES > spin
85
77
// Set service.version from Spin metadata
86
78
Box :: new ( SpinResourceDetector :: new ( spin_version) ) ,
87
79
// Sets fields from env OTEL_RESOURCE_ATTRIBUTES
88
80
Box :: new ( EnvResourceDetector :: new ( ) ) ,
89
81
// Sets telemetry.sdk{name, language, version}
90
82
Box :: new ( TelemetryResourceDetector ) ,
91
- ] ,
92
- ) ) ;
83
+ ] ;
84
+
85
+ processor. set_resource ( & Resource :: builder ( ) . with_detectors ( detectors) . build ( ) ) ;
86
+
93
87
Ok ( Self {
94
88
processor : Arc :: new ( processor) ,
95
89
} )
@@ -98,7 +92,7 @@ impl OtelFactor {
98
92
99
93
pub struct InstanceState {
100
94
pub ( crate ) state : Arc < RwLock < State > > ,
101
- pub ( crate ) processor : Arc < BatchSpanProcessor < Tokio > > ,
95
+ pub ( crate ) processor : Arc < BatchSpanProcessor > ,
102
96
}
103
97
104
98
impl SelfInstanceBuilder for InstanceState { }
0 commit comments