From 68664951aedf2c851b9b8a87c974695c6b7c0354 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Thu, 22 Sep 2022 11:07:50 -0500 Subject: [PATCH 1/2] chore: add option for specifically disabling Coder tracing --- cli/server.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cli/server.go b/cli/server.go index e8b8a1d1a6d19..a45361824139a 100644 --- a/cli/server.go +++ b/cli/server.go @@ -103,6 +103,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, error)) oidcScopes []string tailscaleEnable bool telemetryEnable bool + telemetryTraceEnable bool telemetryURL string tlsCertFile string tlsClientCAFile string @@ -160,10 +161,20 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, error)) sqlDriver = "postgres" ) - if traceEnable || telemetryEnable { + // Coder tracing should be disabled if telemetry is disabled unless + // --telemetry-trace was explicitly provided. + shouldCoderTrace := telemetryEnable && !isTest() + // Only override if telemetryTraceEnable was specifically set. + // By default we want it to be controlled by telemetryEnable. + if cmd.Flags().Changed("telemetry-trace") { + shouldCoderTrace = telemetryTraceEnable + } + + fmt.Println("shouldCoder", shouldCoderTrace) + if traceEnable || shouldCoderTrace { sdkTracerProvider, closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{ Default: traceEnable, - Coder: telemetryEnable && !isTest(), + Coder: shouldCoderTrace, }) if err != nil { logger.Warn(ctx, "start telemetry exporter", slog.Error(err)) @@ -812,6 +823,8 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, error)) enableTelemetryByDefault := !isTest() cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", enableTelemetryByDefault, "Whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.") + cliflag.BoolVarP(root.Flags(), &telemetryTraceEnable, "telemetry-trace", "", "CODER_TELEMETRY_TRACE", enableTelemetryByDefault, + "Whether Opentelemetry traces are sent to Coder. Coder collects anonymized application tracing to help improve our product. Disabling telemetry also disables this option.") cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "URL to send telemetry.") _ = root.Flags().MarkHidden("telemetry-url") From 743bff3aa6f7b5e19dc6f7971ae9acd30ae7a57b Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Thu, 22 Sep 2022 11:12:49 -0500 Subject: [PATCH 2/2] fixup! chore: add option for specifically disabling Coder tracing --- cli/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/server.go b/cli/server.go index a45361824139a..8875a15480b0c 100644 --- a/cli/server.go +++ b/cli/server.go @@ -170,7 +170,6 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, error)) shouldCoderTrace = telemetryTraceEnable } - fmt.Println("shouldCoder", shouldCoderTrace) if traceEnable || shouldCoderTrace { sdkTracerProvider, closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{ Default: traceEnable,