Skip to content

feat: add --disable-otel / DISABLE_OTEL to disable otel trace export#145

Open
galexrt wants to merge 1 commit intofivemanage:developfrom
galexrt:feat/disable-otel-flag
Open

feat: add --disable-otel / DISABLE_OTEL to disable otel trace export#145
galexrt wants to merge 1 commit intofivemanage:developfrom
galexrt:feat/disable-otel-flag

Conversation

@galexrt
Copy link

@galexrt galexrt commented Mar 6, 2026

Add flag/env var to allow disabling OTEL export/traces.

This should eliminate logs such as this when there isn't OTEL export available at localhost:4318:

[09:59:59.043] INFO: traces export: Post "https://localhost:4318/v1/traces": dial tcp [::1]:4318: connect: connection refused
[09:34:34.057] INFO: traces export: Post "https://localhost:4318/v1/traces": dial tcp [::1]:4318: connect: connection refused
[09:49:49.062] INFO: traces export: Post "https://localhost:4318/v1/traces": dial tcp [::1]:4318: connect: connection refused

Are there any steps I'm missing to build the project? I can't seem to build it due to "docs" pkg missing:

internal/http/publicapi/public_api.go:11:2: no required module provides package github.com/fivemanage/lite/docs; to add it:
        go get github.com/fivemanage/lite/docs

Looking around, the web/package.json target generate:api accesses the docs/ dir as well, but there is no docs/ dir after following the steps from the README.md.
I would appreciate any hints to get it to build locally so I can test it and also look into fixing another issue (nil panics when clickhouse is disabled/not used).

Copilot AI review requested due to automatic review settings March 6, 2026 10:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a --disable-otel CLI flag and DISABLE_OTEL environment variable to allow users to opt out of OpenTelemetry trace export. This is intended to eliminate noisy connection-refused log messages when no OTEL collector is running at localhost:4318.

Changes:

  • pkg/otel/exporter.go: Adds a disabled bool parameter to SetupTracer and InstallExportPipeline; when disabled is true, sets up a bare (no-exporter) tracer provider instead of connecting to the OTLP endpoint.
  • cmd/lite/lite.go: Registers the --disable-otel flag and binds it to the DISABLE_OTEL env var via viper; passes the value into otel.SetupTracer.
  • README.md / .env.template: Documents the new DISABLE_OTEL configuration option.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/otel/exporter.go Core logic change: skips OTLP exporter setup when disabled=true
cmd/lite/lite.go Registers --disable-otel flag and wires it to viper/env
README.md Adds DISABLE_OTEL to the configuration table
.env.template Adds DISABLE_OTEL=false to the dev template

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rootCmd.Flags().String("s3-provider", "minio", "S3 provider")
rootCmd.Flags().String("bucket-domain", "", "Bucket domain for file storage")
// otel
rootCmd.Flags().Bool("disable-otel", false, "Disable OpenTelemetry")
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --disable-otel CLI flag is registered with rootCmd.Flags().Bool(...) but there is no viper.BindPFlag("disable-otel", rootCmd.Flags().Lookup("disable-otel")) call, unlike other flags such as port and dsn. Without this binding, viper.GetBool("disable-otel") will never read the value supplied via the command-line flag — it will only pick up the value from the DISABLE_OTEL environment variable. To make the flag functional, a corresponding viper.BindPFlag call must be added alongside the existing viper.BindEnv call.

Copilot uses AI. Check for mistakes.
func InstallExportPipeline(ctx context.Context) (func(context.Context) error, error) {
func InstallExportPipeline(ctx context.Context, disabled bool) (func(context.Context) error, error) {
if disabled {
tracerProvider := trace.NewTracerProvider()
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When OTEL is disabled, the code creates a full SDK trace.NewTracerProvider() with no exporter but with the default sampler (ParentBased(AlwaysSample)). This means spans are still allocated in memory throughout the application — they are just never exported. A more efficient approach would be to use otel.NewNoopTracerProvider() (from go.opentelemetry.io/otel) instead, which provides a true no-op implementation that skips span creation entirely and incurs zero overhead.

Suggested change
tracerProvider := trace.NewTracerProvider()
tracerProvider := otel.NewNoopTracerProvider()

Copilot uses AI. Check for mistakes.
@galexrt galexrt force-pushed the feat/disable-otel-flag branch from e42d94b to e71e694 Compare March 6, 2026 10:21
@galexrt galexrt changed the title feat: add --otel-disabled / OTEL_DISABLED to disable otel trace export feat: add --disable-otel / DISABLE_OTEL to disable otel trace export Mar 6, 2026
Signed-off-by: Alexander Trost <galexrt@googlemail.com>
@galexrt galexrt force-pushed the feat/disable-otel-flag branch from e71e694 to 5fc55f5 Compare March 6, 2026 10:25
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.

2 participants