From e30c0dcc7d8def451517970329ad7b24f9957463 Mon Sep 17 00:00:00 2001 From: Safeer Jiwan Date: Mon, 29 Jul 2024 12:40:34 -0700 Subject: [PATCH] fix breaking changes from otel 1.27 -> 1.28 --- cmd/ftl/cmd_serve.go | 3 -- go.mod | 3 +- go.sum | 2 -- internal/observability/client.go | 2 +- internal/rpc/otel_interceptor.go | 49 ++++++++++++++++++-------------- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/cmd/ftl/cmd_serve.go b/cmd/ftl/cmd_serve.go index 56855d82d1..1f985915fe 100644 --- a/cmd/ftl/cmd_serve.go +++ b/cmd/ftl/cmd_serve.go @@ -44,10 +44,7 @@ type serveCmd struct { Stop bool `help:"Stop the running FTL instance. Can be used with --background to restart the server" default:"false"` StartupTimeout time.Duration `help:"Timeout for the server to start up." default:"1m"` ObservabilityConfig observability.Config `embed:"" prefix:"o11y-"` -<<<<<<< HEAD DatabaseImage string `help:"The container image to start for the database" default:"postgres:15.4" env:"FTL_DATABASE_IMAGE" hidden:""` -======= ->>>>>>> 31713171 (fix: init observability client in cmd_serve) controller.CommonConfig } diff --git a/go.mod b/go.mod index d3145f9362..74902401f5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.22.2 require ( connectrpc.com/connect v1.16.2 connectrpc.com/grpcreflect v1.2.0 - connectrpc.com/otelconnect v0.7.1 github.com/BurntSushi/toml v1.4.0 github.com/TBD54566975/golang-tools v0.2.1 github.com/TBD54566975/scaffolder v1.0.0 @@ -55,6 +54,7 @@ require ( go.opentelemetry.io/otel/metric v1.28.0 go.opentelemetry.io/otel/sdk v1.28.0 go.opentelemetry.io/otel/sdk/metric v1.28.0 + go.opentelemetry.io/otel/trace v1.28.0 go.uber.org/automaxprocs v1.5.3 golang.org/x/exp v0.0.0-20240707233637-46b078467d37 golang.org/x/mod v0.19.0 @@ -101,7 +101,6 @@ require ( github.com/stretchr/objx v0.5.2 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.26.0 // indirect - go.opentelemetry.io/otel/trace v1.28.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/tools v0.23.0 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/go.sum b/go.sum index 5becce661c..07cf542813 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE= connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc= connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U= connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= -connectrpc.com/otelconnect v0.7.1 h1:scO5pOb0i4yUE66CnNrHeK1x51yq0bE0ehPg6WvzXJY= -connectrpc.com/otelconnect v0.7.1/go.mod h1:dh3bFgHBTb2bkqGCeVVOtHJreSns7uu9wwL2Tbz17ms= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= diff --git a/internal/observability/client.go b/internal/observability/client.go index 9e980476ac..0fcd9531ab 100644 --- a/internal/observability/client.go +++ b/internal/observability/client.go @@ -13,7 +13,7 @@ import ( "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.25.0" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" "github.com/TBD54566975/ftl/internal/log" ) diff --git a/internal/rpc/otel_interceptor.go b/internal/rpc/otel_interceptor.go index 35bc250a6b..09257c34d1 100644 --- a/internal/rpc/otel_interceptor.go +++ b/internal/rpc/otel_interceptor.go @@ -17,16 +17,21 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/propagation" - semconv "go.opentelemetry.io/otel/semconv/v1.7.0" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" "go.opentelemetry.io/otel/trace" "google.golang.org/protobuf/proto" ) const ( - otelFtlRequestKey = "ftl.requestKey" - otelFtlVerbRef = "ftl.verb.ref" - otelFtlVerbModule = "ftl.verb.module" - otelFtlEventName = "ftl.message" + otelFtlRequestKey = "ftl.requestKey" + otelFtlVerbRef = "ftl.verb.ref" + otelFtlVerbModule = "ftl.verb.module" + otelMessageEvent = "message" + otelMessageIDKey = attribute.Key("message.id") + otelMessageSizeKey = attribute.Key("message.uncompressed_size") + otelMessageTypeKey = attribute.Key("message.type") + otelMessageTypeSent = "SENT" + otelMessageTypeReceived = "RECEIVED" ) func OtelInterceptor() connect.Interceptor { @@ -77,10 +82,12 @@ func (i *otelInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { name := strings.TrimLeft(request.Spec().Procedure, "/") spanKind := trace.SpanKindClient - requestSpan, responseSpan := semconv.MessageTypeSent, semconv.MessageTypeReceived + requestSpan := otelMessageTypeKey.String(otelMessageTypeSent) + responseSpan := otelMessageTypeKey.String(otelMessageTypeReceived) if !isClient { spanKind = trace.SpanKindServer - requestSpan, responseSpan = semconv.MessageTypeReceived, semconv.MessageTypeSent + requestSpan = otelMessageTypeKey.String(otelMessageTypeReceived) + responseSpan = otelMessageTypeKey.String(otelMessageTypeSent) } attributes := getAttributes(ctx, request.Peer().Protocol) @@ -99,11 +106,11 @@ func (i *otelInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { } } - span.AddEvent(otelFtlEventName, + span.AddEvent(otelMessageEvent, trace.WithAttributes( requestSpan, - semconv.MessageIDKey.Int(1), - semconv.MessageUncompressedSizeKey.Int(requestSize), + otelMessageIDKey.Int(1), + otelMessageSizeKey.Int(requestSize), ), ) @@ -115,11 +122,11 @@ func (i *otelInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc { responseSize = proto.Size(msg) } } - span.AddEvent(otelFtlEventName, + span.AddEvent(otelMessageEvent, trace.WithAttributes( responseSpan, - semconv.MessageIDKey.Int(1), - semconv.MessageUncompressedSizeKey.Int(responseSize), + otelMessageIDKey.Int(1), + otelMessageSizeKey.Int(responseSize), ), ) span.SetAttributes(attributes...) @@ -335,17 +342,17 @@ func (s *streamingState) receive(ctx context.Context, msg any, conn streamingSen s.attributes = append(s.attributes, statusCodeAttribute(s.protocol, err)) } attrs := append(s.attributes, []attribute.KeyValue{ // nolint:gocritic - semconv.MessageTypeReceived, - semconv.MessageIDKey.Int64(s.receivedCounter), + otelMessageTypeKey.String(otelMessageTypeReceived), + otelMessageIDKey.Int64(s.receivedCounter), }...) if protomsg, ok := msg.(proto.Message); ok { size := proto.Size(protomsg) - attrs = append(attrs, semconv.MessageUncompressedSizeKey.Int(size)) + attrs = append(attrs, otelMessageSizeKey.Int(size)) s.receiveSize.Record(ctx, int64(size), metric.WithAttributes(attrs...)) } span := trace.SpanFromContext(ctx) - span.AddEvent(otelFtlEventName, trace.WithAttributes(attrs...)) + span.AddEvent(otelMessageEvent, trace.WithAttributes(attrs...)) return err // nolint:wrapcheck } @@ -362,17 +369,17 @@ func (s *streamingState) send(ctx context.Context, msg any, conn streamingSender s.attributes = append(s.attributes, statusCodeAttribute(s.protocol, err)) } attrs := append(s.attributes, []attribute.KeyValue{ // nolint:gocritic - semconv.MessageTypeSent, - semconv.MessageIDKey.Int64(s.sentCounter), + otelMessageTypeKey.String(otelMessageTypeSent), + otelMessageIDKey.Int64(s.sentCounter), }...) if protomsg, ok := msg.(proto.Message); ok { size := proto.Size(protomsg) - attrs = append(attrs, semconv.MessageUncompressedSizeKey.Int(size)) + attrs = append(attrs, otelMessageSizeKey.Int(size)) s.sendSize.Record(ctx, int64(size), metric.WithAttributes(attrs...)) } span := trace.SpanFromContext(ctx) - span.AddEvent(otelFtlEventName, trace.WithAttributes(attrs...)) + span.AddEvent(otelMessageEvent, trace.WithAttributes(attrs...)) return err // nolint:wrapcheck }