Skip to content

Commit

Permalink
Merge pull request #7 from swisscom/feature/upgrade-to-otel-1.13
Browse files Browse the repository at this point in the history
feat: upgrade otel to v1.13
  • Loading branch information
zstone12 authored Feb 14, 2023
2 parents 4e950b1 + 9ede9cc commit 941cd3e
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 268 deletions.
42 changes: 21 additions & 21 deletions examples/metric/metrics/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ module github.com/uptrace/opentelemetry-go-extra/example/prometheus/metrics
go 1.17

require (
go.opentelemetry.io/contrib/instrumentation/runtime v0.33.0
go.opentelemetry.io/otel v1.8.0
go.opentelemetry.io/otel/exporters/jaeger v1.8.0
go.opentelemetry.io/otel/exporters/prometheus v0.30.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.7.0
go.opentelemetry.io/otel/metric v0.31.0
go.opentelemetry.io/otel/sdk v1.8.0
go.opentelemetry.io/otel/sdk/metric v0.31.0
go.opentelemetry.io/otel/trace v1.8.0
gorm.io/driver/sqlite v1.3.6
gorm.io/gorm v1.23.8
go.opentelemetry.io/contrib/instrumentation/runtime v0.39.0
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/exporters/jaeger v1.13.0
go.opentelemetry.io/otel/exporters/prometheus v0.36.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.13.0
go.opentelemetry.io/otel/metric v0.36.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/trace v1.13.0
gorm.io/driver/sqlite v1.4.4
gorm.io/gorm v1.24.5
gorm.io/plugin/opentelemetry v0.0.0-00010101000000-000000000000
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
google.golang.org/protobuf v1.28.0 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.36.0 // indirect
golang.org/x/sys v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)

replace gorm.io/plugin/opentelemetry => ./../../..
767 changes: 722 additions & 45 deletions examples/metric/metrics/go.sum

Large diffs are not rendered by default.

38 changes: 13 additions & 25 deletions examples/metric/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import (
"os"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/metric"

runtimemetrics "go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
selector "go.opentelemetry.io/otel/sdk/metric/selector/simple"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
"gorm.io/driver/sqlite"
Expand Down Expand Up @@ -90,13 +88,13 @@ func TraceURL(span trace.Span) string {
}

func configureOpentelemetry() {
exporter := configureMetrics()
configureMetrics()

if err := runtimemetrics.Start(); err != nil {
panic(err)
}

http.HandleFunc("/metrics", exporter.ServeHTTP)
http.Handle("/metrics", promhttp.Handler())
fmt.Println("listenening on http://localhost:8088/metrics")

go func() {
Expand All @@ -105,24 +103,14 @@ func configureOpentelemetry() {
}

func configureMetrics() *prometheus.Exporter {
config := prometheus.Config{}

ctrl := controller.New(
processor.NewFactory(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
aggregation.CumulativeTemporalitySelector(),
processor.WithMemory(true),
),
)

exporter, err := prometheus.New(config, ctrl)
exporter, err := prometheus.New()
if err != nil {
panic(err)
}

global.SetMeterProvider(exporter.MeterProvider())
provider := metric.NewMeterProvider(
metric.WithReader(exporter),
)
global.SetMeterProvider(provider)

return exporter
}
Expand All @@ -134,7 +122,7 @@ func main() {
configureOpentelemetry()
defer shutdown()

logger := logger.New(
l := logger.New(
logrus.NewWriter(),
logger.Config{
SlowThreshold: time.Millisecond,
Expand All @@ -143,7 +131,7 @@ func main() {
},
)

db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{Logger: logger})
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{Logger: l})
if err != nil {
panic(err)
}
Expand Down
58 changes: 28 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ go 1.18

require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.33.0
go.opentelemetry.io/contrib/propagators/b3 v1.8.0
go.opentelemetry.io/contrib/propagators/jaeger v1.8.0
go.opentelemetry.io/contrib/propagators/opencensus v0.33.0
go.opentelemetry.io/contrib/propagators/ot v1.8.0
go.opentelemetry.io/otel v1.8.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.7.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.7.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.7.0
go.opentelemetry.io/otel/metric v0.31.0
go.opentelemetry.io/otel/sdk v1.8.0
go.opentelemetry.io/otel/sdk/metric v0.31.0
go.opentelemetry.io/otel/trace v1.8.0
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0
go.opentelemetry.io/contrib/propagators/b3 v1.13.0
go.opentelemetry.io/contrib/propagators/jaeger v1.13.0
go.opentelemetry.io/contrib/propagators/opencensus v0.39.0
go.opentelemetry.io/contrib/propagators/ot v1.13.0
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.36.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.13.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.13.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.13.0
go.opentelemetry.io/otel/metric v0.36.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/sdk/metric v0.36.0
go.opentelemetry.io/otel/trace v1.13.0
gorm.io/driver/sqlite v1.3.2
gorm.io/gorm v1.23.5
)

require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -35,20 +34,19 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.22.6-0.20201102222123-380f4078db9f // indirect
go.opentelemetry.io/otel/bridge/opencensus v0.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.8.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/bridge/opencensus v0.36.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.36.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect
google.golang.org/grpc v1.46.2 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/grpc v1.52.3 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 941cd3e

Please sign in to comment.