Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Support JAEGER_TRACEID_128BIT env var
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Nov 27, 2020
1 parent 9d60a81 commit 39e8d47
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions config/config_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}
Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -133,13 +134,15 @@ 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)

// cleanup
unsetEnv(t, envServiceName)
unsetEnv(t, envDisabled)
unsetEnv(t, envRPCMetrics)
unsetEnv(t, env128bit)
unsetEnv(t, envTags)
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 39e8d47

Please sign in to comment.