feat: make OpenTelemetry an optional dependency#320
feat: make OpenTelemetry an optional dependency#320r0x0d wants to merge 3 commits intochrisguidry:mainfrom
Conversation
Move opentelemetry-api from required dependencies to optional extras,
allowing docket to be used without OpenTelemetry installed. When OTel
is not available, the library silently uses noop stub implementations
that maintain the same interface but perform no operations.
This change is particularly helpful for Linux distribution packagers,
especially in Fedora, where the OpenTelemetry Python packages have
faced significant packaging challenges. As discussed in the Fedora
devel mailing list thread [1], the opentelemetry-* packages have been
difficult to maintain and may be orphaned or retired, making it
problematic for packages that hard-depend on them.
By making OpenTelemetry optional, docket can be packaged and used in
distributions without requiring the full OpenTelemetry stack, while
users who want observability features can still install them via:
pip install pydocket[telemetry] # for tracing only
pip install pydocket[metrics] # for metrics + tracing
Implementation details:
- Add _otel_stubs.py with noop implementations of OTel interfaces
- Add _otel.py as unified import point with automatic fallback
- Update all source files to import from _otel module
- Move opentelemetry-api to new 'telemetry' optional extra
- Update 'metrics' extra to depend on 'telemetry'
- Add conftest.py to skip instrumentation tests when OTel unavailable
- All 601 tests pass, 90% coverage maintained
[1] https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/3LHITWOBP76JNSQICDDX5BHFVFCFS4NA/
|
Hi, @chrisguidry! Not sure if this is something that you will find useful or valuable, but this patch would help a lot of packaging docket in downstream distributions. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25f376be0f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The skip condition previously only checked OTEL_AVAILABLE (opentelemetry-api), but tests in this directory use metrics_server and TracerProvider which require opentelemetry-sdk to be installed. If someone installs only pydocket[telemetry] (API without SDK) and runs tests, these tests would execute and fail instead of being skipped. This fix adds a separate SDK availability check using importlib.import_module() to detect opentelemetry.sdk.metrics and opentelemetry.sdk.trace. Tests are now skipped unless both API and SDK are available. Installation scenarios: - pydocket (base): tests skipped - pydocket[telemetry] (API only): tests skipped - pydocket[metrics] (API + SDK): tests run
|
Hi @r0x0d, thank you so much for the PR! I'm trying to decide how I feel about this. It was definitely problematic when Docket had a dependency on the Could you help me understand more about the Fedora packaging issue? Would relaxing the version constraint help? I'm not opposed to vendoring some OTEL stubs, but it feels like a pretty disappointing step to take. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #320 +/- ##
==========================================
- Coverage 98.65% 96.88% -1.77%
==========================================
Files 102 104 +2
Lines 10161 10311 +150
Branches 491 491
==========================================
- Hits 10024 9990 -34
- Misses 121 303 +182
- Partials 16 18 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Hi, @chrisguidry! Thanks for being open on the idea. So, the difficulties we have with OTEL right now is managing the updates from version to version, especially the protobuf ones that are super outdated, and it seems that folks have a hard time trying to update it to newer versions 1. My goal here (and maybe my PR is not reflecting it directly), is to have an option to disable OTEL entirely when building in Fedora until things normalize, and we can unretire the OTEL packages again. Making it optional, for us, would decrease the complexity of packaging. The upstream docket could (and should) still make OTEL default and that how it should be, but for downstream, a way to toggle it off would be much appreciated. Giving a bit of context here; I'm trying to get https://github.com/rhel-lightspeed/linux-mcp-server/ to Fedora repositories, in which, it depends on fastmcp==2.14.x, that depends on docket. Maybe there's an easier way to handle this, and if so, please let me know and I would love to work on it. Thanks for your attention! |
|
Ahh okay, I think you may be seeing the dependencies from before I introduced the This doesn't bring in the heavier-weight Are you testing with the current version of Docket (0.17.5)? I wonder if the problem is that we still have a <0.17 pin in |
Yeah, Fedora requires that we always ship the latest version of a library/software.
Seems like it. https://github.com/jlowin/fastmcp/blob/v2.14.4/pyproject.toml#L13, but, in the upcoming 3.0, pydocket will become optional, which kinda helps, but they have introduced opentelemetry-api as required dependency 😅. I will need to have the same conversation with fastmcp community once 3.0 lands, so 😅… It's a more general problem. Unfortunately, I don't think there is a timeline for when it will come out of beta, that's why I'm pursuing this update in here, because if I can get pydocket build/shipping in Fedora, I can get fastmcp 2.14 (current stable) shipped as well.
It's not that making the opentelemetry-sdk optional is not helpful, it is just that, If I unretire the package in Fedora, that means I will need to support all that was shipped before, and that includes the |
|
Ha, well that "community" that introduced What we're doing in I'd like to help you get this fixed at the source, which seems to be Fedora's packaging of the opentelemetry Python libraries. If we don't fix this at the source, then I think you'll just keep having this problem in general. Solving it here and making Docket and FastMCP more complex is a last resort. It sounds to me like the core problem is that Fedora's packages for opentelemetry-python are bundled as a monolith, so you can't get So first, is every Python library in existence supposed to be represented separately in Fedora? Like, did someone make a |
|
Maybe let's back up and start at the core problem you're hitting when you try to build the |
|
This release Jeremiah just cut of FastMCP 2.x should definitely help: https://github.com/jlowin/fastmcp/releases/tag/v2.14.5 |
|
Hi, @chrisguidry! I took it back with the former maintainer of OTEL package in Fedora, and he gave me a workaround that I could probably just package otel-api instead of the whole workspace. I have opened a package review in Fedora for it. If that works, then this won't be needed anymore. |
|
Ooo that's great news! Mind linking to it here? |
|
https://bugzilla.redhat.com/show_bug.cgi?id=2436472 here is the bugzilla for the package review. Hopefully someone will be able to take a look at this soon. |
|
Oh, thanks! I forgot to come here to close this. |

Move opentelemetry-api from required dependencies to optional extras, allowing docket to be used without OpenTelemetry installed. When OTel is not available, the library silently uses noop stub implementations that maintain the same interface but perform no operations.
This change is particularly helpful for Linux distribution packagers, especially in Fedora, where the OpenTelemetry Python packages have faced significant packaging challenges. As discussed in the Fedora devel mailing list thread [1], the opentelemetry-* packages have been difficult to maintain and may be orphaned or retired, making it problematic for packages that hard-depend on them.
By making OpenTelemetry optional, docket can be packaged and used in distributions without requiring the full OpenTelemetry stack, while users who want observability features can still install them via:
Implementation details:
[1] https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/3LHITWOBP76JNSQICDDX5BHFVFCFS4NA/