Skip to content

Commit

Permalink
feat: Enable OpenTracing (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptescher authored Mar 14, 2020
1 parent b23c79a commit cb0f3f2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func RunServe(version, build, date string) func(cmd *cobra.Command, args []strin
adminmw.Use(metrics)
publicmw.Use(metrics)

if tracer := d.Registry().Tracer(); tracer.IsLoaded() {
adminmw.Use(tracer)
publicmw.Use(tracer)
}

var wg sync.WaitGroup
tasks := []func(){
runAPI(d, adminmw, logger),
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@ services:
- "4456:4456"
command:
serve --config=/etc/config/oathkeeper/config.yaml
environment:
- TRACING_PROVIDER=jaeger
- TRACING_PROVIDER_JAEGER_SAMPLING_SERVER_URL=http://jaeger:5778/sampling
- TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS=jaeger:6831
- TRACING_PROVIDER_JAEGER_SAMPLING_TYPE=const
- TRACING_PROVIDER_JAEGER_SAMPLING_VALUE=1
volumes:
- type: bind
source: ./.docker_compose
target: /etc/config/oathkeeper
restart: on-failure
jaeger:
image: jaegertracing/all-in-one
ports:
- "16686:16686" # The UI port
# These are ports for collecting, sampling, agents, ...
# - "5775:5775/udp"
# - "6831:6831/udp"
# - "6832:6832/udp"
# - "5778:5778"
# - "14268:14268"
# - "9411:9411"
5 changes: 5 additions & 0 deletions driver/configuration/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/ory/fosite"
"github.com/ory/x/tracing"

"github.com/rs/cors"
)
Expand Down Expand Up @@ -51,6 +52,10 @@ type Provider interface {
ToScopeStrategy(value string, key string) fosite.ScopeStrategy
ParseURLs(sources []string) ([]url.URL, error)
JSONWebKeyURLs() []string

TracingServiceName() string
TracingProvider() string
TracingJaegerConfig() *tracing.JaegerConfig
}

type ProviderErrorHandlers interface {
Expand Down
22 changes: 22 additions & 0 deletions driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ory/fosite"
"github.com/ory/gojsonschema"
"github.com/ory/x/corsx"
"github.com/ory/x/tracing"
"github.com/ory/x/urlx"
"github.com/ory/x/viperx"

Expand Down Expand Up @@ -373,3 +374,24 @@ func (v *ViperProvider) MutatorConfig(id string, override json.RawMessage, dest
func (v *ViperProvider) JSONWebKeyURLs() []string {
return viperx.GetStringSlice(v.l, ViperKeyMutatorIDTokenJWKSURL, []string{})
}

func (v *ViperProvider) TracingServiceName() string {
return viperx.GetString(v.l, "tracing.service_name", "ORY Oathkeeper")
}

func (v *ViperProvider) TracingProvider() string {
return viperx.GetString(v.l, "tracing.provider", "", "TRACING_PROVIDER")
}

func (v *ViperProvider) TracingJaegerConfig() *tracing.JaegerConfig {
return &tracing.JaegerConfig{
LocalAgentHostPort: viperx.GetString(v.l, "tracing.providers.jaeger.local_agent_address", "", "TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS"),
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"),
),
}
}
2 changes: 2 additions & 0 deletions driver/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ory/oathkeeper/rule"
"github.com/ory/oathkeeper/x"
"github.com/ory/x/healthx"
"github.com/ory/x/tracing"
)

type Registry interface {
Expand All @@ -34,6 +35,7 @@ type Registry interface {
CredentialHandler() *api.CredentialsHandler

Proxy() *proxy.Proxy
Tracer() *tracing.Tracer

authn.Registry
authz.Registry
Expand Down
19 changes: 19 additions & 0 deletions driver/registry_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ory/oathkeeper/proxy"

"github.com/ory/x/logrusx"
"github.com/ory/x/tracing"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,6 +39,7 @@ type RegistryMemory struct {
logger logrus.FieldLogger
writer herodot.Writer
c configuration.Provider
trc *tracing.Tracer

ch *api.CredentialsHandler

Expand Down Expand Up @@ -390,3 +392,20 @@ func (r *RegistryMemory) prepareMutators() {
}
}
}

func (r *RegistryMemory) Tracer() *tracing.Tracer {
if r.trc == nil {
r.trc = &tracing.Tracer{
ServiceName: r.c.TracingServiceName(),
JaegerConfig: r.c.TracingJaegerConfig(),
Provider: r.c.TracingProvider(),
Logger: r.Logger(),
}

if err := r.trc.Setup(); err != nil {
r.Logger().WithError(err).Fatalf("Unable to initialize Tracer.")
}
}

return r.trc
}

0 comments on commit cb0f3f2

Please sign in to comment.