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

tracing: Add support for B3 headers via the JAEGER_PROPAGATION env var #1456

Merged
merged 1 commit into from
Jun 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ tracing:
jaeger:
# The address of the jaeger-agent where spans should be sent to
local_agent_address: 127.0.0.1:6831
# The tracing header format
propagation: jaeger
sampling:
# The type of the sampler you want to use. Supports:
# - const
Expand Down
5 changes: 5 additions & 0 deletions driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/viper"

"github.com/ory/x/corsx"
"github.com/ory/x/stringsx"

"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -251,6 +252,10 @@ func (v *ViperProvider) TracingJaegerConfig() *tracing.JaegerConfig {
SamplerType: viperx.GetString(v.l, "tracing.providers.jaeger.sampling.type", "const", "TRACING_PROVIDER_JAEGER_SAMPLING_TYPE"),
SamplerValue: viperx.GetFloat64(v.l, "tracing.providers.jaeger.sampling.value", float64(1), "TRACING_PROVIDER_JAEGER_SAMPLING_VALUE"),
SamplerServerURL: viperx.GetString(v.l, "tracing.providers.jaeger.sampling.server_url", "", "TRACING_PROVIDER_JAEGER_SAMPLING_SERVER_URL"),
Propagation: stringsx.Coalesce(
viper.GetString("JAEGER_PROPAGATION"), // Standard Jaeger client config
viperx.GetString(v.l, "tracing.providers.jaeger.propagation", "", "TRACING_PROVIDER_JAEGER_PROPAGATION"),
),
}
}

Expand Down
19 changes: 19 additions & 0 deletions tracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
jeagerConf "github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/zipkin"
)

type Tracer struct {
Expand All @@ -25,6 +26,7 @@ type JaegerConfig struct {
SamplerType string
SamplerValue float64
SamplerServerUrl string
Propagation string
}

func (t *Tracer) Setup() error {
Expand Down Expand Up @@ -52,8 +54,21 @@ func (t *Tracer) Setup() error {
jc.Reporter.LocalAgentHostPort = t.JaegerConfig.LocalAgentHostPort
}

var configs []jeagerConf.Option

// This works in other jaeger clients, but is not part of jaeger-client-go
if t.JaegerConfig.Propagation == "b3" {
zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
configs = append(
configs,
jeagerConf.Injector(opentracing.HTTPHeaders, zipkinPropagator),
jeagerConf.Extractor(opentracing.HTTPHeaders, zipkinPropagator),
)
}

closer, err := jc.InitGlobalTracer(
t.ServiceName,
configs...,
)

if err != nil {
Expand Down Expand Up @@ -119,6 +134,10 @@ func HelpMessage() string {

Example: TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS=127.0.0.1:6831

- TRACING_PROVIDER_JAEGER_PROPAGATION: The tracing header propagation format. Defaults to jaeger.

Example: TRACING_PROVIDER_JAEGER_PROPAGATION=b3

- TRACING_SERVICE_NAME: Specifies the service name to use on the tracer.

Default: ORY Hydra
Expand Down