{"record":{"id":"58cf944acb7bc8e6","repo":"cloudflare/cloudflared","slug":"error-starting-tracing","errorCode":null,"errorMessage":"Error starting tracing","messagePattern":"Error starting tracing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/cloudflared/tunnel/cmd.go","lineNumber":367,"sourceCode":"\t\t\ttraceOutputFilepath := c.String(cfdflags.TraceOutput)\n\t\t\t//nolint:gosec // File path is safe because it is explicitly provided by the user via the --trace-output flag\n\t\t\tif err := os.Rename(tmpTraceFile.Name(), traceOutputFilepath); err != nil {\n\t\t\t\ttraceLog.\n\t\t\t\t\tErr(err).\n\t\t\t\t\tStr(LogFieldTraceOutputFilepath, traceOutputFilepath).\n\t\t\t\t\tMsg(\"Failed to rename temporary trace output file\")\n\t\t\t} else {\n\t\t\t\t//nolint:gosec // File path is safe, since it is created by os.CreateTemp\n\t\t\t\terr := os.Remove(tmpTraceFile.Name())\n\t\t\t\tif err != nil {\n\t\t\t\t\ttraceLog.Err(err).Msg(\"Failed to remove the temporary trace file\")\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\n\t\tif err := trace.Start(tmpTraceFile); err != nil {\n\t\t\ttraceLog.Err(err).Msg(\"Failed to start trace\")\n\t\t\treturn errors.Wrap(err, \"Error starting tracing\")\n\t\t}\n\t\tdefer trace.Stop()\n\t}\n\n\tinfo.Log(log)\n\tlogClientOptions(c, log)\n\n\t// this context drives the server, when it's canceled tunnel and all other components (origins, dns, etc...) should stop\n\tctx, cancel := context.WithCancel(c.Context)\n\tdefer cancel()\n\n\tgo waitForSignal(graceShutdownC, log)\n\n\tconnectedSignal := signal.New(make(chan struct{}))\n\tgo notifySystemd(connectedSignal)\n\tif c.IsSet(\"pidfile\") {\n\t\tgo writePidFile(connectedSignal, c.String(\"pidfile\"), log)\n\t}","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/tunnel/cmd.go#L349-L385","documentation":"StartServer optionally enables Go runtime execution tracing when the --trace-output flag points at a file; if trace.Start(tmpTraceFile) fails the error is wrapped as 'Error starting tracing'. trace.Start fails mainly when tracing is already active in this process or the runtime build doesn't support it, so cloudflared aborts startup rather than running without the requested trace.","triggerScenarios":"Running cloudflared with --trace-output=<file> when the Go runtime rejects trace.Start: execution tracing already enabled for the process, or trace.Start returning an error for the opened file (runtime/trace unsupported state). Note the file open itself is handled earlier — this error is specifically from trace.Start.","commonSituations":"Nested cloudflared invocations or wrappers that already started tracing; supplying --trace-output in an environment where runtime tracing was already activated; rare Go runtime/version edge cases around trace startup.","solutions":["Remove the --trace-output flag if you don't need an execution trace — this code path only runs when it is set.","Ensure only one tracing session runs in the process; don't nest cloudflared inside a tool that enabled runtime tracing.","Retry without other tracing activators (e.g. GODEBUG settings) competing for the tracer.","If it persists, check the wrapped inner error for the runtime's specific reason and consider upgrading Go/cloudflared."],"exampleFix":"// before\ncloudflared tunnel run --name mytunnel --trace-output /tmp/trace.out\n\n// after (tracing disabled)\ncloudflared tunnel run --name mytunnel","handlingStrategy":"try-catch","validationCode":"// only pass the flag when tracing is truly needed\nif traceRequested && tracingAlreadyActive() { flags = remove(flags, \"--trace-output\") }","typeGuard":null,"tryCatchPattern":"if err := startServer(); err != nil && strings.Contains(err.Error(), \"Error starting tracing\") {\n    log.Warnf(\"tracing unavailable (%v); retrying without --trace-output\", err)\n    err = startServerWithoutTrace()\n}","preventionTips":["Only set --trace-output when you actually need an execution trace","Avoid nesting cloudflared in wrappers that enable Go runtime tracing themselves","Retry without the flag — it is purely a diagnostics feature","Keep cloudflared/Go toolchain updated to avoid runtime trace edge cases"],"tags":["tracing","diagnostics","go-runtime","cli-flag"],"backgroundTag":"unsupported-operation","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}