(ctx context.Context)
| 186 | } |
| 187 | |
| 188 | func initEngineTelemetry(ctx context.Context) (context.Context, func(error)) { |
| 189 | // Setup telemetry config |
| 190 | telemetryCfg := telemetry.Config{ |
| 191 | Detect: true, |
| 192 | Resource: Resource(ctx), |
| 193 | |
| 194 | LiveTraceExporters: []sdktrace.SpanExporter{Frontend.SpanExporter()}, |
| 195 | LiveLogExporters: []sdklog.Exporter{Frontend.LogExporter()}, |
| 196 | LiveMetricExporters: []sdkmetric.Exporter{Frontend.MetricExporter()}, |
| 197 | } |
| 198 | if spans, logs, metrics, ok := enginetel.ConfiguredCloudExporters(ctx); ok { |
| 199 | telemetryCfg.LiveTraceExporters = append(telemetryCfg.LiveTraceExporters, spans) |
| 200 | telemetryCfg.LiveLogExporters = append(telemetryCfg.LiveLogExporters, logs) |
| 201 | telemetryCfg.LiveMetricExporters = append(telemetryCfg.LiveMetricExporters, metrics) |
| 202 | } |
| 203 | ctx = telemetry.Init(ctx, telemetryCfg) |
| 204 | // telemetry.Init extracts inherited OTel baggage from the environment. |
| 205 | // Re-apply explicit local process settings afterward so a nested Dagger |
| 206 | // command's own NO_COLOR/debug request wins over parent baggage. |
| 207 | if termenv.EnvNoColor() { |
| 208 | ctx = slog.ContextWithColorMode(ctx, true) |
| 209 | } |
| 210 | if debugFlag { |
| 211 | ctx = slog.ContextWithDebugMode(ctx, true) |
| 212 | } |
| 213 | |
| 214 | // Set the full command string as the name of the root span. |
| 215 | // |
| 216 | // If you pass credentials in plaintext, yes, they will be leaked; don't do |
| 217 | // that, since they will also be leaked in various other places (like the |
| 218 | // process tree). Use Secret arguments instead. |
| 219 | name := spanName(os.Args) |
| 220 | if os.Getenv(TraceNameEnv) != "" { |
| 221 | name = os.Getenv(TraceNameEnv) |
| 222 | } |
| 223 | ctx, span := Tracer().Start(ctx, name) |
| 224 | |
| 225 | // Set up global slog to log to the primary span output. |
| 226 | slog.SetDefault(slog.SpanLogger(ctx, InstrumentationLibrary)) |
| 227 | |
| 228 | // Set the root span as the target for "global logs" |
| 229 | ctx = telemetry.ContextWithGlobalLogsSpan(ctx) |
| 230 | |
| 231 | // Set the span as the primary span for the frontend. |
| 232 | Frontend.SetPrimary(dagui.SpanID{SpanID: span.SpanContext().SpanID()}) |
| 233 | |
| 234 | // Direct command stdout/stderr to span stdio via OpenTelemetry. |
| 235 | stdio := telemetry.SpanStdio(ctx, InstrumentationLibrary) |
| 236 | rootCmd.SetOut(stdio.Stdout) |
| 237 | rootCmd.SetErr(stdio.Stderr) |
| 238 | |
| 239 | return ctx, func(rerr error) { |
| 240 | stdio.Close() |
| 241 | telemetry.EndWithCause(span, &rerr) |
| 242 | telemetry.Close() |
| 243 | } |
| 244 | } |
no test coverage detected