open-telemetry / open-telemetry/opentelemetry-python
Explore Custom Sampler injection via Entry Points for Manual Instrumentation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 19
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the trace.sampling and _configuration modules, then review PRs #2972 and #3026 alongside issue #3013. Trace how sampler entry points are loaded for auto-instrumentation and how manual instrumentation configures samplers. Done means establishing whether manual injection can be supported without circular dependencies and documenting the required design or constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100