MCPcopy Index your code
hub / github.com/dagger/dagger / initEngineTelemetry

Function initEngineTelemetry

cmd/dagger/engine.go:188–244  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

186}
187
188func 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}

Callers 1

withEngineFunction · 0.85

Calls 15

ContextWithColorModeFunction · 0.92
ContextWithDebugModeFunction · 0.92
SetDefaultFunction · 0.92
SpanLoggerFunction · 0.92
ResourceFunction · 0.85
spanNameFunction · 0.85
TracerFunction · 0.70
SpanExporterMethod · 0.65
LogExporterMethod · 0.65
MetricExporterMethod · 0.65
GetenvMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected