Skip to content

Commit

Permalink
Add sem version to remaining instrumentation packages (#412)
Browse files Browse the repository at this point in the history
* Add top-level sem version for remaining instrumentations

Includes:
- instrumentation/github.com/Shopify/sarama/otelsarama
- instrumentation/github.com/emicklei/go-restful/otelrestful
- instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo
- instrumentation/net/http/otelhttp
- instrumentation/net/http/httptrace/otelhttptrace

* Update instrumentation README

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
matej-g and MrAlias authored Oct 27, 2020
1 parent 4a5c934 commit a0dc004
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- `otelhttp.{Get,Head,Post,PostForm}` convenience wrappers for their `http` counterparts. (#390)

### Changed

- Add semantic version to `Tracer` / `Meter` created by instrumentation packages `otelsaram`, `otelrestful`, `otelmongo`, `otelhttp` and `otelhttptrace`. (#412)
- Update instrumentation guidelines about tracer / meter semantic version. (#412)

## Fixed

- `/detectors/aws` no longer fails if instance metadata is not available (e.g. not running in AWS) (#401)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ Additionally the following guidelines for package composition need to be followe
Also, packages MUST use the default `TracerProvider`, `MeterProvider`, and `Propagators` supplied by the `global` package if no optional one is provided.
- All instrumentation packages MUST NOT provide an option to accept a `Tracer` or `Meter`.
- All instrumentation packages MUST create any used `Tracer` or `Meter` with a name matching the instrumentation package name.
- All instrumentation packages MUST create any used `Tracer` or `Meter` with a semantic version corresponding to the the version of this repository.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package otelsarama

import (
"go.opentelemetry.io/contrib"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
Expand Down Expand Up @@ -44,7 +45,10 @@ func newConfig(opts ...Option) config {
opt(&cfg)
}

cfg.Tracer = cfg.TracerProvider.Tracer(defaultTracerName)
cfg.Tracer = cfg.TracerProvider.Tracer(
defaultTracerName,
trace.WithInstrumentationVersion(contrib.SemVersion()),
)

return cfg
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/contrib"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
)

func TestNewConfig(t *testing.T) {
Expand All @@ -35,7 +37,7 @@ func TestNewConfig(t *testing.T) {
},
expected: config{
TracerProvider: global.TracerProvider(),
Tracer: global.TracerProvider().Tracer(defaultTracerName),
Tracer: global.TracerProvider().Tracer(defaultTracerName, trace.WithInstrumentationVersion(contrib.SemVersion())),
Propagators: global.TextMapPropagator(),
},
},
Expand All @@ -46,7 +48,7 @@ func TestNewConfig(t *testing.T) {
},
expected: config{
TracerProvider: global.TracerProvider(),
Tracer: global.TracerProvider().Tracer(defaultTracerName),
Tracer: global.TracerProvider().Tracer(defaultTracerName, trace.WithInstrumentationVersion(contrib.SemVersion())),
Propagators: nil,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ package otelrestful
import (
"github.com/emicklei/go-restful/v3"

"go.opentelemetry.io/contrib"
otelglobal "go.opentelemetry.io/otel/api/global"
oteltrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/semconv"
)

const (
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
tracerVersion = "1.0"
)
const tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"

// OTelFilter returns a restful.FilterFunction which will trace an incoming request.
//
Expand All @@ -40,7 +38,10 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
if cfg.TracerProvider == nil {
cfg.TracerProvider = otelglobal.TracerProvider()
}
tracer := cfg.TracerProvider.Tracer(tracerName, oteltrace.WithInstrumentationVersion(tracerVersion))
tracer := cfg.TracerProvider.Tracer(
tracerName,
oteltrace.WithInstrumentationVersion(contrib.SemVersion()),
)
if cfg.Propagators == nil {
cfg.Propagators = otelglobal.TextMapPropagator()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
package otelmongo

import (
"go.opentelemetry.io/contrib"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
)

const (
defaultTracerName = "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)
const defaultTracerName = "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"

// config is used to configure the mongo tracer.
type config struct {
Expand All @@ -39,7 +38,10 @@ func newConfig(opts ...Option) config {
opt(&cfg)
}

cfg.Tracer = cfg.TracerProvider.Tracer(defaultTracerName)
cfg.Tracer = cfg.TracerProvider.Tracer(
defaultTracerName,
trace.WithInstrumentationVersion(contrib.SemVersion()),
)
return cfg
}

Expand Down
12 changes: 7 additions & 5 deletions instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (
"strings"
"sync"

"go.opentelemetry.io/otel/semconv"

"go.opentelemetry.io/otel/codes"

"go.opentelemetry.io/contrib"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/semconv"
)

var (
Expand Down Expand Up @@ -69,7 +68,10 @@ func NewClientTrace(ctx context.Context) *httptrace.ClientTrace {
activeHooks: make(map[string]context.Context),
}

ct.tr = global.Tracer("go.opentelemetry.io/otel/instrumentation/httptrace")
ct.tr = global.TracerProvider().Tracer(
"go.opentelemetry.io/otel/instrumentation/httptrace",
trace.WithInstrumentationVersion(contrib.SemVersion()),
)

return &httptrace.ClientTrace{
GetConn: ct.getConn,
Expand Down
1 change: 1 addition & 0 deletions instrumentation/net/http/httptrace/otelhttptrace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ go 1.14
require (
github.com/google/go-cmp v0.5.2
github.com/stretchr/testify v1.6.1
go.opentelemetry.io/contrib v0.13.0
go.opentelemetry.io/otel v0.13.0
)
11 changes: 11 additions & 0 deletions instrumentation/net/http/httptrace/otelhttptrace/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/contrib v0.13.0 h1:q34CFu5REx9Dt2ksESHC/doIjFJkEg1oV3aSwlL5JR0=
go.opentelemetry.io/contrib v0.13.0/go.mod h1:HzCu6ebm0ywgNxGaEfs3izyJOMP4rZnzxycyTgpI5Sg=
go.opentelemetry.io/otel v0.13.0 h1:2isEnyzjjJZq6r2EKMsFj4TxiQiexsM04AVhwbR/oBA=
go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11 changes: 9 additions & 2 deletions instrumentation/net/http/otelhttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package otelhttp
import (
"net/http"

"go.opentelemetry.io/contrib"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/metric"
Expand Down Expand Up @@ -67,8 +68,14 @@ func newConfig(opts ...Option) *config {
opt.Apply(c)
}

c.Tracer = c.TracerProvider.Tracer(instrumentationName)
c.Meter = c.MeterProvider.Meter(instrumentationName)
c.Tracer = c.TracerProvider.Tracer(
instrumentationName,
trace.WithInstrumentationVersion(contrib.SemVersion()),
)
c.Meter = c.MeterProvider.Meter(
instrumentationName,
metric.WithInstrumentationVersion(contrib.SemVersion()),
)

return c
}
Expand Down

0 comments on commit a0dc004

Please sign in to comment.