dependencies: update otel-go dependencies
This commit is contained in:
committed by
David Ashpole
parent
7ee2af5cc5
commit
dc334b953d
@@ -15,14 +15,18 @@
|
||||
package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
oteltrace "go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// config is used to configure the go-restful middleware.
|
||||
type config struct {
|
||||
TracerProvider oteltrace.TracerProvider
|
||||
Propagators propagation.TextMapPropagator
|
||||
TracerProvider oteltrace.TracerProvider
|
||||
Propagators propagation.TextMapPropagator
|
||||
PublicEndpoint bool
|
||||
PublicEndpointFn func(*http.Request) bool
|
||||
}
|
||||
|
||||
// Option applies a configuration value.
|
||||
@@ -36,6 +40,15 @@ func (o optionFunc) apply(c *config) {
|
||||
o(c)
|
||||
}
|
||||
|
||||
// WithPublicEndpoint configures the Handler to link the span with an incoming
|
||||
// span context. If this option is not provided, then the association is a child
|
||||
// association instead of a link.
|
||||
func WithPublicEndpoint() Option {
|
||||
return optionFunc(func(c *config) {
|
||||
c.PublicEndpoint = true
|
||||
})
|
||||
}
|
||||
|
||||
// WithPropagators specifies propagators to use for extracting
|
||||
// information from the HTTP requests. If none are specified, global
|
||||
// ones will be used.
|
||||
@@ -56,3 +69,14 @@ func WithTracerProvider(provider oteltrace.TracerProvider) Option {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WithPublicEndpointFn runs with every request, and allows conditionnally
|
||||
// configuring the Handler to link the span with an incoming span context. If
|
||||
// this option is not provided or returns false, then the association is a
|
||||
// child association instead of a link.
|
||||
// Note: [WithPublicEndpoint] takes precedence over WithPublicEndpointFn.
|
||||
func WithPublicEndpointFn(fn func(*http.Request) bool) Option {
|
||||
return optionFunc(func(c *config) {
|
||||
c.PublicEndpointFn = fn
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.17.0/httpconv"
|
||||
oteltrace "go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,7 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
}
|
||||
tracer := cfg.TracerProvider.Tracer(
|
||||
tracerName,
|
||||
oteltrace.WithInstrumentationVersion(SemVersion()),
|
||||
oteltrace.WithInstrumentationVersion(Version()),
|
||||
)
|
||||
if cfg.Propagators == nil {
|
||||
cfg.Propagators = otel.GetTextMapPropagator()
|
||||
@@ -51,12 +52,24 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
route := req.SelectedRoutePath()
|
||||
spanName := route
|
||||
|
||||
ctx, span := tracer.Start(ctx, spanName,
|
||||
oteltrace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...),
|
||||
oteltrace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...),
|
||||
oteltrace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(service, route, r)...),
|
||||
opts := []oteltrace.SpanStartOption{
|
||||
oteltrace.WithAttributes(httpconv.ServerRequest(service, r)...),
|
||||
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
|
||||
)
|
||||
}
|
||||
if route != "" {
|
||||
rAttr := semconv.HTTPRoute(route)
|
||||
opts = append(opts, oteltrace.WithAttributes(rAttr))
|
||||
}
|
||||
|
||||
if cfg.PublicEndpoint || (cfg.PublicEndpointFn != nil && cfg.PublicEndpointFn(r.WithContext(ctx))) {
|
||||
opts = append(opts, oteltrace.WithNewRoot())
|
||||
// Linking incoming span context if any for public endpoint.
|
||||
if s := oteltrace.SpanContextFromContext(ctx); s.IsValid() && s.IsRemote() {
|
||||
opts = append(opts, oteltrace.WithLinks(oteltrace.Link{SpanContext: s}))
|
||||
}
|
||||
}
|
||||
|
||||
ctx, span := tracer.Start(ctx, spanName, opts...)
|
||||
defer span.End()
|
||||
|
||||
// pass the span through the request context
|
||||
@@ -64,9 +77,10 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
|
||||
chain.ProcessFilter(req, resp)
|
||||
|
||||
attrs := semconv.HTTPAttributesFromHTTPStatusCode(resp.StatusCode())
|
||||
spanStatus, spanMessage := semconv.SpanStatusFromHTTPStatusCodeAndSpanKind(resp.StatusCode(), oteltrace.SpanKindServer)
|
||||
span.SetAttributes(attrs...)
|
||||
span.SetStatus(spanStatus, spanMessage)
|
||||
status := resp.StatusCode()
|
||||
span.SetStatus(httpconv.ServerStatus(status))
|
||||
if status > 0 {
|
||||
span.SetAttributes(semconv.HTTPStatusCode(status))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,13 @@ package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/githu
|
||||
|
||||
// Version is the current release version of the go-restful instrumentation.
|
||||
func Version() string {
|
||||
return "0.35.0"
|
||||
return "0.42.0"
|
||||
// This string is updated by the pre_release.sh script during release
|
||||
}
|
||||
|
||||
// SemVersion is the semantic version to be supplied to tracer/meter creation.
|
||||
//
|
||||
// Deprecated: Use [Version] instead.
|
||||
func SemVersion() string {
|
||||
return "semver:" + Version()
|
||||
return Version()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user