Skip to content

Commit

Permalink
api/standard package has moved to semconv
Browse files Browse the repository at this point in the history
  • Loading branch information
Aneurysm9 committed Aug 4, 2020
1 parent 91d579f commit eceaa35
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions instrumentation/net/http/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.opentelemetry.io v0.1.0 h1:EANZoRCOP+A3faIlw/iN6YEWoYb1vleZRKm1EvH8T48=
go.opentelemetry.io/otel v0.10.0 h1:2y/HYj1dIfG1nPh0Z15X4se8WwYWuTyKHLSgRb/mbQ0=
go.opentelemetry.io/otel v0.10.0/go.mod h1:n3v1JGUBpn5DafiF1UeoDs5fr5XZMG+43kigDtFB8Vk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
16 changes: 8 additions & 8 deletions instrumentation/net/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/semconv"
)

var _ http.Handler = &Handler{}
Expand Down Expand Up @@ -125,9 +125,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

opts := append([]trace.StartOption{
trace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", r)...),
trace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(r)...),
trace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(h.operation, "", r)...),
trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...),
trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...),
trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(h.operation, "", r)...),
}, h.spanStartOptions...) // start with the configured options

ctx := propagation.ExtractHTTP(r.Context(), h.propagators, r.Header)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// Add request metrics

labels := standard.HTTPServerMetricAttributesFromHTTPRequest(h.operation, r)
labels := semconv.HTTPServerMetricAttributesFromHTTPRequest(h.operation, r)

h.counters[RequestContentLength].Add(ctx, bw.read, labels...)
h.counters[ResponseContentLength].Add(ctx, rww.written, labels...)
Expand All @@ -183,8 +183,8 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int,
kv = append(kv, WroteBytesKey.Int64(wrote))
}
if statusCode > 0 {
kv = append(kv, standard.HTTPAttributesFromHTTPStatusCode(statusCode)...)
span.SetStatus(standard.SpanStatusFromHTTPStatusCode(statusCode))
kv = append(kv, semconv.HTTPAttributesFromHTTPStatusCode(statusCode)...)
span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(statusCode))
}
if werr != nil && werr != io.EOF {
kv = append(kv, WriteErrorKey.String(werr.Error()))
Expand All @@ -197,7 +197,7 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int,
func WithRouteTag(route string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
span := trace.SpanFromContext(r.Context())
span.SetAttributes(standard.HTTPRouteKey.String(route))
span.SetAttributes(semconv.HTTPRouteKey.String(route))
h.ServeHTTP(w, r)
})
}
12 changes: 6 additions & 6 deletions instrumentation/net/http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"google.golang.org/grpc/codes"

"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/standard"
"go.opentelemetry.io/otel/api/semconv"
"go.opentelemetry.io/otel/api/trace"

mockmeter "go.opentelemetry.io/contrib/internal/metric"
Expand Down Expand Up @@ -68,11 +68,11 @@ func TestHandlerBasics(t *testing.T) {
}

labelsToVerify := []kv.KeyValue{
standard.HTTPServerNameKey.String(operation),
standard.HTTPSchemeHTTP,
standard.HTTPHostKey.String(r.Host),
standard.HTTPFlavorKey.String(fmt.Sprintf("1.%d", r.ProtoMinor)),
standard.HTTPRequestContentLengthKey.Int64(3),
semconv.HTTPServerNameKey.String(operation),
semconv.HTTPSchemeHTTP,
semconv.HTTPHostKey.String(r.Host),
semconv.HTTPFlavorKey.String(fmt.Sprintf("1.%d", r.ProtoMinor)),
semconv.HTTPRequestContentLengthKey.Int64(3),
}

assertMetricLabels(t, labelsToVerify, meterimpl.MeasurementBatches)
Expand Down
8 changes: 4 additions & 4 deletions instrumentation/net/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
"go.opentelemetry.io/otel/api/semconv"
"go.opentelemetry.io/otel/api/trace"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -89,7 +89,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
ctx, span := t.tracer.Start(r.Context(), t.spanNameFormatter("", r), opts...)

r = r.WithContext(ctx)
span.SetAttributes(standard.HTTPClientAttributesFromHTTPRequest(r)...)
span.SetAttributes(semconv.HTTPClientAttributesFromHTTPRequest(r)...)
propagation.InjectHTTP(ctx, t.propagators, r.Header)

res, err := t.rt.RoundTrip(r)
Expand All @@ -99,8 +99,8 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
return res, err
}

span.SetAttributes(standard.HTTPAttributesFromHTTPStatusCode(res.StatusCode)...)
span.SetStatus(standard.SpanStatusFromHTTPStatusCode(res.StatusCode))
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(res.StatusCode)...)
span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(res.StatusCode))
res.Body = &wrappedBody{ctx: ctx, span: span, body: res.Body}

return res, err
Expand Down

0 comments on commit eceaa35

Please sign in to comment.