-
Notifications
You must be signed in to change notification settings - Fork 15
HYPERFLEET-762: Add OpenTelemetry configuration to standard environme… #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6e087ee
e95d947
b804696
5dd7790
de5e6db
9d50749
087c701
ada76a9
718aab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "log/slog" | ||
| "os" | ||
| "os/signal" | ||
| "strconv" | ||
| "syscall" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
@@ -69,14 +70,45 @@ func runServe(cmd *cobra.Command, args []string) { | |
| logger.Info(ctx, config.DumpConfig(environments.Environment().Config)) | ||
|
|
||
| var tp *trace.TracerProvider | ||
| if environments.Environment().Config.Logging.OTel.Enabled { | ||
| samplingRate := environments.Environment().Config.Logging.OTel.SamplingRate | ||
| traceProvider, err := telemetry.InitTraceProvider(ctx, "hyperfleet-api", api.Version, samplingRate) | ||
|
|
||
| // Check for deprecated HYPERFLEET_LOGGING_OTEL_ENABLED variable | ||
| if deprecatedEnv := os.Getenv("HYPERFLEET_LOGGING_OTEL_ENABLED"); deprecatedEnv != "" { | ||
| logger.With(ctx, | ||
| "deprecated_variable", "HYPERFLEET_LOGGING_OTEL_ENABLED", | ||
| "replacement", "TRACING_ENABLED", | ||
| ).Warn("HYPERFLEET_LOGGING_OTEL_ENABLED is deprecated and ignored. Please use TRACING_ENABLED instead.") | ||
| } | ||
|
|
||
| // Determine if tracing is enabled using TRACING_ENABLED (tracing standard) | ||
| var tracingEnabled bool | ||
| if tracingEnv := os.Getenv("TRACING_ENABLED"); tracingEnv != "" { | ||
| if enabled, err := strconv.ParseBool(tracingEnv); err == nil { | ||
| tracingEnabled = enabled | ||
| } else { | ||
| logger.With(ctx, | ||
| logger.FieldTracingEnabled, tracingEnv, | ||
| "falling_back_to", environments.Environment().Config.Logging.OTel.Enabled). | ||
| WithError(err).Warn("Invalid TRACING_ENABLED value, falling back to config") | ||
| tracingEnabled = environments.Environment().Config.Logging.OTel.Enabled | ||
| } | ||
| } else { | ||
| // Use config default if TRACING_ENABLED not set | ||
| tracingEnabled = environments.Environment().Config.Logging.OTel.Enabled | ||
| } | ||
|
|
||
| if tracingEnabled { | ||
| // OpenTelemetry configuration is driven entirely by standard environment variables: | ||
| serviceName := "hyperfleet-api" | ||
| if svcName := os.Getenv("OTEL_SERVICE_NAME"); svcName != "" { | ||
| serviceName = svcName | ||
| } | ||
|
|
||
| traceProvider, err := telemetry.InitTraceProvider(ctx, serviceName, api.Version) | ||
|
Comment on lines
+101
to
+106
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both sentinel and adapter have a Then, here we are reading a variable that is otel specific.... I wonder if that should be done inside the |
||
| if err != nil { | ||
| logger.WithError(ctx, err).Warn("Failed to initialize OpenTelemetry") | ||
| } else { | ||
| tp = traceProvider | ||
| logger.With(ctx, logger.FieldSamplingRate, samplingRate).Info("OpenTelemetry initialized") | ||
| logger.With(ctx, logger.FieldServiceName, serviceName).Info("OpenTelemetry initialized") | ||
| } | ||
| } else { | ||
| logger.With(ctx, logger.FieldOTelEnabled, false).Info("OpenTelemetry disabled") | ||
|
|
@@ -89,7 +121,7 @@ func runServe(cmd *cobra.Command, args []string) { | |
| "masking_enabled", environments.Environment().Config.Logging.Masking.Enabled, | ||
| ).Info("Logger initialized") | ||
|
|
||
| apiServer := server.NewAPIServer() | ||
| apiServer := server.NewAPIServer(tracingEnabled) | ||
| go apiServer.Start() | ||
|
|
||
| metricsServer := server.NewMetricsServer() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we align on using a single variable for enabling tracing?
I see the standard says
TRACING_ENABLEDand this may come from before standarising environment variables with prefixHYPERFLEET_Then, the docs mention
HYPERFLEET_LOGGING_OTEL_ENABLEDI think we should consolidate in a single one and keep it consistent across repositories.
AFAIK
OTEL_*variables do not have theHYPERFLEET_prefix since they are used directly by the OTEL libraries, but any other variable that we introduce should be prefixed by our standard convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I’ll remove HYPERFLEET_LOGGING_OTEL_ENABLED then. I’ll keep the OTEL_ variables* for consistency with hyperfleet-sentinel. Does that make sense?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to clarify, I meant to use
HYPERFLEET_TRACING_ENABLEDinstead of simpleTRACING_ENABLEDThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HYPERFLEET_TRACING_ENABLEDis not compliant with the tracing standards — we should useTRACING_ENABLEDinstead. See: tracing standards