From 47a0f4e2942da49fb7a71f42b21e407f568886ef Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 26 Nov 2020 12:44:20 -0500 Subject: [PATCH 1/2] Support JAEGER_TRACEID_128BIT env var Signed-off-by: Yuri Shkuro --- config/config.go | 14 +++++++++++--- config/config_env.go | 9 +++++++++ config/config_test.go | 7 +++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index bb122829..bd0a1812 100644 --- a/config/config.go +++ b/config/config.go @@ -40,12 +40,18 @@ type Configuration struct { // Can be provided by FromEnv() via the environment variable named JAEGER_SERVICE_NAME ServiceName string `yaml:"serviceName"` - // Disabled can be provided by FromEnv() via the environment variable named JAEGER_DISABLED + // Disabled makes the config return opentracing.NoopTracer. + // Value can be provided by FromEnv() via the environment variable named JAEGER_DISABLED. Disabled bool `yaml:"disabled"` - // RPCMetrics can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICS + // RPCMetrics enables generations of RPC metrics (requires metrics factory to be provided). + // Value can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICS RPCMetrics bool `yaml:"rpc_metrics"` + // Gen128Bit isntructs the tracer to generate 128-bit wide trace IDs, compatible with W3C Trace Context. + // Value can be provided by FromEnv() via the environment variable named JAEGER_TRACEID_128BIT. + Gen128Bit bool `yaml:"traceid_128bit"` + // Tags can be provided by FromEnv() via the environment variable named JAEGER_TAGS Tags []opentracing.Tag `yaml:"tags"` @@ -261,12 +267,14 @@ func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Clos jaeger.TracerOptions.Metrics(tracerMetrics), jaeger.TracerOptions.Logger(opts.logger), jaeger.TracerOptions.CustomHeaderKeys(c.Headers), - jaeger.TracerOptions.Gen128Bit(opts.gen128Bit), jaeger.TracerOptions.PoolSpans(opts.poolSpans), jaeger.TracerOptions.ZipkinSharedRPCSpan(opts.zipkinSharedRPCSpan), jaeger.TracerOptions.MaxTagValueLength(opts.maxTagValueLength), jaeger.TracerOptions.NoDebugFlagOnForcedSampling(opts.noDebugFlagOnForcedSampling), } + if c.Gen128Bit || opts.gen128Bit { + tracerOptions = append(tracerOptions, jaeger.TracerOptions.Gen128Bit(opts.gen128Bit)) + } for _, tag := range opts.tags { tracerOptions = append(tracerOptions, jaeger.TracerOptions.Tag(tag.Key, tag.Value)) diff --git a/config/config_env.go b/config/config_env.go index 92d60cd5..0fc3c53f 100644 --- a/config/config_env.go +++ b/config/config_env.go @@ -49,6 +49,7 @@ const ( envPassword = "JAEGER_PASSWORD" envAgentHost = "JAEGER_AGENT_HOST" envAgentPort = "JAEGER_AGENT_PORT" + env128bit = "JAEGER_TRACEID_128BIT" ) // FromEnv uses environment variables to set the tracer's Configuration @@ -83,6 +84,14 @@ func (c *Configuration) FromEnv() (*Configuration, error) { c.Tags = parseTags(e) } + if e := os.Getenv(env128bit); e != "" { + if value, err := strconv.ParseBool(e); err == nil { + c.Gen128Bit = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", env128bit, e) + } + } + if c.Sampler == nil { c.Sampler = &SamplerConfig{} } diff --git a/config/config_test.go b/config/config_test.go index 6f97d0a6..adb40dbd 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -123,6 +123,7 @@ func TestConfigFromEnv(t *testing.T) { setEnv(t, envServiceName, "my-service") setEnv(t, envDisabled, "false") setEnv(t, envRPCMetrics, "true") + setEnv(t, env128bit, "true") setEnv(t, envTags, "KEY=VALUE") // test with env set @@ -133,6 +134,7 @@ func TestConfigFromEnv(t *testing.T) { assert.Equal(t, "my-service", cfg.ServiceName) assert.Equal(t, false, cfg.Disabled) assert.Equal(t, true, cfg.RPCMetrics) + assert.Equal(t, true, cfg.Gen128Bit) assert.Equal(t, "KEY", cfg.Tags[0].Key) assert.Equal(t, "VALUE", cfg.Tags[0].Value) @@ -140,6 +142,7 @@ func TestConfigFromEnv(t *testing.T) { unsetEnv(t, envServiceName) unsetEnv(t, envDisabled) unsetEnv(t, envRPCMetrics) + unsetEnv(t, env128bit) unsetEnv(t, envTags) } @@ -479,6 +482,10 @@ func TestParsingErrorsFromEnv(t *testing.T) { envVar: envDisabled, value: "NOT_A_BOOLEAN", }, + { + envVar: env128bit, + value: "NOT_A_BOOLEAN", + }, { envVar: envSamplerParam, value: "NOT_A_FLOAT", From 43572e6f81bd9bdd47fbab07a879ae02dc4c47d3 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 26 Nov 2020 13:46:23 -0500 Subject: [PATCH 2/2] fixes Signed-off-by: Yuri Shkuro --- config/config.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index bd0a1812..165754b2 100644 --- a/config/config.go +++ b/config/config.go @@ -48,7 +48,7 @@ type Configuration struct { // Value can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICS RPCMetrics bool `yaml:"rpc_metrics"` - // Gen128Bit isntructs the tracer to generate 128-bit wide trace IDs, compatible with W3C Trace Context. + // Gen128Bit instructs the tracer to generate 128-bit wide trace IDs, compatible with W3C Trace Context. // Value can be provided by FromEnv() via the environment variable named JAEGER_TRACEID_128BIT. Gen128Bit bool `yaml:"traceid_128bit"` @@ -272,8 +272,9 @@ func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Clos jaeger.TracerOptions.MaxTagValueLength(opts.maxTagValueLength), jaeger.TracerOptions.NoDebugFlagOnForcedSampling(opts.noDebugFlagOnForcedSampling), } + if c.Gen128Bit || opts.gen128Bit { - tracerOptions = append(tracerOptions, jaeger.TracerOptions.Gen128Bit(opts.gen128Bit)) + tracerOptions = append(tracerOptions, jaeger.TracerOptions.Gen128Bit(true)) } for _, tag := range opts.tags {