{"record":{"id":"65513da7cc78f54d","repo":"apache/seatunnel","slug":"unable-to-initialize-metrics-context-for-file-sour","errorCode":null,"errorMessage":"Unable to initialize metrics context for file source enumerator.","messagePattern":"Unable to initialize metrics context for file source enumerator\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/split/ContinuousMultipleTableFileSourceSplitEnumerator.java","lineNumber":156,"sourceCode":"            FileSplitStrategy fileSplitStrategy) {\n        this(\n                context,\n                multipleTableFileSourceConfig,\n                fileSplitStrategy,\n                new FileSourceState(new HashSet<>()));\n    }\n\n    public ContinuousMultipleTableFileSourceSplitEnumerator(\n            Context<FileSourceSplit> context,\n            BaseMultipleTableFileSourceConfig multipleTableFileSourceConfig,\n            FileSplitStrategy fileSplitStrategy,\n            FileSourceState checkpointState) {\n        this.context = context;\n        MetricsContext metricsContext = null;\n        try {\n            metricsContext = context.getMetricsContext();\n        } catch (Exception e) {\n            log.warn(\"Unable to initialize metrics context for file source enumerator.\", e);\n        }\n        this.postSyncSubmittedCounter = initCounter(metricsContext, METRIC_POST_SYNC_SUBMITTED);\n        this.postSyncSucceededCounter = initCounter(metricsContext, METRIC_POST_SYNC_SUCCEEDED);\n        this.postSyncFailedCounter = initCounter(metricsContext, METRIC_POST_SYNC_FAILED);\n        this.postSyncStaleSkippedCounter =\n                initCounter(metricsContext, METRIC_POST_SYNC_STALE_SKIPPED);\n        this.retentionDeletedCounter = initCounter(metricsContext, METRIC_RETENTION_DELETED);\n        this.retentionFailedCounter = initCounter(metricsContext, METRIC_RETENTION_FAILED);\n\n        this.jobStartTimeMillis =\n                checkpointState.getDiscoveryStartTimeMillis() > 0\n                        ? checkpointState.getDiscoveryStartTimeMillis()\n                        : System.currentTimeMillis();\n        Set<FileSourceSplit> restoredInFlightSplits =\n                new HashSet<>(checkpointState.getAssignedSplit());\n        this.inFlightSplits = new HashSet<>();\n\n        List<BaseFileSourceConfig> fileSourceConfigs =","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/split/ContinuousMultipleTableFileSourceSplitEnumerator.java#L138-L174","documentation":"The ContinuousMultipleTableFileSourceSplitEnumerator constructor tries to obtain a MetricsContext from the enumerator context to initialize its post-sync counters. If context.getMetricsContext() throws any exception, it logs this warning, keeps metricsContext as null, and continues. The counters become inert (initCounter handles null), so metrics reporting for post-sync operations is lost but the job still runs.","triggerScenarios":"Constructing the enumerator with a context whose getMetricsContext() throws — e.g. an engine/runtime version or test harness that does not provide a metrics context, or a metrics subsystem initialization failure in the runtime.","commonSituations":"Running the continuous file source on a runtime where the metrics context API is unavailable or not wired; unit-test contexts that throw from getMetricsContext; engine upgrades changing the metrics SPI.","solutions":["Check the wrapped exception (logged with this warning) to find why getMetricsContext() threw and fix the runtime/metrics configuration","Upgrade or align the SeaTunnel engine version so the metrics context is provided to split enumerators","Ignore safely if metrics are not needed — the enumerator continues with null counters"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"// Treat metrics as optional everywhere\nif (metricsContext != null) {\n    counter = metricsContext.getCounter(name);\n} else {\n    counter = noopCounter;\n}","tryCatchPattern":"try {\n    metricsContext = context.getMetricsContext();\n} catch (Exception e) {\n    log.warn(\"Unable to initialize metrics context for file source enumerator.\", e);\n    metricsContext = null; // counters degrade to no-ops\n}","preventionTips":["Run on an engine/runtime version that provides MetricsContext to split enumerators","When writing test harnesses, implement getMetricsContext() instead of throwing","Treat missing metrics as non-fatal and monitor for this warning to catch wiring regressions"],"tags":["file-connector","metrics","split-enumerator"],"backgroundTag":"module-init-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}