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

Inject trace context to grpc metadata #2870

Conversation

lujiajing1126
Copy link
Contributor

@lujiajing1126 lujiajing1126 commented Mar 9, 2021

Signed-off-by: Megrez Lu lujiajing1126@gmail.com

Which problem is this PR solving?

Resolve #2869

Short description of the changes

  • Update go-plugin to 1.4.2
  • Add interceptors to support tracing propagation

@lujiajing1126 lujiajing1126 requested a review from a team as a code owner March 9, 2021 06:14
@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #2870 (92733ab) into master (2687983) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2870      +/-   ##
==========================================
+ Coverage   96.00%   96.03%   +0.03%     
==========================================
  Files         229      229              
  Lines        9937     9941       +4     
==========================================
+ Hits         9540     9547       +7     
+ Misses        327      325       -2     
+ Partials       70       69       -1     
Impacted Files Coverage Δ
plugin/storage/grpc/shared/archive.go 100.00% <100.00%> (ø)
plugin/storage/grpc/shared/grpc_client.go 87.06% <100.00%> (+0.46%) ⬆️
cmd/collector/app/server/zipkin.go 61.53% <0.00%> (-15.39%) ⬇️
plugin/storage/integration/integration.go 77.90% <0.00%> (+0.55%) ⬆️
plugin/storage/badger/spanstore/reader.go 96.08% <0.00%> (+0.71%) ⬆️
...lugin/sampling/strategystore/adaptive/processor.go 100.00% <0.00%> (+0.92%) ⬆️
cmd/query/app/static_handler.go 96.77% <0.00%> (+1.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2687983...92733ab. Read the comment docs.

@@ -44,7 +44,7 @@ type archiveWriter struct {

// GetTrace takes a traceID and returns a Trace associated with that traceID from Archive Storage
func (r *archiveReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
stream, err := r.client.GetArchiveTrace(upgradeContextWithBearerToken(ctx), &storage_v1.GetTraceRequest{
stream, err := r.client.GetArchiveTrace(upgradeWithTraceContext(upgradeContextWithBearerToken(ctx)), &storage_v1.GetTraceRequest{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be time to split the statement here, creating the context in one and using it in another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've used a functional type with a composition function to refactor this part. I suppose it is fine now.

if !ok {
md = metadata.New(nil)
} else {
md = md.Copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need a copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. I've checked it is unnecessary.

@@ -0,0 +1,51 @@
// Copyright (c) 2019 The Jaeger Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

oops?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to 2021

@@ -85,7 +121,7 @@ func (c *grpcClient) ArchiveSpanWriter() spanstore.Writer {

// GetTrace takes a traceID and returns a Trace associated with that traceID
func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
stream, err := c.readerClient.GetTrace(upgradeContextWithBearerToken(ctx), &storage_v1.GetTraceRequest{
stream, err := c.readerClient.GetTrace(upgradeWithTraceContext(upgradeContextWithBearerToken(ctx)), &storage_v1.GetTraceRequest{
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the number of places calling the two upgrade functions, it might be a good idea to combine both in another function, and use only this other function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in the same way

@lujiajing1126
Copy link
Contributor Author

lujiajing1126 commented Mar 9, 2021

@jpkrohling Any idea why unit test failed? I don't think it is related to my latest modification

Update: Seems not stable

return ctx
}

if span := opentracing.SpanFromContext(ctx); span != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This is not now RPCs are typically instrumented, you need to create a child span for each outbound request.

Also, there is a common lib https://opentracing.io/registry/go-grpc/ for gRPC instrumentation, can we use that instead of doing manual instrumentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I agree with you that a child span should be created. But this is acutally a compromise here that I make use of the active span from the context.

The difficulty stems from the fact that go-plugin does not support customized DialOption which I have mentioned in the issue #2869.

The server-side code can use https://github.com/opentracing-contrib/go-grpc

Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
@lujiajing1126 lujiajing1126 force-pushed the gprc-storage-inject-propagation-headers branch from 0bdde89 to 4c600f6 Compare June 4, 2021 01:18
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
@lujiajing1126 lujiajing1126 force-pushed the gprc-storage-inject-propagation-headers branch from 15da37b to a559ebc Compare June 4, 2021 02:19
@lujiajing1126
Copy link
Contributor Author

lujiajing1126 commented Jun 4, 2021

@jpkrohling @yurishkuro I've updated to the latest go-plugin(v1.4.2) to enable client-side gRPC tracing. Could you kindly have a review again?

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

  • I see you're only changing grpc-client. Are there similar changes needed for the server?
  • since there are no tests for tracing instrumentation of the plugin, could you try a manual test and post a screenshot of the trace?

@@ -16,11 +16,14 @@ package config

import (
"fmt"
"github.com/opentracing/opentracing-go"
Copy link
Member

Choose a reason for hiding this comment

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

please move to the next group (I think make fmt will do this automatically)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
@lujiajing1126
Copy link
Contributor Author

lujiajing1126 commented Jun 4, 2021

  • I see you're only changing grpc-client. Are there similar changes needed for the server?

The plugin developer can enable tracing while starting the plugin server.

grpc.ServeWithGRPCServer(
				store.NewAliyunSLSStore(&appConfig, logger),
				func(options []googleGRPC.ServerOption) *googleGRPC.Server {
					return plugin.DefaultGRPCServer([]googleGRPC.ServerOption{
						googleGRPC.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)),
						googleGRPC.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)),
					})
				},
			)

Do we need to make it a default option?

  • since there are no tests for tracing instrumentation of the plugin, could you try a manual test and post a screenshot of the trace?

image

@yurishkuro
Copy link
Member

I don't know if there's a place to make this a default option, at minimum it would make sense to mention this in the plugin/README, and perhaps add to examples/memstore-plugin/main.go ?

Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
@lujiajing1126
Copy link
Contributor Author

I don't know if there's a place to make this a default option, at minimum it would make sense to mention this in the plugin/README, and perhaps add to examples/memstore-plugin/main.go ?

I've added a tracing section in the document as well as code in the memstore example.

@jpkrohling
Copy link
Contributor

Should 1.23 wait for this one?

@jpkrohling jpkrohling added this to the Release 1.23.0 milestone Jun 4, 2021
@jpkrohling jpkrohling enabled auto-merge (squash) June 4, 2021 14:37
@jpkrohling jpkrohling merged commit ff32436 into jaegertracing:master Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support trace propagation for gRPC plugin
3 participants