Skip to content

Commit

Permalink
feat: update otel version (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: rogerogers <rogers@rogerogers.com>
  • Loading branch information
rogerogers authored Feb 21, 2023
1 parent 0fc86f9 commit f719a52
Show file tree
Hide file tree
Showing 10 changed files with 926 additions and 194 deletions.
52 changes: 26 additions & 26 deletions provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ module github.com/hertz-contrib/obs-opentelemetry/provider
go 1.17

require (
github.com/cloudwego/hertz v0.3.0
github.com/stretchr/testify v1.8.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.32.0
go.opentelemetry.io/contrib/propagators/b3 v1.9.0
go.opentelemetry.io/contrib/propagators/ot v1.9.0
go.opentelemetry.io/otel v1.9.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.9.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0
go.opentelemetry.io/otel/metric v0.31.0
go.opentelemetry.io/otel/sdk v1.9.0
go.opentelemetry.io/otel/sdk/metric v0.31.0
github.com/cloudwego/hertz v0.5.2
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/contrib/instrumentation/runtime v0.39.0
go.opentelemetry.io/contrib/propagators/b3 v1.14.0
go.opentelemetry.io/contrib/propagators/ot v1.14.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/metric v0.36.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/sdk/metric v0.36.0
)

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
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
go.opentelemetry.io/otel/trace v1.9.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.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-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe // indirect
golang.org/x/text v0.3.5 // 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
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/otel/trace v1.13.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
817 changes: 750 additions & 67 deletions provider/go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions provider/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/contrib/propagators/ot"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
Expand Down Expand Up @@ -53,6 +54,8 @@ type config struct {
resourceDetectors []resource.Detector

textMapPropagator propagation.TextMapPropagator

meterProvider *metric.MeterProvider
}

func newConfig(opts []Option) *config {
Expand Down Expand Up @@ -192,3 +195,10 @@ func WithSdkTracerProvider(sdkTracerProvider *sdktrace.TracerProvider) Option {
cfg.sdkTracerProvider = sdkTracerProvider
})
}

// WithMeterProvider configures MeterProvider
func WithMeterProvider(meterProvider *metric.MeterProvider) Option {
return option(func(cfg *config) {
cfg.meterProvider = meterProvider
})
}
47 changes: 19 additions & 28 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ package provider

import (
"context"
"time"

"github.com/cloudwego/hertz/pkg/common/hlog"
runtimemetrics "go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/metric/global"
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"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
Expand All @@ -39,7 +36,7 @@ type OtelProvider interface {

type otelProvider struct {
traceExp *otlptrace.Exporter
metricsPusher *controller.Controller
metricsPusher *metric.MeterProvider
}

func (p *otelProvider) Shutdown(ctx context.Context) error {
Expand All @@ -52,7 +49,7 @@ func (p *otelProvider) Shutdown(ctx context.Context) error {
}

if p.metricsPusher != nil {
if err = p.metricsPusher.Stop(ctx); err != nil {
if err = p.metricsPusher.Shutdown(ctx); err != nil {
otel.Handle(err)
}
}
Expand All @@ -61,11 +58,11 @@ func (p *otelProvider) Shutdown(ctx context.Context) error {
}

// NewOpenTelemetryProvider Initializes an otlp trace and metrics provider
func NewOpenTelemetryProvider(opts ...Option) *otelProvider {
func NewOpenTelemetryProvider(opts ...Option) OtelProvider {
var (
err error
traceExp *otlptrace.Exporter
metricsPusher *controller.Controller
meterProvider *metric.MeterProvider
)

ctx := context.TODO()
Expand Down Expand Up @@ -127,7 +124,6 @@ func NewOpenTelemetryProvider(opts ...Option) *otelProvider {
// Metrics
if cfg.enableMetrics {
// prometheus only supports CumulativeTemporalitySelector
exportKindSelector := aggregation.CumulativeTemporalitySelector()

var metricsClientOpts []otlpmetricgrpc.Option
if cfg.exportEndpoint != "" {
Expand All @@ -143,34 +139,29 @@ func NewOpenTelemetryProvider(opts ...Option) *otelProvider {
metricsClientOpts = append(metricsClientOpts, otlpmetricgrpc.WithCompressor("gzip"))
}

// metrics client
metricClient := otlpmetricgrpc.NewClient(metricsClientOpts...)
meterProvider = cfg.meterProvider
if meterProvider == nil {
// metrics exporter
metricExp, err := otlpmetricgrpc.New(context.Background(), metricsClientOpts...)

// metrics exporter
metricExp, err := otlpmetric.New(ctx, metricClient, otlpmetric.WithMetricAggregationTemporalitySelector(exportKindSelector))
handleInitErr(err, "Failed to create the collector metric exporter")
handleInitErr(err, "Failed to create the metric exporter")

// reader := metric.NewPeriodicReader(exporter)
reader := metric.WithReader(metric.NewPeriodicReader(metricExp, metric.WithInterval(15*time.Second)))

meterProvider = metric.NewMeterProvider(reader, metric.WithResource(res))
}

// metrics pusher
pusher := controller.New(
processor.NewFactory(
simple.NewWithHistogramDistribution(),
metricExp,
),
controller.WithResource(res),
controller.WithExporter(metricExp),
)
global.SetMeterProvider(pusher)

err = pusher.Start(ctx)
handleInitErr(err, "Failed to start metrics pusher")
global.SetMeterProvider(meterProvider)

err = runtimemetrics.Start()
handleInitErr(err, "Failed to start runtime metrics collector")
}

return &otelProvider{
traceExp: traceExp,
metricsPusher: metricsPusher,
metricsPusher: meterProvider,
}
}

Expand Down
51 changes: 26 additions & 25 deletions tracing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,41 @@ module github.com/hertz-contrib/obs-opentelemetry/tracing
go 1.17

require (
github.com/bytedance/gopkg v0.0.0-20220623074550-9d6d3df70991
github.com/cloudwego/hertz v0.4.1
github.com/stretchr/testify v1.8.0
go.opentelemetry.io/contrib/propagators/b3 v1.9.0
go.opentelemetry.io/contrib/propagators/ot v1.9.0
go.opentelemetry.io/otel v1.9.0
go.opentelemetry.io/otel/metric v0.31.0
go.opentelemetry.io/otel/sdk v1.9.0
go.opentelemetry.io/otel/trace v1.9.0
github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
github.com/cloudwego/hertz v0.5.2
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/contrib/propagators/b3 v1.14.0
go.opentelemetry.io/contrib/propagators/ot v1.14.0
go.opentelemetry.io/otel 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
)

require (
github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect
github.com/andeya/goutil v1.0.0 // indirect
github.com/bytedance/go-tagexpr/v2 v2.9.6 // indirect
github.com/bytedance/sonic v1.5.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 // indirect
github.com/cloudwego/netpoll v0.3.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudwego/netpoll v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.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.0 // indirect
github.com/henrylee2cn/ameda v1.4.10 // indirect
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/nyaruka/phonenumbers v1.0.55 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/henrylee2cn/ameda v1.5.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/nyaruka/phonenumbers v1.1.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/gjson v1.13.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
google.golang.org/protobuf v1.27.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit f719a52

Please sign in to comment.