Skip to content

Commit 2119f5f

Browse files
authored
Add the enable tracing opt-in flag (#4685)
## Which problem is this PR solving? Resolves #4680 ## Description of the changes - Add an opt-in option `--query.enable-tracing` to enable tracing for the jaeger-query component. - The jaeger all-in-one component does not expose this flag since traces are emitted to port 4317 by default, which all-in-one listens on. ## How was this change tested? ``` # Run jaeger-query component with tracing enabled and verify that the connection errors are appearing in stdout. $ SPAN_STORAGE_TYPE=memory go run -tags ui ./cmd/query/main.go --query.enable-tracing ... {"level":"info","ts":1692363754.9049716,"caller":"grpc/clientconn.go:1301","msg":"[core][Channel #1 SubChannel #2] Subchannel Connectivity change to CONNECTING","system":"grpc","grpc_log":true} {"level":"info","ts":1692363754.9050152,"caller":"grpc/clientconn.go:1414","msg":"[core][Channel #1 SubChannel #2] Subchannel picks a new address \"localhost:4317\" to connect","system":"grpc","grpc_log":true} {"level":"warn","ts":1692363754.9058733,"caller":"grpc/clientconn.go:1476","msg":"[core][Channel #1 SubChannel #2] grpc: addrConn.createTransport failed to connect to {Addr: \"localhost:4317\", ServerName: \"localhost:4317\", }. Err: connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:4317: connect: connection refused\"","system":"grpc","grpc_log":true} {"level":"info","ts":1692363754.9067123,"caller":"grpc/clientconn.go:1303","msg":"[core][Channel #1 SubChannel #2] Subchannel Connectivity change to TRANSIENT_FAILURE, last error: connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:4317: connect: connection refused\"","system":"grpc","grpc_log":true} ... # Run jaeger-query component with tracing disabled and verify that the connection errors no longer appear. # Of course, we can't see traces in Jaeger UI because there's nothing to receive the traces. $ SPAN_STORAGE_TYPE=memory go run -tags ui ./cmd/query/main.go # Start an all-in-one instance just as a quick and dirty way to bring up an in-memory jaeger stack to # receive traces from jaeger-query $ make run-all-in-one # Run jaeger-query as a separate component, listening on different ports to all-in-one to avoid port binding collisions. $ SPAN_STORAGE_TYPE=memory go run -tags ui ./cmd/query/main.go --query.enable-tracing --query.grpc-server.host-port :17685 --query.http-server.host-port :17686 --admin.http.host-port :17687 # Open localhost:17686 in a browser and refresh a few times to emit traces to jaeger all-in-one. ``` Confirmed that `jaeger-query` is visible and contains traces: <img width="1572" alt="Screenshot 2023-08-18 at 11 45 26 pm" src="https://github.com/jaegertracing/jaeger/assets/26584478/a348e804-6d37-49f9-9d9f-f73854e9b6bc"> ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits ~- [] I have added unit tests for the new functionality~ - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: albertteoh <see.kwang.teoh@gmail.com>
1 parent 4798446 commit 2119f5f

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

cmd/all-in-one/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/spf13/cobra"
2626
"github.com/spf13/viper"
27-
"go.opentelemetry.io/otel"
2827
_ "go.uber.org/automaxprocs"
2928
"go.uber.org/zap"
3029

@@ -105,7 +104,6 @@ by default uses only in-memory database.`,
105104
if err != nil {
106105
logger.Fatal("Failed to initialize tracer", zap.Error(err))
107106
}
108-
otel.SetTracerProvider(tracer.OTEL)
109107

110108
storageFactory.InitFromViper(v, logger)
111109
if err := storageFactory.Initialize(metricsFactory, logger); err != nil {

cmd/query/app/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
queryTokenPropagation = "query.bearer-token-propagation"
4848
queryAdditionalHeaders = "query.additional-headers"
4949
queryMaxClockSkewAdjust = "query.max-clock-skew-adjustment"
50+
queryEnableTracing = "query.enable-tracing"
5051
)
5152

5253
var tlsGRPCFlagsConfig = tlscfg.ServerFlagsConfig{
@@ -85,6 +86,8 @@ type QueryOptions struct {
8586
MaxClockSkewAdjust time.Duration
8687
// Tenancy configures tenancy for query
8788
Tenancy tenancy.Options
89+
// EnableTracing determines whether traces will be emitted by jaeger-query.
90+
EnableTracing bool
8891
}
8992

9093
// AddFlags adds flags for QueryOptions
@@ -98,6 +101,7 @@ func AddFlags(flagSet *flag.FlagSet) {
98101
flagSet.String(queryUIConfig, "", "The path to the UI configuration file in JSON format")
99102
flagSet.Bool(queryTokenPropagation, false, "Allow propagation of bearer token to be used by storage plugins")
100103
flagSet.Duration(queryMaxClockSkewAdjust, 0, "The maximum delta by which span timestamps may be adjusted in the UI due to clock skew; set to 0s to disable clock skew adjustments")
104+
flagSet.Bool(queryEnableTracing, false, "Enables emitting jaeger-query traces")
101105
tlsGRPCFlagsConfig.AddFlags(flagSet)
102106
tlsHTTPFlagsConfig.AddFlags(flagSet)
103107
}
@@ -131,6 +135,7 @@ func (qOpts *QueryOptions) InitFromViper(v *viper.Viper, logger *zap.Logger) (*Q
131135
qOpts.AdditionalHeaders = headers
132136
}
133137
qOpts.Tenancy = tenancy.InitFromViper(v)
138+
qOpts.EnableTracing = v.GetBool(queryEnableTracing)
134139
return qOpts, nil
135140
}
136141

cmd/query/main.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/spf13/cobra"
2525
"github.com/spf13/viper"
26-
"go.opentelemetry.io/otel"
2726
_ "go.uber.org/automaxprocs"
2827
"go.uber.org/zap"
2928

@@ -73,15 +72,20 @@ func main() {
7372
baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
7473
metricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "query"})
7574
version.NewInfoMetrics(metricsFactory)
76-
jtracer, err := jtracer.New("jaeger-query")
77-
if err != nil {
78-
logger.Fatal("Failed to create tracer:", zap.Error(err))
79-
}
80-
otel.SetTracerProvider(jtracer.OTEL)
75+
8176
queryOpts, err := new(app.QueryOptions).InitFromViper(v, logger)
8277
if err != nil {
8378
logger.Fatal("Failed to configure query service", zap.Error(err))
8479
}
80+
81+
jt := jtracer.NoOp()
82+
if queryOpts.EnableTracing {
83+
jt, err = jtracer.New("jaeger-query")
84+
if err != nil {
85+
logger.Fatal("Failed to create tracer", zap.Error(err))
86+
}
87+
}
88+
8589
// TODO: Need to figure out set enable/disable propagation on storage plugins.
8690
v.Set(bearertoken.StoragePropagationKey, queryOpts.BearerTokenPropagation)
8791
storageFactory.InitFromViper(v, logger)
@@ -108,7 +112,7 @@ func main() {
108112
dependencyReader,
109113
*queryServiceOptions)
110114
tm := tenancy.NewManager(&queryOpts.Tenancy)
111-
server, err := app.NewServer(svc.Logger, queryService, metricsQueryService, queryOpts, tm, jtracer)
115+
server, err := app.NewServer(svc.Logger, queryService, metricsQueryService, queryOpts, tm, jt)
112116
if err != nil {
113117
logger.Fatal("Failed to create server", zap.Error(err))
114118
}
@@ -128,7 +132,7 @@ func main() {
128132
if err := storageFactory.Close(); err != nil {
129133
logger.Error("Failed to close storage factory", zap.Error(err))
130134
}
131-
if err = jtracer.Close(context.Background()); err != nil {
135+
if err = jt.Close(context.Background()); err != nil {
132136
logger.Fatal("Error shutting down tracer provider", zap.Error(err))
133137
}
134138
})

examples/memstore-plugin/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/hashicorp/go-plugin"
2424
"github.com/spf13/viper"
2525
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
26-
"go.opentelemetry.io/otel"
2726
googleGRPC "google.golang.org/grpc"
2827

2928
"github.com/jaegertracing/jaeger/pkg/jtracer"
@@ -62,7 +61,6 @@ func main() {
6261
panic(fmt.Errorf("failed to initialize tracer: %w", err))
6362
}
6463
defer tracer.Close(context.Background())
65-
otel.SetTracerProvider(tracer.OTEL)
6664

6765
memStorePlugin := grpcMemory.NewStoragePlugin(memory.NewStore(), memory.NewStore())
6866
service := &shared.PluginServices{

pkg/jtracer/jtracer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func initOTEL(ctx context.Context, svc string) (*sdktrace.TracerProvider, error)
8888
))
8989
})
9090

91+
otel.SetTracerProvider(tracerProvider)
92+
9193
return tracerProvider, nil
9294
}
9395

0 commit comments

Comments
 (0)