Skip to content

Commit

Permalink
[WIP] Add otel tracing implementation support
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Thiesen <[email protected]>
  • Loading branch information
lucastt committed Sep 8, 2023
1 parent c7faea9 commit fbf33d5
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 37 deletions.
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ require (
github.com/uber/jaeger-lib v2.4.1+incompatible
github.com/yookoala/gofast v0.7.0
github.com/yuin/gopher-lua v1.1.0
go.opentelemetry.io/otel v1.17.0
go.opentelemetry.io/otel/bridge/opentracing v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.17.0
go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab
golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0
Expand Down Expand Up @@ -146,13 +153,8 @@ require (
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.17.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,24 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 h1:pginetY7+onl4qN1vl0xW/V/v6OBZ0vVdH+esuJgvmM=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0/go.mod h1:XiYsayHc36K3EByOO6nbAXnAWbrUxdjUROCEeeROOH8=
go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
go.opentelemetry.io/otel v1.17.0 h1:MW+phZ6WZ5/uk2nd93ANk/6yJ+dVrvNWUjGhnnFU5jM=
go.opentelemetry.io/otel v1.17.0/go.mod h1:I2vmBGtFaODIVMBSTPVDlJSzBDNf93k60E6Ft0nyjo0=
go.opentelemetry.io/otel/bridge/opentracing v1.17.0 h1:iDLIoRgDD+ewHEP7nKbx6wJzpLseZ6rWojSHC6KoTg4=
go.opentelemetry.io/otel/bridge/opentracing v1.17.0/go.mod h1:ok+4CU6mpaI3xjA1OnadBCoPFMsELOtk11amo7CJobY=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 h1:t4ZwRPU+emrcvM2e9DHd0Fsf0JTPVcbfa/BhTDF03d0=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0/go.mod h1:vLarbg68dH2Wa77g71zmKQqlQ8+8Rq3GRG31uc0WcWI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 h1:cbsD4cUcviQGXdw8+bo5x2wazq10SKz8hEbtCRPcU78=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0/go.mod h1:JgXSGah17croqhJfhByOLVY719k1emAXC8MVhCIJlRs=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 h1:TVQp/bboR4mhZSav+MdgXB8FaRho1RC8UwVn3T0vjVc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0/go.mod h1:I33vtIe0sR96wfrUcilIzLoA3mLHhRmz9S9Te0S3gDo=
go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo=
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0 h1:iqjq9LAB8aK++sKVcELezzn655JnBNdsDhghU4G/So8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0/go.mod h1:hGXzO5bhhSHZnKvrDaXB82Y9DRFour0Nz/KrBh7reWw=
go.opentelemetry.io/otel/metric v1.17.0 h1:iG6LGVz5Gh+IuO0jmgvpTB6YVrCGngi8QGm+pMd8Pdc=
go.opentelemetry.io/otel/metric v1.17.0/go.mod h1:h4skoxdZI17AxwITdmdZjjYJQH5nzijUUjm+wtPph5o=
go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE=
go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4=
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
go.opentelemetry.io/otel/trace v1.17.0 h1:/SWhSRHmDPOImIAetP1QAeMnZYiQXrTy4fMMYOdSKWQ=
go.opentelemetry.io/otel/trace v1.17.0/go.mod h1:I/4vKTgFclIsXRVucpH25X0mpFSczM7aHeaz0ZBLWjY=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw=
go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
Expand Down
71 changes: 47 additions & 24 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,31 +1493,54 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {

o.PluginDirs = append(o.PluginDirs, o.PluginDir)

tracer, err := o.openTracingTracerInstance()
if err != nil {
return err
var otTracer ot.Tracer
if len(o.OpenTracing) > 0 {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// TODO (@lucastt): We should use otelTracer and pass it along to filters and proxy
// in next iterations.
_, otTracer, err = tracing.TryOtelTracerWithBridge(ctx, o.OpenTracing)
if err != nil {
return err
}

if otTracer == nil {
otTracer, err = o.openTracingTracerInstance()
if err != nil {
return err
}
} else {
o.OpenTracingTracer = otTracer
}
} else {
// always have a tracer available, so filter authors can rely on the
// existence of a tracer
otTracer, _ = tracing.LoadTracingPlugin(o.PluginDirs, []string{"noop"})
}

// tee filters override with initialized tracer
o.CustomFilters = append(o.CustomFilters,
// tee()
teefilters.WithOptions(teefilters.Options{
Tracer: tracer,
NoFollow: false,
}),
// teenf()
teefilters.WithOptions(teefilters.Options{
NoFollow: true,
Tracer: tracer,
}),
)
// tee filters override if we have a tracer
if len(o.OpenTracing) > 0 {
o.CustomFilters = append(o.CustomFilters,
// tee()
teefilters.WithOptions(teefilters.Options{
Tracer: otTracer,
NoFollow: false,
}),
// teenf()
teefilters.WithOptions(teefilters.Options{
NoFollow: true,
Tracer: otTracer,
}),
)
}

if o.OAuthTokeninfoURL != "" {
tio := auth.TokeninfoOptions{
URL: o.OAuthTokeninfoURL,
Timeout: o.OAuthTokeninfoTimeout,
MaxIdleConns: o.IdleConnectionsPerHost,
Tracer: tracer,
Tracer: otTracer,
CacheSize: o.OAuthTokeninfoCacheSize,
CacheTTL: o.OAuthTokeninfoCacheTTL,
}
Expand Down Expand Up @@ -1546,17 +1569,17 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
tio := auth.TokenintrospectionOptions{
Timeout: o.OAuthTokenintrospectionTimeout,
MaxIdleConns: o.IdleConnectionsPerHost,
Tracer: tracer,
Tracer: otTracer,
}

who := auth.WebhookOptions{
Timeout: o.WebhookTimeout,
MaxIdleConns: o.IdleConnectionsPerHost,
Tracer: tracer,
Tracer: otTracer,
}

admissionControlFilter := shedder.NewAdmissionControl(shedder.Options{
Tracer: tracer,
Tracer: otTracer,
})
admissionControlSpec, ok := admissionControlFilter.(*shedder.AdmissionControlSpec)
if !ok {
Expand Down Expand Up @@ -1593,7 +1616,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
CookieValidity: o.OIDCCookieValidity,
Timeout: o.OIDCDistributedClaimsTimeout,
MaxIdleConns: o.IdleConnectionsPerHost,
Tracer: tracer,
Tracer: otTracer,
}

o.CustomFilters = append(o.CustomFilters,
Expand Down Expand Up @@ -1622,7 +1645,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
MaxIdleConns: o.SwarmRedisMaxIdleConns,
ConnMetricsInterval: o.SwarmRedisConnMetricsInterval,
UpdateInterval: o.SwarmRedisUpdateInterval,
Tracer: tracer,
Tracer: otTracer,
Log: log.New(),
}
} else {
Expand Down Expand Up @@ -1762,7 +1785,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
oauthConfig.Insecure = o.OAuth2GrantInsecure
oauthConfig.ConnectionTimeout = o.OAuthTokeninfoTimeout
oauthConfig.MaxIdleConnectionsPerHost = o.IdleConnectionsPerHost
oauthConfig.Tracer = tracer
oauthConfig.Tracer = otTracer

if err := oauthConfig.Init(); err != nil {
log.Errorf("Failed to initialize oauth grant filter: %v.", err)
Expand Down Expand Up @@ -2006,7 +2029,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
}

proxyParams.OpenTracing = &proxy.OpenTracingParams{
Tracer: tracer,
Tracer: otTracer,
InitialSpan: o.OpenTracingInitialSpan,
ExcludeTags: o.OpenTracingExcludedProxyTags,
DisableFilterSpans: o.OpenTracingDisableFilterSpans,
Expand Down
Loading

0 comments on commit fbf33d5

Please sign in to comment.