@@ -2,7 +2,6 @@ mod host;
22
33use std:: {
44 sync:: { Arc , RwLock } ,
5- time:: Duration ,
65} ;
76
87use anyhow:: bail;
@@ -13,28 +12,24 @@ use opentelemetry::{
1312} ;
1413use opentelemetry_sdk:: {
1514 resource:: { EnvResourceDetector , TelemetryResourceDetector } ,
16- runtime:: Tokio ,
1715 trace:: { BatchSpanProcessor , SpanProcessor } ,
1816 Resource ,
1917} ;
20- use spin_factors:: { Factor , PrepareContext , RuntimeFactors , SelfInstanceBuilder } ;
18+ use spin_factors:: { Factor , FactorData , PrepareContext , RuntimeFactors , SelfInstanceBuilder } ;
2119use spin_telemetry:: { detector:: SpinResourceDetector , env:: OtlpProtocol } ;
2220use tracing_opentelemetry:: OpenTelemetrySpanExt ;
2321
2422pub struct OtelFactor {
25- processor : Arc < BatchSpanProcessor < Tokio > > ,
23+ processor : Arc < BatchSpanProcessor > ,
2624}
2725
2826impl Factor for OtelFactor {
2927 type RuntimeConfig = ( ) ;
3028 type AppState = ( ) ;
3129 type InstanceBuilder = InstanceState ;
3230
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 > > ) ?;
3833 Ok ( ( ) )
3934 }
4035
@@ -71,25 +66,24 @@ impl OtelFactor {
7166 . build ( ) ?,
7267 OtlpProtocol :: HttpJson => bail ! ( "http/json OTLP protocol is not supported" ) ,
7368 } ;
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+
7972 // This is a hack b/c we know the version of this crate will be the same as the version of Spin
8073 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 ] = & [
8476 // Set service.name from env OTEL_SERVICE_NAME > env OTEL_RESOURCE_ATTRIBUTES > spin
8577 // Set service.version from Spin metadata
8678 Box :: new ( SpinResourceDetector :: new ( spin_version) ) ,
8779 // Sets fields from env OTEL_RESOURCE_ATTRIBUTES
8880 Box :: new ( EnvResourceDetector :: new ( ) ) ,
8981 // Sets telemetry.sdk{name, language, version}
9082 Box :: new ( TelemetryResourceDetector ) ,
91- ] ,
92- ) ) ;
83+ ] ;
84+
85+ processor. set_resource ( & Resource :: builder ( ) . with_detectors ( detectors) . build ( ) ) ;
86+
9387 Ok ( Self {
9488 processor : Arc :: new ( processor) ,
9589 } )
@@ -98,7 +92,7 @@ impl OtelFactor {
9892
9993pub struct InstanceState {
10094 pub ( crate ) state : Arc < RwLock < State > > ,
101- pub ( crate ) processor : Arc < BatchSpanProcessor < Tokio > > ,
95+ pub ( crate ) processor : Arc < BatchSpanProcessor > ,
10296}
10397
10498impl SelfInstanceBuilder for InstanceState { }
0 commit comments