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

Support JAEGER_TRACEID_128BIT env var #547

Merged
merged 2 commits into from Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions config/config.go
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
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
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"`

Expand Down Expand Up @@ -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))
}
Expand Down
9 changes: 9 additions & 0 deletions config/config_env.go
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
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