Skip to content

Commit

Permalink
fix: traceability of the middleware plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Jul 20, 2023
1 parent 7792d19 commit 47faae2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/server/middleware/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (
}

middleware = func(next http.Handler) (http.Handler, error) {
return plug(ctx, next)
return newTraceablePlugin(ctx, middlewareName, plug, next)
}
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/server/middleware/plugins.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package middleware

import (
"context"
"errors"
"net/http"

"github.com/opentracing/opentracing-go/ext"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/plugins"
"github.com/traefik/traefik/v2/pkg/tracing"
)

// PluginsBuilder the plugin's builder interface.
Expand All @@ -31,3 +35,25 @@ func findPluginConfig(rawConfig map[string]dynamic.PluginConf) (string, map[stri

return pluginType, rawPluginConfig, nil
}

type traceablePlugin struct {
name string
h http.Handler
}

func newTraceablePlugin(ctx context.Context, name string, plug plugins.Constructor, next http.Handler) (*traceablePlugin, error) {
h, err := plug(ctx, next)
if err != nil {
return nil, err
}

return &traceablePlugin{name: name, h: h}, nil
}

func (s *traceablePlugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
s.h.ServeHTTP(rw, req)
}

func (s *traceablePlugin) GetTracingInformation() (string, ext.SpanKindEnum) {
return s.name, tracing.SpanKindNoneEnum
}

0 comments on commit 47faae2

Please sign in to comment.