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

[Tracing Redesign][2/N] Implement tracing unary Interceptors #2304

Merged
merged 28 commits into from
Oct 28, 2024

Conversation

kexiongliu123
Copy link

This PR introduces the unary interceptors in YARPC Go to improve the structure and functionality of tracing and middleware handling. The primary focus is on separating the unary interceptors to allow for specialized optimizations and cleaner handling of tracing operations.

Key Changes:

Introduced a dedicated UnaryInbound and UnaryOutbound middleware architecture, simplifying the tracing logic for unary requests.
Introduced inbound.go and outbound.go files to reflect the specialized unary middleware design, improving maintainability and reducing complexity.
Enhanced test coverage for the unary path, ensuring that all middleware logic is properly unit tested with specific focus on the flow of unary RPCs.
Updated helper methods for extracting and applying tracing tags to unary requests, ensuring clearer separation of concerns.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

internal/tracinginterceptor/tagshelper.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/tagshelper.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/tagshelper.go Outdated Show resolved Hide resolved
transport/tchannel/channel_transport.go Outdated Show resolved Hide resolved
internal/interceptor/inbound.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor_test.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
api/transport/propagation.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
transport/tchannel/tracing/tracing.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
defer span.Finish()

err := h.Handle(ctx, req, resw)
if appErrSetter, ok := resw.(interface{ IsApplicationError() bool }); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

The writer wrapper is probably still the right way to go with, the reasons are:

  1. We also want to get the applicationErrorMeta
  2. For the case where yarpc dispatcher is not used (hence obs middleware is not used), the original writer doesn't have IsApplicationError() method at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Moreover, IsApplicationError() is implemented only for tChannel it seems. So tag value won't be set for other transports.

internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
@@ -22,10 +22,15 @@ package tracinginterceptor

import (
"context"
"go.uber.org/yarpc/transport/tchannel/tracing"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rebase to the fresh dev branch, I added linter for imports.

Copy link
Author

Choose a reason for hiding this comment

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

This hasn't been addressed in this commit, but I will address it eventually.

internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
defer span.Finish()

err := h.Handle(ctx, req, resw)
if appErrSetter, ok := resw.(interface{ IsApplicationError() bool }); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Moreover, IsApplicationError() is implemented only for tChannel it seems. So tag value won't be set for other transports.

api/transport/response.go Outdated Show resolved Hide resolved
api/transport/response.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
transport/grpc/response_writer.go Outdated Show resolved Hide resolved
transport/http/handler.go Outdated Show resolved Hide resolved
transport/tchannel/handler.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
internal/tracinginterceptor/interceptor.go Outdated Show resolved Hide resolved
transport/tchannel/handler.go Outdated Show resolved Hide resolved
}
return err
}
span.SetTag(errorCodeTag, unknownInternalYarpcError)
Copy link
Contributor

Choose a reason for hiding this comment

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

We have two sort of error code span tags here: 1) rpc.yarpc.status_code, 2) error.code.
And we have 3 conditions here: 1) L198 - yarpc code derivable from err, 2) L204 - application err, 3) L217 - none of above

But they are not consistent:

  • condition 1. sets tag 1) and tag 2)
  • condition 2. sets tag 1)
  • condition 3. sets tag 2)

Let's just just use tag 1) - rpc.yarpc.status_code for all of them. So for condition 3, can we use

span.SetTag(rpcStatusCodeTag, int(yarpcerrors.CodeUnknown))

And for condition 1, let's remove error.code tag.

For this general error.code span tag, let's add it during our ingestion pipeline, and use similar format like muttley error code: https://engwiki.uberinternal.com/display/TE0OBSERVAPPS/RPC+Error+Codes

Copy link
Contributor

@ChenX1993 ChenX1993 left a comment

Choose a reason for hiding this comment

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

Good job!

@biosvs biosvs merged commit 04e4f2b into yarpc:dev-tracing-fix Oct 28, 2024
16 of 17 checks passed
kexiongliu123 added a commit to kexiongliu123/yarpc-go that referenced this pull request Dec 19, 2024
)

Added ExtendedResponseWriter, implemented tracing for unary inbounds/outbounds.
biosvs pushed a commit that referenced this pull request Dec 30, 2024
Added ExtendedResponseWriter, implemented tracing for unary inbounds/outbounds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants