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 fix for passing thrift client name in interop #679

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions internalv2compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ type IsThrift interface {
isThrift()
}

// ClientTraceMiddlewareArgs is the arguments used to instantiate client tracing middleware
//
// This struct is exported so that it can be used by baseplate V2 interop utilities.
type ClientTraceMiddlewareArgs struct {
ServiceName string
}

type ThriftClientTraceMiddlewareProvider func(args ClientTraceMiddlewareArgs) thrift.ClientMiddleware

var v2Tracing struct {
sync.Mutex
enabled bool

thriftClientMiddleware thrift.ClientMiddleware
thriftServerMiddleware thrift.ProcessorMiddleware
thriftClientMiddlewareProvider ThriftClientTraceMiddlewareProvider
thriftServerMiddleware thrift.ProcessorMiddleware

httpClientMiddleware func(base http.RoundTripper) http.RoundTripper
httpServerMiddleware func(name string, next http.Handler) http.Handler
Expand All @@ -93,13 +102,27 @@ func V2TracingEnabled() bool {
func SetV2TracingThriftClientMiddleware(middleware thrift.ClientMiddleware) {
v2Tracing.Lock()
defer v2Tracing.Unlock()
v2Tracing.thriftClientMiddleware = middleware
v2Tracing.thriftClientMiddlewareProvider = func(args ClientTraceMiddlewareArgs) thrift.ClientMiddleware {
return middleware
}
}

func V2TracingThriftClientMiddleware() thrift.ClientMiddleware {
v2Tracing.Lock()
defer v2Tracing.Unlock()
return v2Tracing.thriftClientMiddleware
if v2Tracing.thriftClientMiddlewareProvider == nil {
return nil
}
return v2Tracing.thriftClientMiddlewareProvider(ClientTraceMiddlewareArgs{ServiceName: "unknown"})
}

func V2TracingThriftClientMiddlewareWithArgs(args ClientTraceMiddlewareArgs) thrift.ClientMiddleware {
v2Tracing.Lock()
defer v2Tracing.Unlock()
if v2Tracing.thriftClientMiddlewareProvider == nil {
return nil
}
return v2Tracing.thriftClientMiddlewareProvider(args)
}

func SetV2TracingThriftServerMiddleware(middleware thrift.ProcessorMiddleware) {
Expand Down
6 changes: 4 additions & 2 deletions thriftbp/client_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func BaseplateDefaultClientMiddlewares(args DefaultClientMiddlewareArgs) []thrif
ForwardEdgeRequestContext(args.EdgeContextImpl),
SetClientName(args.ClientName),
MonitorClient(MonitorClientArgs{
ServiceSlug: args.ServiceSlug + MonitorClientWrappedSlugSuffix,
ServiceSlug: args.ServiceSlug,
ErrorSpanSuppressor: args.ErrorSpanSuppressor,
}),
PrometheusClientMiddleware(args.ServiceSlug + MonitorClientWrappedSlugSuffix),
Expand Down Expand Up @@ -211,7 +211,9 @@ var monitorClientLoggingOnce sync.Once
// This middleware always use the injected v2 tracing thrift client middleware.
// If there's no v2 tracing thrift client middleware injected, it's no-op.
func MonitorClient(args MonitorClientArgs) thrift.ClientMiddleware {
if mw := internalv2compat.V2TracingThriftClientMiddleware(); mw != nil {
if mw := internalv2compat.V2TracingThriftClientMiddlewareWithArgs(
internalv2compat.ClientTraceMiddlewareArgs{ServiceName: args.ServiceSlug},
); mw != nil {
return mw
}
return func(next thrift.TClient) thrift.TClient {
Expand Down