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

Add get{Signal}Exporter methods to Simple{Signal}Processor, Batch{Signal}Processor

Open jack-berg opened this issue 1 year ago • 5 comments

Originally discussed in this comment, the idea is to make AutoConfigurationCustomizer#addSpanProcessorCustomizer more useful by allowing you to extract the configured SpanExporter/LogRecordExporter from the processor, and plug it into your own processor.

autoConfiguration.addSpanProcessorCustomizer(
        (spanProcessor, configProperties) -> {
          if (spanProcessor instanceof BatchSpanProcessor) {
            SpanExporter exporter = ((BatchSpanProcessor) spanProcessor).getExporter();
            return new MyCustomProcessor(exporter);
          }
          return spanProcessor;
        });

jack-berg avatar Dec 14 '23 23:12 jack-berg

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ffd53c7) 91.11% compared to head (40fe6bb) 91.09%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6078      +/-   ##
============================================
- Coverage     91.11%   91.09%   -0.03%     
- Complexity     5736     5739       +3     
============================================
  Files           628      628              
  Lines         16810    16814       +4     
  Branches       1662     1662              
============================================
- Hits          15317    15316       -1     
- Misses         1028     1035       +7     
+ Partials        465      463       -2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 14 '23 23:12 codecov[bot]

I'm not necessarily opposed to this approach, but it does feel like a band-aid on something that should be easier to do with auto-configuration.

I don't have a concrete proposal, but what if we had some sort of "autoconfiguration context" that stored all of the currently available auto-configured things, so that any customizer would be able to grab what it needs. It might mean a re-think of the whole auto-configuration codebase/SPIs, though. 🤔

jkwatson avatar Jan 02 '24 16:01 jkwatson

My thought is that this is sort of the like the pattern of adding toBuilder methods. The design question is whether or not we want users to be able to introspect on the configuration of components, or have them be black boxes. Personally, I don't see any advantage to keeping them black boxes. Sure there's more surface area, but its trivial to maintain and hard to imagine abuse.

It might mean a re-think of the whole auto-configuration codebase/SPIs, though.

I think the design of autoconfigure and the SPIs is pretty good, and don't have interest in boiling the ocean to solve this problem. One related option I've thought about is to ensure we have public APIs for all the places where we interpret ConfigProperties and return SDK components. For example, we could add a public static BatchSpanProcessor createProcessor(ConfigProperties, SpanExporter), and public static SpanExporter createSpanExporter(SpanExporter). This would allow users to cherry pick portions of autoconfigure they want to use. We already to this to some extent with ResourceConfiguration#createEnvironmentResource.

But I'm not inclined to do this without more conversation / motivating use cases because it would require adding a bunch of new surface area.

jack-berg avatar Jan 02 '24 17:01 jack-berg

👍🏽 before we merge, are we sure the user from that conversation still needs this?

jkwatson avatar Jan 02 '24 17:01 jkwatson

👍🏽 before we merge, are we sure the user from https://github.com/open-telemetry/opentelemetry-java/pull/5986#discussion_r1412295799 still needs this?

I don't think its strictly necessary since in that case they want to wrap the batch processor instead of replacing it (from what I can gather). But I've personally had use cases where I wanted to replace the batch processor altogether: I wanted to ensure that all spans associated with a particular local root (typically all spans with a particular web request) were guaranteed to be exported in the same batch. This would allow the collector to do a sort of tail based sampling using all spans of request, but which does not require the normal resource intensive / complex routing associated with typical tail sampling where all spans of an entire trace are accumulated before making the decision.

In this case, I am still sending batches of spans to a span exporter, but according to different rules than the batch span processor.

jack-berg avatar Jan 03 '24 21:01 jack-berg

Will merge this if there are no additional comments.

jack-berg avatar Mar 21 '24 19:03 jack-berg