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

bug: Set sentry-trace header when using tracing middleware #1331

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

DAcodedBEAT
Copy link
Contributor

@DAcodedBEAT DAcodedBEAT commented Jun 14, 2022

According to PSR-7, withHeader operates in the following manner:

Return an instance with the provided value replacing the specified header.
[...]
This method MUST be implemented in such a way as to retain the
immutability of the message, and MUST return an instance that has the
new and/or updated header and value.

(see: https://www.php-fig.org/psr/psr-7/)

Due to this, we must set $request to the modified request object (from the return value of
withHeader) in order to actually send the sentry-trace header.

Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

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

Nice catch! Can you please update the CHANGELOG (remember to also reference the PR) and change the tests to ensure that no regression can happen in the future?

@DAcodedBEAT
Copy link
Contributor Author

@ste93cry I updated the CHANGELOG and fixed up the tests (I had to rework the unit tests to properly test the request/response values from Guzzle.). Let me know what you think and thanks for the quick reply!

@ste93cry
Copy link
Collaborator

I'm not sure I understand why the entire testing class had to be changed. The lambda that is returned from GuzzleTracingMiddleware::trace() must be invoked by passing to it an handler, which is then called here:

return $handler($request, $options)->then($handlerPromiseCallback, $handlerPromiseCallback);

What we want to assert is that the request contains the sentry-trace header. To do it, it's enough to add the $request parameter to the handler and add the missing assertion...

$function = $middleware(static function () use ($expectedPromiseResult): PromiseInterface {

@DAcodedBEAT
Copy link
Contributor Author

I wanted to make sure the middleware was fully-working from the Guzzle client's configuration perspective (with the added benefit of removing PHPStan violations in the baseline since Guzzle would've been introduced as a dev dependency by using their MockHandler) but you're right -- this can be just the assertion on the header.

I updated this in 72094da. If this test update is acceptable, I can either squash and force-push to my branch or you can do squash these commits on merge. 👍

@DAcodedBEAT DAcodedBEAT requested a review from ste93cry June 16, 2022 00:33
CHANGELOG.md Show resolved Hide resolved
tests/Tracing/GuzzleTracingMiddlewareTest.php Outdated Show resolved Hide resolved
According to PSR-7 (https://www.php-fig.org/psr/psr-7/), `withHeader` operates in the following manner:
```
Return an instance with the provided value replacing the specified header.
[...]
This method MUST be implemented in such a way as to retain the
immutability of the message, and MUST return an instance that has the
new and/or updated header and value.
```

Due to this, we must set `$request` to the modified request object (from the return value of
withHeader) in order to actually send the sentry-trace header.
Copy link
Collaborator

@ste93cry ste93cry 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!

@ste93cry ste93cry merged commit c445901 into getsentry:master Jun 17, 2022
@DAcodedBEAT
Copy link
Contributor Author

Thanks for merging this @ste93cry - can't wait to use the distributed tracing capability!

I noticed this was flagged for the 3.6 milestone but 3.6.0 has already been tagged off. Is this going into a 3.6.1 or would this be in a new semver version?

@ste93cry
Copy link
Collaborator

Yes, since it's a bugfix it will be released with the next patch version. We usually wait a few days/weeks to see if more issues comes and then we make the release

@DAcodedBEAT DAcodedBEAT deleted the patch-1 branch July 1, 2022 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants