Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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,
})...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]+}"),
)

Expand All @@ -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}"),
)
}
Expand Down Expand Up @@ -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())

Expand Down
Loading