Repository navigation
OTel logs should go through SdkLogger not direct to log processor #3807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,13 @@ impl Factor for OtelFactor { | |
| ); | ||
| } | ||
|
|
||
| let sdk_logger_provider = self.log_processor.as_ref().map(|lp| { | ||
| let log_processor = DammitOTel(lp.clone()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this just be done inline? If you purposely did this hear according to your stylistic sense that is fine too. |
||
| opentelemetry_sdk::logs::SdkLoggerProvider::builder() | ||
| .with_log_processor(log_processor) | ||
| .build() | ||
| }); | ||
|
|
||
| Ok(InstanceState { | ||
| tracing_state: self.span_processor.as_ref().map(|span_processor| { | ||
| Arc::new(RwLock::new(TracingState { | ||
|
|
@@ -85,11 +92,33 @@ impl Factor for OtelFactor { | |
| })) | ||
| }), | ||
| metric_exporter: self.metric_exporter.clone(), | ||
| log_processor: self.log_processor.clone(), | ||
| sdk_logger_provider, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // OTel is mad about our Arc. Dammit OTel | ||
| #[derive(Debug)] | ||
| struct DammitOTel(Arc<BatchLogProcessor<Tokio>>); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Not quite enough condemnation for my taste |
||
|
|
||
| impl LogProcessor for DammitOTel { | ||
| fn emit( | ||
| &self, | ||
| data: &mut opentelemetry_sdk::logs::SdkLogRecord, | ||
| instrumentation: &opentelemetry::InstrumentationScope, | ||
| ) { | ||
| self.0.emit(data, instrumentation); | ||
| } | ||
|
|
||
| fn force_flush(&self) -> opentelemetry_sdk::error::OTelSdkResult { | ||
| self.0.force_flush() | ||
| } | ||
|
|
||
| fn shutdown(&self) -> opentelemetry_sdk::error::OTelSdkResult { | ||
| self.0.shutdown() | ||
| } | ||
| } | ||
|
|
||
| impl OtelFactor { | ||
| pub fn new(spin_version: &str, enable_interface: bool) -> anyhow::Result<Self> { | ||
| if !enable_interface { | ||
|
|
@@ -179,7 +208,7 @@ impl OtelFactor { | |
| pub struct InstanceState { | ||
| tracing_state: Option<Arc<RwLock<TracingState>>>, | ||
| metric_exporter: Option<Arc<MetricExporter>>, | ||
| log_processor: Option<Arc<BatchLogProcessor<Tokio>>>, | ||
| sdk_logger_provider: Option<opentelemetry_sdk::logs::SdkLoggerProvider>, | ||
| } | ||
|
|
||
| impl SelfInstanceBuilder for InstanceState {} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger is something that feeds into the log processor.