opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

How to modify log data in the log pipeline?

Open trask opened this issue 2 years ago • 8 comments

There's AutoConfigurationCustomizer.addLogExporterCustomizer which gives a nice hook to modify log data, but it occurs after the BatchLogProcessor, and so doesn't have access to the Context.

LogProcessors run before the BatchLogProcessors, but are not able to modify log data (which makes them unlike SpanProcessors, but also makes them much simpler from concurrency/performance perspective).

Short of making LogProcessors similar to SpanProcessors and allowing them to modify the logs, wdyt of adding AutoConfigurationCustomizer.addBatchLogProcessorCustomizer to allow modifying log data before it goes to the BatchLogProcessor which you still have access to the Context?

trask avatar Jun 20 '22 06:06 trask

An additional problem is that log processors only have access to LogData - there are no methods to mutate. This is problematic because it means that if trying to implement a log processor that extracts data from context, even if you provide your own LogData implementation (i.e. a DelegatingLogData), downstream log processors won't see any of the changes. To accomplish this you'd have to have a log processor that delegates to the batch processor.

jack-berg avatar Jun 22 '22 16:06 jack-berg

I made this example to get a better feel for what it would take to do context extraction via an autoconfigure extension point. Yuck.

jack-berg avatar Jun 22 '22 16:06 jack-berg

discussed briefly with @anuraaga on Tue and he was in favor of changing the LogProcessors to mimic SpanProcessors (i.e. introduce ReadWriteLog similar to ReadWriteSpan)

trask avatar Jun 24 '22 00:06 trask

a good example use case for (mutable) LogProcessor is stamping baggage on logs, e.g. https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1391

trask avatar Jun 26 '22 05:06 trask

IMO baggage isn't an ideal example since it's supposed to be handled by OTel itself.

I'm still for having log processor to mimic tracing but if a use case is needed to justify it, it's not baggage ;)

anuraaga avatar Jun 26 '22 08:06 anuraaga

IMO baggage isn't an ideal example since it's supposed to be handled by OTel itself.

Could you expand on this? I think you're saying there should be built in mechanisms to extract baggage onto logs, but I'm not aware of such mechanisms on spans and metrics. Metrics do have experimental support via a baggage attribute processor for views, but it's not part of the spec.

jack-berg avatar Jun 27 '22 15:06 jack-berg

but I'm not aware of such mechanisms

Yeah that's why "supposed to be handled" :P The point is mainly that it would be possible to stamp baggage even without making Log mutable, by the SDK doing it directly before emitting the record.

anuraaga avatar Jun 28 '22 02:06 anuraaga

Opened spec issue #2674 to request allowing this.

jack-berg avatar Jul 06 '22 17:07 jack-berg