Skip to content

Add OpenTelemetry middleware#150

Open
anuraaga wants to merge 4 commits intoconnectrpc:mainfrom
anuraaga:connectrpc-otel
Open

Add OpenTelemetry middleware#150
anuraaga wants to merge 4 commits intoconnectrpc:mainfrom
anuraaga:connectrpc-otel

Conversation

@anuraaga
Copy link
Collaborator

@anuraaga anuraaga commented Mar 3, 2026

Initial implement with basic tracing / propagation. Follow-ups will add opt-in metadata attributes and metrics.

Some questions

  • Whether to use a separate package at all. As an "OTel guy" I'm happy to go with native instrumentation built into the library as I did with pyqwest (single dep on opentelemetry-api) but started with middleware since it's more common.
  • PyPi package name - I went with connectrpc-otel hoping we will publish to connectrpc eventually (not sure the latest on that)
  • Whether to use a workspace package vs separate repo. It probably won't really depend on much of conenctrpc and could be better to version separately, but it becomes easier to lose track of the repo

Happy with any direction for these.

https://opentelemetry.io/docs/specs/semconv/rpc/connect-rpc/

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@anuraaga anuraaga requested a review from a team March 3, 2026 07:27
anuraaga added 2 commits March 3, 2026 16:29
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
finally:
self._finish_span(span, error)

async def intercept_client_stream(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added unit tests for unary for now since I'll probably avoid the stream-type specific interceptors after #149

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@stefanvanburen
Copy link
Member

  • Whether to use a workspace package vs separate repo. It probably won't really depend on much of conenctrpc and could be better to version separately, but it becomes easier to lose track of the repo

Are we able to keep the upstreamed PyPI version completely separated? I think as long as we can do that, it's probably ok to keep in this repo — I think we avoided it with Go because it's annoying to do multi-module versioning in a single repo, and probably borrowed that approach for the -es repos (like @connectrpc/validate).

If we can do e.g. tag connectrpc-otel/0.1.0 and have that release just that package, probably fine? I don't know exactly how all the recent python tooling works with this sort of set up. Just wanted to get your thoughts before taking a closer look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants