traceClientFromEnv creates a GRPC OTLP client based on OS environment variables. https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/
()
| 121 | // |
| 122 | // https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/ |
| 123 | func traceClientFromEnv() (otlptrace.Client, envMap) { |
| 124 | hasOtelEndpointInEnv := false |
| 125 | otelEnv := make(map[string]string) |
| 126 | for _, kv := range os.Environ() { |
| 127 | k, v, ok := strings.Cut(kv, "=") |
| 128 | if !ok { |
| 129 | continue |
| 130 | } |
| 131 | if strings.HasPrefix(k, "OTEL_") { |
| 132 | otelEnv[k] = v |
| 133 | if strings.HasSuffix(k, "ENDPOINT") { |
| 134 | hasOtelEndpointInEnv = true |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if !hasOtelEndpointInEnv { |
| 140 | return nil, nil |
| 141 | } |
| 142 | |
| 143 | client := otlptracegrpc.NewClient() |
| 144 | return client, otelEnv |
| 145 | } |