Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for grpc aio server interceptor #1870

Merged

Conversation

felipou
Copy link
Contributor

@felipou felipou commented Jul 5, 2023

What does this pull request do?

Add support for grpc aio server (async) instrumentation using an interceptor mostly copied from the "regular", sync, version. For now it's still missing tests, but I'm creating the PR just to check if anything breaks in the CI.

Related issues

Closes #1869

@cla-checker-service
Copy link

cla-checker-service bot commented Jul 5, 2023

💚 CLA has been signed

@github-actions github-actions bot added agent-python community Issues opened by the community triage Issues awaiting triage labels Jul 5, 2023
@basepi
Copy link
Contributor

basepi commented Jul 5, 2023

I approved it so tests will run.

@felipou
Copy link
Contributor Author

felipou commented Jul 6, 2023

Thanks @basepi! I saw some problems and fixed them.

I also just tried to push an attempt at the tests. Not sure it will work, I haven't been able to setup my local dev environment yet, will try to do that sometime soon, but if you'd like to run the CI as it is!

@felipou felipou force-pushed the add-support-for-grpc-aio-server-interceptor branch from dd9d354 to c7167fc Compare July 7, 2023 00:10
@felipou felipou force-pushed the add-support-for-grpc-aio-server-interceptor branch from c7167fc to 529a293 Compare July 7, 2023 00:11
@felipou
Copy link
Contributor Author

felipou commented Jul 7, 2023

Turns out it was quite easy to run the tests locally, so I was able to fix some issues and now the tests are running properly.

@basepi
Copy link
Contributor

basepi commented Jul 7, 2023

@felipou Can you please sign the CLA?

@felipou
Copy link
Contributor Author

felipou commented Jul 7, 2023

Ok, done

import grpc

# Check against the oldest version that I believe has the expected API
if parse_version(grpc.__version__) >= parse_version("1.33.1") and hasattr(grpc, "aio"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how I'm checking if we should try to instrument the async version, but I'm not sure what is the recommended way for doing this kind of thing here. I've thought of leaving just the check for the aio module's existence (and perhaps add a check for a server attribute inside grpc.aio), but since I wrote the version check first, I just left it there too.

Async tracing is only supported from python 3.7.
Copy link
Contributor

@basepi basepi left a comment

Choose a reason for hiding this comment

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

One small fix

elasticapm/instrumentation/packages/grpc.py Outdated Show resolved Hide resolved
@basepi basepi enabled auto-merge (squash) July 19, 2023 18:38
@basepi
Copy link
Contributor

basepi commented Jul 19, 2023

@elasticmachine, run elasticsearch-ci/docs

@basepi basepi merged commit 4940236 into elastic:main Jul 19, 2023
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-python community Issues opened by the community triage Issues awaiting triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GRPC aio (async) server instrumentation support
3 participants