{"record":{"id":"d482b89c946e50b5","repo":"apache/seatunnel","slug":"already-an-mdcconsumer","errorCode":null,"errorMessage":"Already an MDCConsumer","messagePattern":"Already an MDCConsumer","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java","lineNumber":143,"sourceCode":"    public static MDCScheduledExecutorService tracing(\n            MDCContext context, ScheduledExecutorService delegate) {\n        if (delegate instanceof MDCExecutor) {\n            throw new IllegalArgumentException(\"Already an MDCExecutor\");\n        }\n        return new MDCScheduledExecutorService(context, delegate);\n    }\n\n    public static <T> MDCConsumer<T> tracing(Consumer<T> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T> MDCConsumer<T> tracing(Long jobId, Consumer<T> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\n    public static <T> MDCConsumer<T> tracing(MDCContext context, Consumer<T> delegate) {\n        if (delegate instanceof MDCConsumer) {\n            throw new IllegalArgumentException(\"Already an MDCConsumer\");\n        }\n        return new MDCConsumer<>(context, delegate);\n    }\n\n    public static <T, R> MDCFunction<T, R> tracing(Function<T, R> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T, R> MDCFunction<T, R> tracing(Long jobId, Function<T, R> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\n    public static <T, R> MDCFunction<T, R> tracing(MDCContext context, Function<T, R> delegate) {\n        if (delegate instanceof MDCFunction) {\n            throw new IllegalArgumentException(\"Already an MDCFunction\");\n        }\n        return new MDCFunction<>(context, delegate);\n    }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java#L125-L161","documentation":"MDCTracer.tracing(context, Consumer) rejects a delegate already wrapped as MDCConsumer with IllegalArgumentException. Double wrapping would capture and restore MDC state twice around a single consumer invocation.","triggerScenarios":"Calling tracing(jobId, consumer) or tracing(context, consumer) where consumer is already an MDCConsumer produced by an earlier tracing() call, e.g. wrapping sink record consumers twice.","commonSituations":"Sink/committer pipelines where both a generic wrapper and a connector-specific wrapper apply tracing to the same Consumer.","solutions":["Apply tracing at one layer only and pass the MDCConsumer down as-is","Guard: `if (c instanceof MDCConsumer) use it else tracing(...)`","Remove the redundant tracing call in the inner layer"],"exampleFix":"// before\nMDCConsumer<T> c = MDCTracer.tracing(jobId, MDCTracer.tracing(jobId, consumer));\n// after\nMDCConsumer<T> c = MDCTracer.tracing(jobId, consumer);","handlingStrategy":"type-guard","validationCode":"MDCConsumer<T> safeWrap(Long jobId, Consumer<T> c) {\n    return c instanceof MDCConsumer ? (MDCConsumer<T>) c : MDCTracer.tracing(jobId, c);\n}","typeGuard":"boolean isWrapped(Consumer<?> c) {\n    return c instanceof MDCConsumer;\n}","tryCatchPattern":"try {\n    return MDCTracer.tracing(jobId, consumer);\n} catch (IllegalArgumentException e) {\n    return (MDCConsumer<T>) consumer;\n}","preventionTips":["Wrap consumers at one pipeline layer only","Do not re-trace consumers handed to you by other components","Add an instanceof MDCConsumer pass-through in wrapper utilities"],"tags":["java","mdc","tracing","double-wrap"],"backgroundTag":"invalid-argument-value","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}