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

GRPC traces called twice when result evaluates to false #3380

Open
kevmodo opened this issue Mar 21, 2025 · 0 comments · May be fixed by #3381
Open

GRPC traces called twice when result evaluates to false #3380

kevmodo opened this issue Mar 21, 2025 · 0 comments · May be fixed by #3381
Labels
bug Something isn't working

Comments

@kevmodo
Copy link

kevmodo commented Mar 21, 2025

Describe your environment

OS: MacOS
Python version: 3.12.9
Package version: commit a5474c3b290f5fcd7b5e8f9953ae8b2891c374c0
google-cloud-pubsub 2.28.0

What happened?

When instrumenting Google Cloud PubSub, I see a lot of log messages Calling end() on an ended span..

This appears to happen whenever no messages are available after a PubSub call:

...
GrpcInstrumentorClient().instrument()

subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(env.pubsub_project_id, env.subscription_id)
with subscriber:
    while True:
        response = subscriber.pull(
            subscription=subscription_path,
            max_messages=1,
            retry=retry.Retry(timeout=env.timeout),
        )
       ...

This appears to be due to

which ends the span when result evaluates falsy.

But then since there was no exception, program flow continues to

, where it calls span.end().

My interpretation of the if not result: is that it's mainly acting as an indication that there was an exception; at any rate, in my simple use case, spans seem to start and end correctly if I change it to if result is None:.

Steps to Reproduce

...
GrpcInstrumentorClient().instrument()

subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(env.pubsub_project_id, env.subscription_id)
with subscriber:
    while True:
        response = subscriber.pull(
            subscription=subscription_path,
            max_messages=1,
            retry=retry.Retry(timeout=env.timeout),
        )
       ...

(This relies on an empty queue. I'm not familiar enough with gRPC to create a fully standalone test at this point)

Expected Result

Only a single span.end() call for each span created.

Actual Result

span.end() is called twice when result contains no messages.

Additional context

No response

Would you like to implement a fix?

Yes

@kevmodo kevmodo added the bug Something isn't working label Mar 21, 2025
kevmodo pushed a commit to kevmodo/opentelemetry-python-contrib that referenced this issue Mar 21, 2025
kevmodo added a commit to kevmodo/opentelemetry-python-contrib that referenced this issue Mar 21, 2025
@kevmodo kevmodo linked a pull request Mar 21, 2025 that will close this issue
10 tasks
kevmodo added a commit to kevmodo/opentelemetry-python-contrib that referenced this issue Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant