Skip to content

Commit

Permalink
Use trace convention helpers from main otel-go repo (#112)
Browse files Browse the repository at this point in the history
* prepare for release_v0.7.0

* Upgrade metric exporter code to otel-v0.7.0 API

* Remove internal trace standard helpers in favor of api/standard from otel-go

* fixup go.mod

Co-authored-by: Evan Torrie <evantorrie@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 29, 2020
1 parent 9890acb commit 99b417a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1,078 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module go.opentelemetry.io/contrib
go 1.14

require (
github.com/stretchr/testify v1.6.1
go.opentelemetry.io/otel v0.7.0
google.golang.org/grpc v1.30.0
)
12 changes: 6 additions & 6 deletions instrumentation/gin-gonic/gin/gintrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/gin-gonic/gin"
"google.golang.org/grpc/codes"

"go.opentelemetry.io/contrib/internal/trace"
otelglobal "go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
oteltrace "go.opentelemetry.io/otel/api/trace"
)

Expand Down Expand Up @@ -56,9 +56,9 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
}()
ctx := otelpropagation.ExtractHTTP(savedCtx, cfg.Propagators, c.Request.Header)
opts := []oteltrace.StartOption{
oteltrace.WithAttributes(trace.NetAttributesFromHTTPRequest("tcp", c.Request)...),
oteltrace.WithAttributes(trace.EndUserAttributesFromHTTPRequest(c.Request)...),
oteltrace.WithAttributes(trace.HTTPServerAttributesFromHTTPRequest(service, c.FullPath(), c.Request)...),
oteltrace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", c.Request)...),
oteltrace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(c.Request)...),
oteltrace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(service, c.FullPath(), c.Request)...),
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
}
spanName := c.FullPath()
Expand All @@ -75,8 +75,8 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
c.Next()

status := c.Writer.Status()
attrs := trace.HTTPAttributesFromHTTPStatusCode(status)
spanStatus, spanMessage := trace.SpanStatusFromHTTPStatusCode(status)
attrs := standard.HTTPAttributesFromHTTPStatusCode(status)
spanStatus, spanMessage := standard.SpanStatusFromHTTPStatusCode(status)
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)
if len(c.Errors) > 0 {
Expand Down
12 changes: 6 additions & 6 deletions instrumentation/gopkg.in/macaron.v1/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (

"gopkg.in/macaron.v1"

"go.opentelemetry.io/contrib/internal/trace"
otelglobal "go.opentelemetry.io/otel/api/global"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
oteltrace "go.opentelemetry.io/otel/api/trace"
)

Expand Down Expand Up @@ -50,9 +50,9 @@ func Middleware(service string, opts ...Option) macaron.Handler {

ctx := otelpropagation.ExtractHTTP(savedCtx, cfg.Propagators, c.Req.Header)
opts := []oteltrace.StartOption{
oteltrace.WithAttributes(trace.NetAttributesFromHTTPRequest("tcp", c.Req.Request)...),
oteltrace.WithAttributes(trace.EndUserAttributesFromHTTPRequest(c.Req.Request)...),
oteltrace.WithAttributes(trace.HTTPServerAttributesFromHTTPRequest(service, "", c.Req.Request)...),
oteltrace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", c.Req.Request)...),
oteltrace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(c.Req.Request)...),
oteltrace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(service, "", c.Req.Request)...),
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
}
// TODO: span name should be router template not the actual request path, eg /user/:id vs /user/123
Expand All @@ -70,8 +70,8 @@ func Middleware(service string, opts ...Option) macaron.Handler {
c.Next()

status := c.Resp.Status()
attrs := trace.HTTPAttributesFromHTTPStatusCode(status)
spanStatus, spanMessage := trace.SpanStatusFromHTTPStatusCode(status)
attrs := standard.HTTPAttributesFromHTTPStatusCode(status)
spanStatus, spanMessage := standard.SpanStatusFromHTTPStatusCode(status)
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)
}
Expand Down
12 changes: 6 additions & 6 deletions instrumentation/gorilla/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

"github.com/gorilla/mux"

"go.opentelemetry.io/contrib/internal/trace"
otelglobal "go.opentelemetry.io/otel/api/global"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
oteltrace "go.opentelemetry.io/otel/api/trace"
)

Expand Down Expand Up @@ -129,9 +129,9 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
spanName = fmt.Sprintf("HTTP %s route not found", r.Method)
}
opts := []oteltrace.StartOption{
oteltrace.WithAttributes(trace.NetAttributesFromHTTPRequest("tcp", r)...),
oteltrace.WithAttributes(trace.EndUserAttributesFromHTTPRequest(r)...),
oteltrace.WithAttributes(trace.HTTPServerAttributesFromHTTPRequest(tw.service, routeStr, r)...),
oteltrace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", r)...),
oteltrace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(r)...),
oteltrace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(tw.service, routeStr, r)...),
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
}
ctx, span := tw.tracer.Start(ctx, spanName, opts...)
Expand All @@ -140,8 +140,8 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rrw := getRRW(w)
defer putRRW(rrw)
tw.handler.ServeHTTP(rrw, r2)
attrs := trace.HTTPAttributesFromHTTPStatusCode(rrw.status)
spanStatus, spanMessage := trace.SpanStatusFromHTTPStatusCode(rrw.status)
attrs := standard.HTTPAttributesFromHTTPStatusCode(rrw.status)
spanStatus, spanMessage := standard.SpanStatusFromHTTPStatusCode(rrw.status)
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)
}
12 changes: 6 additions & 6 deletions instrumentation/labstack/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

"github.com/labstack/echo/v4"

"go.opentelemetry.io/contrib/internal/trace"
otelglobal "go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/standard"
oteltrace "go.opentelemetry.io/otel/api/trace"
)

Expand Down Expand Up @@ -54,9 +54,9 @@ func Middleware(service string, opts ...Option) echo.MiddlewareFunc {
}()
ctx := otelpropagation.ExtractHTTP(savedCtx, cfg.Propagators, request.Header)
opts := []oteltrace.StartOption{
oteltrace.WithAttributes(trace.NetAttributesFromHTTPRequest("tcp", request)...),
oteltrace.WithAttributes(trace.EndUserAttributesFromHTTPRequest(request)...),
oteltrace.WithAttributes(trace.HTTPServerAttributesFromHTTPRequest(service, c.Path(), request)...),
oteltrace.WithAttributes(standard.NetAttributesFromHTTPRequest("tcp", request)...),
oteltrace.WithAttributes(standard.EndUserAttributesFromHTTPRequest(request)...),
oteltrace.WithAttributes(standard.HTTPServerAttributesFromHTTPRequest(service, c.Path(), request)...),
oteltrace.WithSpanKind(oteltrace.SpanKindServer),
}
spanName := c.Path()
Expand All @@ -78,8 +78,8 @@ func Middleware(service string, opts ...Option) echo.MiddlewareFunc {
c.Error(err)
}

attrs := trace.HTTPAttributesFromHTTPStatusCode(c.Response().Status)
spanStatus, spanMessage := trace.SpanStatusFromHTTPStatusCode(c.Response().Status)
attrs := standard.HTTPAttributesFromHTTPStatusCode(c.Response().Status)
spanStatus, spanMessage := standard.SpanStatusFromHTTPStatusCode(c.Response().Status)
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)

Expand Down
Loading

0 comments on commit 99b417a

Please sign in to comment.