Skip to content

Commit

Permalink
feat: bump opentelemetry dependencies
Browse files Browse the repository at this point in the history
The stable version of the metric API has been released,
see https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.16.0
  • Loading branch information
thall committed Jun 28, 2023
1 parent 2189a83 commit db601d0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 79 deletions.
36 changes: 18 additions & 18 deletions cloudmonitoring/metricmiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strings"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand All @@ -27,28 +27,28 @@ const (
)

func NewMetricMiddleware() (MetricMiddleware, error) {
meter := global.MeterProvider().Meter("cloudrunner-go/cloudmonitoring")
meter := otel.GetMeterProvider().Meter("cloudrunner-go/cloudmonitoring")

serverRequestCount, err := meter.Int64Counter(
serverRequestCountMetricName,
instrument.WithUnit("1"),
instrument.WithDescription("Count of RPCs received by a gRPC server."),
metric.WithUnit("1"),
metric.WithDescription("Count of RPCs received by a gRPC server."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create server request count counter: %w", err)
}
clientRequestCount, err := meter.Int64Counter(
clientRequestCountMetricName,
instrument.WithUnit("1"),
instrument.WithDescription("Count of RPCs sent by a gRPC client."),
metric.WithUnit("1"),
metric.WithDescription("Count of RPCs sent by a gRPC client."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create client request count counter: %w", err)
}
clientRequestDuration, err := meter.Int64Histogram(
clientRequestDurationMetricName,
instrument.WithUnit("ms"),
instrument.WithDescription("Duration of RPCs sent by a gRPC client."),
metric.WithUnit("ms"),
metric.WithDescription("Duration of RPCs sent by a gRPC client."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create client request duration histogram: %w", err)
Expand All @@ -61,9 +61,9 @@ func NewMetricMiddleware() (MetricMiddleware, error) {
}

type MetricMiddleware struct {
serverRequestCount instrument.Int64Counter
clientRequestCount instrument.Int64Counter
clientRequestDuration instrument.Int64Histogram
serverRequestCount metric.Int64Counter
clientRequestCount metric.Int64Counter
clientRequestDuration metric.Int64Histogram
}

// GRPCUnaryServerInterceptor implements grpc.UnaryServerInterceptor and
Expand All @@ -78,7 +78,7 @@ func (m *MetricMiddleware) GRPCUnaryServerInterceptor(
response, err := handler(ctx, request)
code := status.Code(err)
attrs := rpcAttrs(info.FullMethod, code)
m.serverRequestCount.Add(ctx, 1, attrs...)
m.serverRequestCount.Add(ctx, 1, attrs)
return response, err
}

Expand All @@ -94,7 +94,7 @@ func (m *MetricMiddleware) GRPCStreamServerInterceptor(
err = handler(srv, ss)
code := status.Code(err)
attrs := rpcAttrs(info.FullMethod, code)
m.serverRequestCount.Add(ss.Context(), 1, attrs...)
m.serverRequestCount.Add(ss.Context(), 1, attrs)
return err
}

Expand All @@ -114,12 +114,12 @@ func (m *MetricMiddleware) GRPCUnaryClientInterceptor(
duration := time.Since(startTime)

attrs := rpcAttrs(fullMethod, code)
m.clientRequestCount.Add(ctx, 1, attrs...)
m.clientRequestDuration.Record(ctx, duration.Milliseconds(), attrs...)
m.clientRequestCount.Add(ctx, 1, attrs)
m.clientRequestDuration.Record(ctx, duration.Milliseconds(), attrs)
return err
}

func rpcAttrs(fullMethod string, code codes.Code) []attribute.KeyValue {
func rpcAttrs(fullMethod string, code codes.Code) metric.MeasurementOption {
attrs := make([]attribute.KeyValue, 0, 5)
attrs = append(
attrs,
Expand All @@ -136,7 +136,7 @@ func rpcAttrs(fullMethod string, code codes.Code) []attribute.KeyValue {
semconv.RPCMethodKey.String(method),
)
}
return attrs
return metric.WithAttributes(attrs...)
}

func splitFullMethod(fullMethod string) (service, method string, ok bool) {
Expand Down
4 changes: 2 additions & 2 deletions cloudotel/metricexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"go.einride.tech/cloudrunner/cloudzap"
hostinstrumentation "go.opentelemetry.io/contrib/instrumentation/host"
runtimeinstrumentation "go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
globalmetric "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/instrumentation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -73,7 +73,7 @@ func StartMetricExporter(
),
),
)
globalmetric.SetMeterProvider(provider)
otel.SetMeterProvider(provider)
shutdown := func() {
if err := exporter.Shutdown(context.Background()); err != nil {
if logger, ok := cloudzap.GetLogger(ctx); ok {
Expand Down
39 changes: 20 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ require (
cloud.google.com/go/compute/metadata v0.2.3
cloud.google.com/go/profiler v0.3.1
cloud.google.com/go/pubsub v1.30.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.37.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.13.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator v0.37.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.39.2
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.15.2
github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator v0.39.2
github.com/google/go-cmp v0.5.9
github.com/soheilhy/cmux v0.1.5
go.einride.tech/protobuf-sensitive v0.3.0
go.opencensus.io v0.24.0
go.opentelemetry.io/contrib/detectors/gcp v1.15.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.40.0
go.opentelemetry.io/contrib/instrumentation/host v0.40.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.40.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/bridge/opencensus v0.37.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/sdk/metric v0.37.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
go.opentelemetry.io/contrib/instrumentation/host v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/bridge/opencensus v0.39.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/sdk/metric v0.39.0
go.uber.org/zap v1.24.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.1.0
google.golang.org/api v0.116.0
google.golang.org/genproto v0.0.0-20230403163135-c38d8f061ccd
google.golang.org/grpc v1.54.0
google.golang.org/grpc v1.55.0
google.golang.org/grpc/examples v0.0.0-20220915225546-9c3e589d3ee6
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -41,10 +41,10 @@ require (
cloud.google.com/go/monitoring v1.13.0 // indirect
cloud.google.com/go/trace v1.9.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.11.2 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.37.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.39.2 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -56,15 +56,16 @@ require (
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/shirou/gopsutil/v3 v3.23.1 // indirect
github.com/shirou/gopsutil/v3 v3.23.4 // indirect
github.com/shoenig/go-m1cpu v0.1.5 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
)
Loading

0 comments on commit db601d0

Please sign in to comment.