diff --git a/config/config.go b/config/config.go index bb122829..165754b2 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 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"` + // Tags can be provided by FromEnv() via the environment variable named JAEGER_TAGS Tags []opentracing.Tag `yaml:"tags"` @@ -261,13 +267,16 @@ 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(true)) + } + 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",