diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go index 3c8d911d70a..c13e81002e0 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go @@ -6,12 +6,10 @@ package otelrestful // import "go.opentelemetry.io/contrib/instrumentation/githu import ( "github.com/emicklei/go-restful/v3" + "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" oteltrace "go.opentelemetry.io/otel/trace" - - "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv" - "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil" ) // ScopeName is the instrumentation scope name. @@ -46,7 +44,7 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction { spanName := route opts := []oteltrace.SpanStartOption{ - oteltrace.WithAttributes(semconvutil.HTTPServerRequest(service, r, semconvutil.HTTPServerRequestOptions{}, nil)...), + oteltrace.WithAttributes(semconvServer.RequestTraceAttrs(service, r, semconv.RequestTraceAttrsOpts{})...), oteltrace.WithSpanKind(oteltrace.SpanKindServer), } if route != "" { @@ -71,9 +69,9 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction { chain.ProcessFilter(req, resp) status := resp.StatusCode() - span.SetStatus(semconvutil.HTTPServerStatus(status)) - if status > 0 { - span.SetAttributes(semconv.HTTPStatusCode(status)) - } + span.SetStatus(semconvServer.Status(status)) + span.SetAttributes(semconvServer.ResponseTraceAttrs(semconv.ResponseTelemetry{ + StatusCode: status, + })...) } } diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/test/restful_test.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/test/restful_test.go index 4c0845086e5..eab2c737ed3 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/test/restful_test.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/test/restful_test.go @@ -95,9 +95,9 @@ func TestChildSpanNames(t *testing.T) { t, spans[0], "/user/{id:[0-9]+}", - attribute.String("net.host.name", "foobar"), - attribute.Int("http.status_code", http.StatusOK), - attribute.String("http.method", "GET"), + attribute.String("server.address", "foobar"), + attribute.Int("http.response.status_code", http.StatusOK), + attribute.String("http.request.method", "GET"), attribute.String("http.route", "/user/{id:[0-9]+}"), ) @@ -110,9 +110,9 @@ func TestChildSpanNames(t *testing.T) { t, spans[1], "/book/{title}", - attribute.String("net.host.name", "foobar"), - attribute.Int("http.status_code", http.StatusOK), - attribute.String("http.method", "GET"), + attribute.String("server.address", "foobar"), + attribute.Int("http.response.status_code", http.StatusOK), + attribute.String("http.request.method", "GET"), attribute.String("http.route", "/book/{title}"), ) } @@ -336,6 +336,8 @@ func TestWithPublicEndpointFn(t *testing.T) { } func assertSpan(t *testing.T, span sdktrace.ReadOnlySpan, name string, attrs ...attribute.KeyValue) { + t.Helper() + assert.Equal(t, name, span.Name()) assert.Equal(t, oteltrace.SpanKindServer, span.SpanKind())