@@ -26,25 +26,26 @@ pub fn handle_app_log(buf: &[u8]) {
26
26
27
27
/// Forward the app log to OTel.
28
28
fn app_log_to_otel ( buf : & [ u8 ] ) {
29
- if !otel_logs_enabled ( ) {
30
- return ;
31
- }
29
+ // TODO(Caleb): Either use logging appender of build our own global logger provider storage
30
+ // if !otel_logs_enabled() {
31
+ // return;
32
+ // }
32
33
33
- let logger = global:: logger_provider ( ) . logger ( "spin" ) ;
34
- if let Ok ( s) = std:: str:: from_utf8 ( buf) {
35
- logger. emit (
36
- opentelemetry:: logs:: LogRecord :: builder ( )
37
- . with_body ( s. to_owned ( ) )
38
- . build ( ) ,
39
- ) ;
40
- } else {
41
- logger. emit (
42
- opentelemetry:: logs:: LogRecord :: builder ( )
43
- . with_body ( escape_non_utf8_buf ( buf) )
44
- . with_attribute ( "app_log_non_utf8" , true )
45
- . build ( ) ,
46
- ) ;
47
- }
34
+ // let logger = global::logger_provider().logger("spin");
35
+ // if let Ok(s) = std::str::from_utf8(buf) {
36
+ // logger.emit(
37
+ // opentelemetry::logs::LogRecord::builder()
38
+ // .with_body(s.to_owned())
39
+ // .build(),
40
+ // );
41
+ // } else {
42
+ // logger.emit(
43
+ // opentelemetry::logs::LogRecord::builder()
44
+ // .with_body(escape_non_utf8_buf(buf))
45
+ // .with_attribute("app_log_non_utf8", true)
46
+ // .build(),
47
+ // );
48
+ // }
48
49
}
49
50
50
51
/// Takes a Spin application log and emits it as a tracing event. This acts as a compatibility layer
@@ -71,42 +72,42 @@ fn escape_non_utf8_buf(buf: &[u8]) -> String {
71
72
72
73
/// Initialize the OTel logging backend.
73
74
pub ( crate ) fn init_otel_logging_backend ( spin_version : String ) -> anyhow:: Result < ( ) > {
74
- let resource = Resource :: from_detectors (
75
- Duration :: from_secs ( 5 ) ,
76
- vec ! [
77
- // Set service.name from env OTEL_SERVICE_NAME > env OTEL_RESOURCE_ATTRIBUTES > spin
78
- // Set service.version from Spin metadata
79
- Box :: new( SpinResourceDetector :: new( spin_version) ) ,
80
- // Sets fields from env OTEL_RESOURCE_ATTRIBUTES
81
- Box :: new( EnvResourceDetector :: new( ) ) ,
82
- // Sets telemetry.sdk{name, language, version}
83
- Box :: new( TelemetryResourceDetector ) ,
84
- ] ,
85
- ) ;
75
+ // let resource = Resource::from_detectors(
76
+ // Duration::from_secs(5),
77
+ // vec![
78
+ // // Set service.name from env OTEL_SERVICE_NAME > env OTEL_RESOURCE_ATTRIBUTES > spin
79
+ // // Set service.version from Spin metadata
80
+ // Box::new(SpinResourceDetector::new(spin_version)),
81
+ // // Sets fields from env OTEL_RESOURCE_ATTRIBUTES
82
+ // Box::new(EnvResourceDetector::new()),
83
+ // // Sets telemetry.sdk{name, language, version}
84
+ // Box::new(TelemetryResourceDetector),
85
+ // ],
86
+ // );
86
87
87
- // This will configure the exporter based on the OTEL_EXPORTER_* environment variables. We
88
- // currently default to using the HTTP exporter but in the future we could select off of the
89
- // combination of OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL to
90
- // determine whether we should use http/protobuf or grpc.
91
- let exporter_builder: LogExporterBuilder = match OtlpProtocol :: logs_protocol_from_env ( ) {
92
- OtlpProtocol :: Grpc => opentelemetry_otlp:: new_exporter ( ) . tonic ( ) . into ( ) ,
93
- OtlpProtocol :: HttpProtobuf => opentelemetry_otlp:: new_exporter ( ) . http ( ) . into ( ) ,
94
- OtlpProtocol :: HttpJson => bail ! ( "http/json OTLP protocol is not supported" ) ,
95
- } ;
88
+ // // This will configure the exporter based on the OTEL_EXPORTER_* environment variables. We
89
+ // // currently default to using the HTTP exporter but in the future we could select off of the
90
+ // // combination of OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL to
91
+ // // determine whether we should use http/protobuf or grpc.
92
+ // let exporter_builder: LogExporterBuilder = match OtlpProtocol::logs_protocol_from_env() {
93
+ // OtlpProtocol::Grpc => opentelemetry_otlp::new_exporter().tonic().into(),
94
+ // OtlpProtocol::HttpProtobuf => opentelemetry_otlp::new_exporter().http().into(),
95
+ // OtlpProtocol::HttpJson => bail!("http/json OTLP protocol is not supported"),
96
+ // };
96
97
97
- let provider = opentelemetry_sdk:: logs:: LoggerProvider :: builder ( )
98
- . with_config ( opentelemetry_sdk:: logs:: config ( ) . with_resource ( resource) )
99
- . with_log_processor (
100
- BatchLogProcessor :: builder (
101
- exporter_builder. build_log_exporter ( ) ?,
102
- opentelemetry_sdk:: runtime:: Tokio ,
103
- )
104
- . with_batch_config ( BatchConfigBuilder :: default ( ) . build ( ) )
105
- . build ( ) ,
106
- )
107
- . build ( ) ;
98
+ // let provider = opentelemetry_sdk::logs::LoggerProvider::builder()
99
+ // .with_config(opentelemetry_sdk::logs::config().with_resource(resource))
100
+ // .with_log_processor(
101
+ // BatchLogProcessor::builder(
102
+ // exporter_builder.build_log_exporter()?,
103
+ // opentelemetry_sdk::runtime::Tokio,
104
+ // )
105
+ // .with_batch_config(BatchConfigBuilder::default().build())
106
+ // .build(),
107
+ // )
108
+ // .build();
108
109
109
- global:: set_logger_provider ( provider) ;
110
+ // global::set_logger_provider(provider);
110
111
111
112
Ok ( ( ) )
112
113
}
0 commit comments