Otel tracing MVP (#4188)

This commit is contained in:
Milos Gajdos
2023-12-11 22:08:40 +00:00
committed by GitHub
1070 changed files with 90847 additions and 18622 deletions

View File

@@ -17,6 +17,7 @@ import (
gorhandlers "github.com/gorilla/handlers"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"golang.org/x/crypto/acme"
"golang.org/x/crypto/acme/autocert"
@@ -25,6 +26,7 @@ import (
"github.com/distribution/distribution/v3/internal/dcontext"
"github.com/distribution/distribution/v3/registry/handlers"
"github.com/distribution/distribution/v3/registry/listener"
"github.com/distribution/distribution/v3/tracing"
"github.com/distribution/distribution/v3/version"
)
@@ -152,6 +154,12 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
handler = applyHandlerMiddleware(config, handler)
}
err = tracing.InitOpenTelemetry(app.Context)
if err != nil {
return nil, fmt.Errorf("error during open telemetry initialization: %v", err)
}
handler = otelHandler(handler)
server := &http.Server{
Handler: handler,
}
@@ -163,6 +171,13 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
}, nil
}
// otelHandler returns an http.Handler that wraps the provided `next` handler with OpenTelemetry instrumentation.
// This instrumentation tracks each HTTP request, creating spans with names derived from the request method and URL path.
func otelHandler(next http.Handler) http.Handler {
return otelhttp.NewHandler(next, "",
otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string { return r.Method + " " + r.URL.Path }))
}
// takes a list of cipher suites and converts it to a list of respective tls constants
// if an empty list is provided, then the defaults will be used
func getCipherSuites(names []string) ([]uint16, error) {