{"record":{"id":"3887cb08a3df2a30","repo":"dbt-labs/dbt-core","slug":"generic","errorCode":"Generic","errorMessage":"Failed to detach invocation telemetry layers: {}","messagePattern":"Failed to detach invocation telemetry layers: (.+?)","errorType":"error_code","errorClass":"FsError","httpStatus":null,"severity":"warning","filePath":"crates/dbt-common/src/tracing/dbt_init.rs","lineNumber":216,"sourceCode":"        if errors.is_empty() {\n            Ok(())\n        } else {\n            Err(errors)\n        }\n    }\n\n    fn teardown(&mut self) -> Vec<FsError> {\n        // Set before the work, not after: a panicking shutdown would otherwise be retried\n        // during unwinding, and a second panic there aborts the process.\n        if self.finished {\n            return Vec::new();\n        }\n        self.finished = true;\n\n        let mut errors: Vec<FsError> = self\n            .shutdown_items\n            .iter_mut()\n            .filter_map(|item| item.shutdown().err().map(FsError::from))\n            .collect();\n\n        if let Err(e) = self.reload_handle.reload_telemetry(vec![], vec![]) {\n            errors.push(*fs_err!(\n                ErrorCode::Generic,\n                \"Failed to detach invocation telemetry layers: {}\",\n                e\n            ));\n        }\n\n        errors\n    }\n}\n\nimpl Drop for InvocationTracingGuard {\n    fn drop(&mut self) {\n        // Shutting the items down here is load-bearing, not a redundant backstop: the file\n        // and parquet writers do flush via their own handles' `Drop`, but OTLP does not —","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-common/src/tracing/dbt_init.rs#L198-L234","documentation":"During tracing teardown, the dbt runtime detaches per-invocation telemetry layers via the tracing reload handle. If reload_telemetry(vec![], vec![]) fails, the FsError is collected and reported with this message. It means invocation-scoped log/trace layers could not be removed — usually a symptom of a telemetry-subscriber internal problem, not of user input.","triggerScenarios":"Calling finish() or dropping the teardown guard when the reload handle's subscriber no longer matches the registered layers (already torn down, reinitialized subscriber, or a poisoned reload registry).","commonSituations":"Double-initialization of the tracing subscriber in the same process (e.g. tests calling dbt init twice); a shutdown ordering bug where layers were already dropped; running under a custom subscriber that replaced dbt's.","solutions":["Check the interpolated {} detail in the message for the underlying reload failure","Ensure dbt's tracing init/teardown runs exactly once per process invocation","Look for other errors logged before this one during shutdown_items shutdown; fix the root cause there","If seen in tests, isolate subscriber initialization per test or use a serial test harness"],"exampleFix":"// before\nlet mut telemetry = TeardownGuard::new();\nlet mut telemetry2 = TeardownGuard::new(); // second init corrupts reload handle\n// after\nlet mut telemetry = TeardownGuard::new();\n// ... single teardown at process end\ntelemetry.finish();","handlingStrategy":"try-catch","validationCode":"// ensure telemetry is initialized exactly once\nstatic INIT: Once = Once::new();\nINIT.call_once(init_dbt_tracing);","typeGuard":"fn telemetry_active(handle: &ReloadHandle) -> bool { handle.is_initialized() }","tryCatchPattern":"if let Err(e) = self.reload_handle.reload_telemetry(vec![], vec![]) {\n    log::warn!(\"telemetry detach failed (non-fatal): {e}\");\n}","preventionTips":["Initialize tracing once per process","Check earlier shutdown errors as the likely root cause","Avoid swapping the global subscriber externally while dbt runs"],"tags":["telemetry","tracing","shutdown","rust"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}