Skip to content

Commit

Permalink
server: Add support for B3 headers via JAEGER_PROPAGATION (#1456)
Browse files Browse the repository at this point in the history
This will provide compatibility with istio.

Closes #1447
  • Loading branch information
ptescher authored and aeneasr committed Jun 12, 2019
1 parent 23e0e6a commit 400c47f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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

0 comments on commit 400c47f

Please sign in to comment.