Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ CLICKHOUSE_DATABASE=default
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=password

DISABLE_OTEL=false

VERSION=dev # dev only
ENV=dev # dev only
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The application is configured via environment variables.
| `CLICKHOUSE_PASSWORD` | ClickHouse password | `password` |
| `CLICKHOUSE_DATABASE` | ClickHouse database name | `default` |
| `ENV` | Environment mode (`production` or `dev`) | `dev` |
| `DISABLE_OTEL` | Disable OpenTelemetry integration (true/false) | `false` |

---

Expand Down
7 changes: 6 additions & 1 deletion cmd/lite/lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var rootCmd = &cobra.Command{

slog.Info("starting Fivemanage application", slog.String("version", Version))

otelShutdown, err := otel.SetupTracer()
otelShutdown, err := otel.SetupTracer(viper.GetBool("disable-otel"))
if err != nil {
slog.Error("failed to setup OpenTelemetry", slog.Any("error", err))
}
Expand Down Expand Up @@ -185,6 +185,8 @@ func init() {
// s3
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.

// fuck me
if err := viper.BindPFlag("port", rootCmd.Flags().Lookup("port")); err != nil {
Expand Down Expand Up @@ -220,6 +222,9 @@ func init() {
if err := viper.BindEnv("bucket-domain", "BUCKET_DOMAIN"); err != nil {
bindError(err)
}
if err := viper.BindEnv("disable-otel", "DISABLE_OTEL"); err != nil {
bindError(err)
}

rootCmd.AddCommand(migrate.RootCmd)
migrate.RootCmd.AddCommand(
Expand Down
14 changes: 11 additions & 3 deletions pkg/otel/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
"go.opentelemetry.io/otel/trace/noop"
)

const (
serviceName = "lite-api"
otlpEndpoint = "localhost:4318"
)

func SetupTracer() (func(context.Context) error, error) {
func SetupTracer(disabled bool) (func(context.Context) error, error) {
ctx := context.Background()
return InstallExportPipeline(ctx)
return InstallExportPipeline(ctx, disabled)
}

func Resource() *resource.Resource {
Expand All @@ -34,7 +35,14 @@ func Resource() *resource.Resource {
)
}

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 := noop.NewTracerProvider()
otel.SetTracerProvider(tracerProvider)

return func(context.Context) error { return nil }, nil
}

var tlsOption otlptracehttp.Option
if os.Getenv("ENV") == "dev" {
tlsOption = otlptracehttp.WithInsecure()
Expand Down