Skip to content

otel: replace cobraotel with native lifecycle management#3107

Closed
Jdepp007004 wants to merge 1 commit intoauthzed:mainfrom
Jdepp007004:fix/otel-lifecycle-native
Closed

otel: replace cobraotel with native lifecycle management#3107
Jdepp007004 wants to merge 1 commit intoauthzed:mainfrom
Jdepp007004:fix/otel-lifecycle-native

Conversation

@Jdepp007004
Copy link
Copy Markdown
Contributor

Fixes #712 and #3095.

Removes the cobraotel dependency and brings OTel lifecycle management natively into SpiceDB.

What changed:

  • pkg/cmd/server/otel.go — new file with RegisterOTelFlags, InitOTelProvider, ShutdownOTelProvider, OTelPreRunE, OTelProviderFromContext
  • pkg/cmd/serve.go — ShutdownOTelProvider now called on SIGTERM/SIGINT, fixing span loss on exit (Bug: OpenTelemetry traces are not flushed on shutdown, dropping spans on SIGTERM #3095)
  • pkg/cmd/server/defaults.go — replaced cobraotel wiring with native OTelPreRunE
  • pkg/cmd/util/util.go — touched only to break an import cycle, flag registrations unchanged
  • vendor/.../cobrautil.go — fixed viper.SetEnvPrefix mutating global singleton instead of local instance
  • 20 tests added (unit, integration, system with in-process OTLP collector)

Question before I finalize: for --otel-provider, you mentioned deprecating/hiding it — should I use MarkDeprecated (warns users when they pass it) or MarkHidden (silently removes from help)? Happy to add that in a follow-up or include it here.

Fixes authzed#712 and authzed#3095.

- Remove dependency on github.com/jzelinskie/cobrautil/v2/cobraotel
- Replicate OTel provider initialization natively in pkg/cmd/server/otel.go
- Wire TracerProvider into serve.go signal handler so Shutdown and
  ForceFlush are called on SIGTERM/SIGINT, preventing span loss on exit
- Fix vendored cobrautil Viper global singleton bug: viper.SetEnvPrefix
  was mutating global state instead of the local instance (v.SetEnvPrefix)
- Touch pkg/cmd/util/util.go only to break import cycle between
  pkg/cmd/util and pkg/cmd/server; all flag registrations unchanged
- Add 20 tests across unit, integration, and system build tags
@Jdepp007004 Jdepp007004 requested a review from a team as a code owner May 9, 2026 14:42
@Jdepp007004 Jdepp007004 closed this May 9, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 9, 2026
@github-actions github-actions Bot added area/cli Affects the command line area/dependencies Affects dependencies area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels May 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/cli Affects the command line area/dependencies Affects dependencies area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure Opentelemetry solely through OTEL_ flags

1 participant