-
Notifications
You must be signed in to change notification settings - Fork 2
[LFXv2-610] Add OpenTelemetry tracing support #40
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
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 |
|---|---|---|
|
|
@@ -73,6 +73,49 @@ spec: | |
| value: {{ .Values.health.cacheDuration }} | ||
| - name: HEALTH_DETAILED_RESPONSE | ||
| value: {{ .Values.health.enableDetailedResponse | quote }} | ||
| {{- with .Values.app.extraEnv }} | ||
| {{- toYaml . | nindent 12 }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.serviceName }} | ||
| - name: OTEL_SERVICE_NAME | ||
| value: {{ .Values.app.otel.serviceName | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.serviceVersion }} | ||
| - name: OTEL_SERVICE_VERSION | ||
| value: {{ .Values.app.otel.serviceVersion | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.endpoint }} | ||
| - name: OTEL_EXPORTER_OTLP_ENDPOINT | ||
| value: {{ .Values.app.otel.endpoint | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.protocol }} | ||
| - name: OTEL_EXPORTER_OTLP_PROTOCOL | ||
| value: {{ .Values.app.otel.protocol | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.insecure }} | ||
| - name: OTEL_EXPORTER_OTLP_INSECURE | ||
| value: {{ .Values.app.otel.insecure | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.tracesExporter }} | ||
| - name: OTEL_TRACES_EXPORTER | ||
| value: {{ .Values.app.otel.tracesExporter | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.tracesSampleRatio }} | ||
| - name: OTEL_TRACES_SAMPLE_RATIO | ||
| value: {{ .Values.app.otel.tracesSampleRatio | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.metricsExporter }} | ||
| - name: OTEL_METRICS_EXPORTER | ||
| value: {{ .Values.app.otel.metricsExporter | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.logsExporter }} | ||
| - name: OTEL_LOGS_EXPORTER | ||
| value: {{ .Values.app.otel.logsExporter | quote }} | ||
| {{- end }} | ||
| {{- if .Values.app.otel.propagators }} | ||
| - name: OTEL_PROPAGATORS | ||
| value: {{ .Values.app.otel.propagators | quote }} | ||
| {{- end }} | ||
|
Comment on lines
+79
to
+118
|
||
| ports: | ||
| - containerPort: {{ .Values.app.port }} | ||
| name: web | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,43 @@ app: | |
| readTimeout: "5s" | ||
| writeTimeout: "5s" | ||
| shutdownTimeout: "10s" | ||
| # extraEnv allows adding additional environment variables to the container. | ||
| # Supports both simple values and Kubernetes field references. | ||
| extraEnv: [] | ||
| # otel is the configuration for OpenTelemetry tracing | ||
| otel: | ||
| # serviceName is the service name for OpenTelemetry resource identification | ||
| # (default: "lfx-v2-indexer-service") | ||
| serviceName: "" | ||
| # serviceVersion is the service version for OpenTelemetry resource identification | ||
| # (default: "1.0.0") | ||
| serviceVersion: "" | ||
|
Comment on lines
+77
to
+79
|
||
| # protocol specifies the OTLP protocol: "grpc" or "http" | ||
| # (default: "grpc") | ||
| protocol: "grpc" | ||
| # endpoint is the OTLP collector endpoint | ||
| # For gRPC: typically "host:4317", for HTTP: typically "host:4318" | ||
| endpoint: "" | ||
| # insecure disables TLS for the OTLP connection | ||
| # Set to "true" for in-cluster communication without TLS | ||
| insecure: "false" | ||
| # tracesExporter specifies the traces exporter: "otlp" or "none" | ||
| # (default: "none") | ||
| tracesExporter: "none" | ||
| # tracesSampleRatio specifies the sampling ratio for traces (0.0 to 1.0) | ||
| # A value of 1.0 means all traces are sampled, 0.5 means 50% are sampled | ||
| # (default: "1.0") | ||
| tracesSampleRatio: "1.0" | ||
| # metricsExporter specifies the metrics exporter: "otlp" or "none" | ||
| # (default: "none") | ||
| metricsExporter: "none" | ||
| # logsExporter specifies the logs exporter: "otlp" or "none" | ||
| # (default: "none") | ||
| logsExporter: "none" | ||
| # propagators specifies the propagators to use, comma-separated | ||
| # Supported values: "tracecontext", "baggage", "jaeger" | ||
| # (default: "tracecontext,baggage") | ||
| propagators: "tracecontext,baggage,jaeger" | ||
|
Comment on lines
+82
to
+105
|
||
|
|
||
| # image is the configuration for the container image | ||
| image: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
|
|
||
| "github.com/linuxfoundation/lfx-v2-indexer-service/internal/container" | ||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/logging" | ||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/utils" | ||
| ) | ||
|
|
||
| func main() { | ||
|
|
@@ -26,6 +27,20 @@ func main() { | |
| // Handle early exits (help, config-check) | ||
| handleEarlyExits(flags, logger) | ||
|
|
||
| // Set up OpenTelemetry SDK. | ||
| ctx := context.Background() | ||
| otelConfig := utils.OTelConfigFromEnv() | ||
| otelShutdown, err := utils.SetupOTelSDKWithConfig(ctx, otelConfig) | ||
| if err != nil { | ||
| logger.Error("error setting up OpenTelemetry SDK", "error", err) | ||
| os.Exit(1) | ||
| } | ||
| defer func() { | ||
| if shutdownErr := otelShutdown(context.Background()); shutdownErr != nil { | ||
| logger.Error("error shutting down OpenTelemetry SDK", "error", shutdownErr) | ||
| } | ||
| }() | ||
|
Comment on lines
+38
to
+42
|
||
|
|
||
| // Log configuration with sources for transparency | ||
| logger.Info("Configuration loaded", | ||
| "port", flags.Port, | ||
|
|
||
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.
Potential issue:
tracesSampleRatioof "0" won't be rendered.The
{{- if .Values.app.otel.tracesSampleRatio }}condition evaluates to false when the value is"0"or0, which is a valid sample ratio meaning "sample no traces". If disabling sampling via0is a valid use case, consider using a different conditional approach.🔧 Suggested fix using `ne` comparison
Alternatively, always set the value since there's a sensible default:
📝 Committable suggestion
🤖 Prompt for AI Agents