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

Make sure the GRPC client interceptor actually returns the response #2928

Merged

Conversation

KJTsanaktsidis
Copy link
Contributor

@KJTsanaktsidis KJTsanaktsidis commented Jun 23, 2023

What does this PR do?
Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Client#trace is currently causing all GRPC client operations to return 0.0 instead of whatever they were supposed to return. This is a bit of a Ruby gotcha.

This method returns :three

def broken_method
    begin
        :one
    rescue => e
        :two
    else
        :three
    end
end

So when #trace is putting yield in a begin block with an else, it's not actually returning the result of yield; it's returning the result of the else block. I guess this was broken in #2620

Fix it by explicitly returning the result of yield.

Motivation
All my GRPC client methods started returning 0.0 after upgrading ddtrace 😱

Additional Notes

How to test the change?
Now my GRPC client methods don't return 0.0! I included a test in this patch.

@KJTsanaktsidis KJTsanaktsidis requested a review from a team June 23, 2023 12:18
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Jun 23, 2023
@KJTsanaktsidis KJTsanaktsidis changed the title Make sure the client interceptor actually returns the response Make sure the GRPC client interceptor actually returns the response Jun 23, 2023
Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Client#trace is
currently causing all GRPC client operations to return 0.0 instead of
whatever they were supposed to return. This is a bit of a Ruby gotcha.

This method returns :three

```ruby
def broken_method
    begin
        :one
    rescue => e
        :two
    else
        :three
    end
end
```

So when `#trace` is putting `yield` in a `begin` block with an `else`,
it's not actually returning the result of yield; it's returning the
result of the else block.

Fix it by explicitly returning the result of yield.
@KJTsanaktsidis KJTsanaktsidis force-pushed the ktsanaktsidis/fix_grpc_client_result branch from 8d5ed99 to 01d7a0e Compare June 23, 2023 12:26
Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

Thank you, @KJTsanaktsidis!

@marcotc marcotc added this to the 1.13.0 milestone Jun 23, 2023
@marcotc marcotc merged commit a4b81cf into DataDog:master Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants