Skip to content

Commit

Permalink
fix breaking changes from otel 1.27 -> 1.28
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Jul 29, 2024
1 parent 743b9b1 commit e30c0dc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
3 changes: 0 additions & 3 deletions cmd/ftl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/observability/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
49 changes: 28 additions & 21 deletions internal/rpc/otel_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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),
),
)

Expand All @@ -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...)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit e30c0dc

Please sign in to comment.