-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathflags_tracing.go
More file actions
39 lines (33 loc) · 1.48 KB
/
flags_tracing.go
File metadata and controls
39 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cmd
// Tracing-related flags for OpenTelemetry OTLP trace export.
import (
"github.com/github/gh-aw-mcpg/internal/config"
"github.com/github/gh-aw-mcpg/internal/envutil"
"github.com/spf13/cobra"
)
// Tracing flag variables
var (
otlpEndpoint string
otlpServiceName string
otlpSampleRate float64
)
func init() {
RegisterFlag(func(cmd *cobra.Command) {
cmd.Flags().StringVar(&otlpEndpoint, "otlp-endpoint", getDefaultOTLPEndpoint(),
"OTLP HTTP endpoint for trace export (e.g. http://localhost:4318). Overrides OTEL_EXPORTER_OTLP_ENDPOINT env var. Tracing is disabled when empty.")
cmd.Flags().StringVar(&otlpServiceName, "otlp-service-name", getDefaultOTLPServiceName(),
"Service name reported in traces. Overrides OTEL_SERVICE_NAME env var.")
cmd.Flags().Float64Var(&otlpSampleRate, "otlp-sample-rate", config.DefaultTracingSampleRate,
"Fraction of traces to sample and export (0.0–1.0). Default 1.0 samples everything.")
})
}
// getDefaultOTLPEndpoint returns the OTLP endpoint, checking OTEL_EXPORTER_OTLP_ENDPOINT
// environment variable first, then falling back to empty (disabled).
func getDefaultOTLPEndpoint() string {
return envutil.GetEnvString("OTEL_EXPORTER_OTLP_ENDPOINT", "")
}
// getDefaultOTLPServiceName returns the OTLP service name, checking OTEL_SERVICE_NAME
// environment variable first, then falling back to the default.
func getDefaultOTLPServiceName() string {
return envutil.GetEnvString("OTEL_SERVICE_NAME", config.DefaultTracingServiceName)
}