Skip to content

Feat/pubsub v2 otel#45

Open
Josemaralves wants to merge 13 commits into
developfrom
feat/pubsub-v2-otel
Open

Feat/pubsub v2 otel#45
Josemaralves wants to merge 13 commits into
developfrom
feat/pubsub-v2-otel

Conversation

@Josemaralves

@Josemaralves Josemaralves commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Migration of Pub/Sub to the cloud.google.com/go/pubsub/v2 SDK with native OpenTelemetry tracing support, a comprehensive OTEL infrastructure overhaul (signal-specific exporters, Prometheus, runtime metrics, sampling), and opt-in MongoDB monitoring, alongside dependency upgrades across the board.

Key Changes

Pub/Sub v2 Migration (factory/contrib/cloud.google.com/pubsub/v1)

  • Switched from pubsub.NewClient to pubsub.NewClientWithConfig with EnableOpenTelemetryTracing: true ? native OTel tracing via the SDK
  • Attached otelgrpc.NewClientHandler() and gRPC experimental metrics dial options, wired to the boost OTel MeterProvider
  • Helper.Start() now uses fire-and-forget goroutines (dropped sync.WaitGroup coordination)
  • Extracted generateCloudEvent to a standalone message.go

OpenTelemetry Overhaul (factory/contrib/go.opentelemetry.io/otel/v1)

  • Signal-specific endpoints: metric.endpoint, metric.protocol, trace.endpoint, trace.protocol, trace.ratio ? resolution order follows the OTel env-var spec
  • Prometheus exporter: registered alongside the periodic OTLP reader in StartMetricProvider
  • Runtime instrumentation: runtime.Start(...) runs automatically (5s memory stats interval)
  • Sampling: AlwaysSample() ? TraceIDRatioBased(options.Trace.Ratio), defaulting to 1.0
  • Env parsing: NewOptions now reads OTEL_RESOURCE_ATTRIBUTES, OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_TRACES_SAMPLER_ARG
  • Provider lifecycle: removed noop initializers ? providers are now only set when explicitly started; plugins no longer auto-start them

MongoDB Opt-in Monitoring (factory/contrib/go.mongodb.org/mongo-driver/v2)

  • Command/pool monitors gated behind Log.Enabled (default false), extracted to setLogMonitor
  • OTel plugin now passes WithMeterProvider alongside the tracer provider

gRPC Client OTel (factory/contrib/google.golang.org/grpc/v1)

  • ~20 experimental gRPC metrics enabled (subchannel, pick_first, RLS, WRR, outlier detection, xDS client) via oteltelemetry.DialOption

Function Middleware

  • OTel middleware: holds a Tracer instance, uses c.Tracer.Start instead of creating a new tracer per invocation; sync.Once-guarded lazy meter init
  • Logger middleware: simplified log adapter signature from func(format string, args ...interface{}) to func(string); default level changed from "INFO" to "DEBUG"

New FX Modules

  • fx/modules/factory/contrib/go.opentelemetry.io/otel/v1 ? starts tracer and meter providers at app startup
  • fx/modules/bootstrap/function/middleware/opentelemetry ? provides OpenTelemetry[T] via fx.Provide, gated by config flag

Dependency Upgrades

  • Go 1.26.0 ? 1.26.4
  • Nearly all dependencies bumped (Datadog agent, AWS SDK v2, OTel stack, Echo, NATS, gRPC, etc.)
  • Added: go.opentelemetry.io/contrib/instrumentation/runtime, go.opentelemetry.io/otel/exporters/prometheus
  • Removed two replace directives (gnostic-models, kube-openapi)

Test Plan

  • Verify Pub/Sub subscriber receives and acknowledges messages with OTel tracing enabled
  • Confirm OTEL signal-specific endpoints work independently for traces and metrics
  • Validate Prometheus /metrics endpoint is exposed correctly
  • Check MongoDB monitors are not attached when Log.Enabled is false (default)
  • Run go build ./... and go test ./... green

Breaking Changes

  • Pub/Sub adapter backoff default changed from true to false
  • Logger middleware adapter signature changed from func(format string, args ...interface{}) to func(string)

@Josemaralves Josemaralves requested review from gabrielzuqueto and jpfaria and removed request for jpfaria June 23, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant