updated etcd to v3.5.5 and newer otel libraries as well
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelrestful
|
||||
package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
@@ -25,22 +25,34 @@ type config struct {
|
||||
Propagators propagation.TextMapPropagator
|
||||
}
|
||||
|
||||
// Option specifies instrumentation configuration options.
|
||||
type Option func(*config)
|
||||
// Option applies a configuration value.
|
||||
type Option interface {
|
||||
apply(*config)
|
||||
}
|
||||
|
||||
type optionFunc func(*config)
|
||||
|
||||
func (o optionFunc) apply(c *config) {
|
||||
o(c)
|
||||
}
|
||||
|
||||
// WithPropagators specifies propagators to use for extracting
|
||||
// information from the HTTP requests. If none are specified, global
|
||||
// ones will be used.
|
||||
func WithPropagators(propagators propagation.TextMapPropagator) Option {
|
||||
return func(cfg *config) {
|
||||
cfg.Propagators = propagators
|
||||
}
|
||||
return optionFunc(func(cfg *config) {
|
||||
if propagators != nil {
|
||||
cfg.Propagators = propagators
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
|
||||
// If none is specified, the global provider is used.
|
||||
func WithTracerProvider(provider oteltrace.TracerProvider) Option {
|
||||
return func(cfg *config) {
|
||||
cfg.TracerProvider = provider
|
||||
}
|
||||
return optionFunc(func(cfg *config) {
|
||||
if provider != nil {
|
||||
cfg.TracerProvider = provider
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//
|
||||
// Instrumentation of an incoming request is achieved via a go-restful
|
||||
// FilterFunc called `OTelFilterFunc` which may be applied at any one of
|
||||
// * the container level
|
||||
// * webservice level
|
||||
// * route level
|
||||
// - the container level
|
||||
// - webservice level
|
||||
// - route level
|
||||
package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
|
||||
|
||||
@@ -12,15 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelrestful
|
||||
package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
|
||||
"go.opentelemetry.io/contrib"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/semconv"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
|
||||
oteltrace "go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@@ -34,14 +33,14 @@ const tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emick
|
||||
func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
cfg := config{}
|
||||
for _, opt := range opts {
|
||||
opt(&cfg)
|
||||
opt.apply(&cfg)
|
||||
}
|
||||
if cfg.TracerProvider == nil {
|
||||
cfg.TracerProvider = otel.GetTracerProvider()
|
||||
}
|
||||
tracer := cfg.TracerProvider.Tracer(
|
||||
tracerName,
|
||||
oteltrace.WithInstrumentationVersion(contrib.SemVersion()),
|
||||
oteltrace.WithInstrumentationVersion(SemVersion()),
|
||||
)
|
||||
if cfg.Propagators == nil {
|
||||
cfg.Propagators = otel.GetTextMapPropagator()
|
||||
@@ -52,13 +51,12 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
route := req.SelectedRoutePath()
|
||||
spanName := route
|
||||
|
||||
opts := []oteltrace.SpanOption{
|
||||
ctx, span := tracer.Start(ctx, spanName,
|
||||
oteltrace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...),
|
||||
oteltrace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...),
|
||||
oteltrace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(service, route, r)...),
|
||||
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
|
||||
}
|
||||
ctx, span := tracer.Start(ctx, spanName, opts...)
|
||||
)
|
||||
defer span.End()
|
||||
|
||||
// pass the span through the request context
|
||||
@@ -67,7 +65,7 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
|
||||
chain.ProcessFilter(req, resp)
|
||||
|
||||
attrs := semconv.HTTPAttributesFromHTTPStatusCode(resp.StatusCode())
|
||||
spanStatus, spanMessage := semconv.SpanStatusFromHTTPStatusCode(resp.StatusCode())
|
||||
spanStatus, spanMessage := semconv.SpanStatusFromHTTPStatusCodeAndSpanKind(resp.StatusCode(), oteltrace.SpanKindServer)
|
||||
span.SetAttributes(attrs...)
|
||||
span.SetStatus(spanStatus, spanMessage)
|
||||
}
|
||||
|
||||
26
vendor/go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/version.go
generated
vendored
Normal file
26
vendor/go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/version.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
|
||||
|
||||
// Version is the current release version of the go-restful instrumentation.
|
||||
func Version() string {
|
||||
return "0.35.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.
|
||||
func SemVersion() string {
|
||||
return "semver:" + Version()
|
||||
}
|
||||
Reference in New Issue
Block a user