In order to enable custom samplers for auto-instrumentation, I needed to use entry points in conjunction with environment variables -- same as exporters, distros, configurators, and other components. Since OT Sampling already uses environment variables (but not entry points) to enable users to specify a built-in sampler, even via manual instrumentation, I initially chose to expand that logic in the trace.sampling module to include custom samplers from entry points. This was unlike existing entry point usage that happens at the higher_configuration level. This enabled custom samplers for auto- and manual instrumentation:
Initial feature PR: https://github.com/open-telemetry/opentelemetry-python/pull/2972
However, because imported custom samplers may come from modules that depend on trace or trace.sampling, this can easily create a circular dependency upon loading the entry point. Note that the circular dependency did not exist within any package, but rather between them:
Bug: https://github.com/open-telemetry/opentelemetry-python/issues/3013
Seeing that the source of this issue was the fact that the entry point needed to be loaded in trace.sampling instead of in _configuration like all others, I fixed the circular dependency issue, but only by once again disabling entry point injection of custom samplers for manual instrumentation:
Fix PR: https://github.com/open-telemetry/opentelemetry-python/pull/3026
With this PR (still open on this issue's creation), manual instrumentation will be as it initially was. Users can specify built in samplers via environment variables or use custom samplings by passing them in as an argument of the TracerProvider. However, auto-instrumentation users will also be able to specify Custom Samplers via entry point injection.
This ticket is to explore if it is possible to enable entry point injection of custom samplers (and other components) for manual instrumentation as well.
In order to enable custom samplers for auto-instrumentation, I needed to use entry points in conjunction with environment variables -- same as exporters, distros, configurators, and other components. Since OT Sampling already uses environment variables (but not entry points) to enable users to specify a built-in sampler, even via manual instrumentation, I initially chose to expand that logic in the trace.sampling module to include custom samplers from entry points. This was unlike existing entry point usage that happens at the higher_configuration level. This enabled custom samplers for auto- and manual instrumentation: Initial feature PR: https://github.com/open-telemetry/opentelemetry-python/pull/2972
However, because imported custom samplers may come from modules that depend on trace or trace.sampling, this can easily create a circular dependency upon loading the entry point. Note that the circular dependency did not exist within any package, but rather between them: Bug: https://github.com/open-telemetry/opentelemetry-python/issues/3013
Seeing that the source of this issue was the fact that the entry point needed to be loaded in trace.sampling instead of in _configuration like all others, I fixed the circular dependency issue, but only by once again disabling entry point injection of custom samplers for manual instrumentation: Fix PR: https://github.com/open-telemetry/opentelemetry-python/pull/3026
With this PR (still open on this issue's creation), manual instrumentation will be as it initially was. Users can specify built in samplers via environment variables or use custom samplings by passing them in as an argument of the TracerProvider. However, auto-instrumentation users will also be able to specify Custom Samplers via entry point injection.
This ticket is to explore if it is possible to enable entry point injection of custom samplers (and other components) for manual instrumentation as well.