apache/seatunnel · warning

Unable to initialize metrics context for file source enumera

Error message

Unable to initialize metrics context for file source enumerator.

What it means

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.

Source

Thrown at seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/split/ContinuousMultipleTableFileSourceSplitEnumerator.java:156

            FileSplitStrategy fileSplitStrategy) {
        this(
                context,
                multipleTableFileSourceConfig,
                fileSplitStrategy,
                new FileSourceState(new HashSet<>()));
    }

    public ContinuousMultipleTableFileSourceSplitEnumerator(
            Context<FileSourceSplit> context,
            BaseMultipleTableFileSourceConfig multipleTableFileSourceConfig,
            FileSplitStrategy fileSplitStrategy,
            FileSourceState checkpointState) {
        this.context = context;
        MetricsContext metricsContext = null;
        try {
            metricsContext = context.getMetricsContext();
        } catch (Exception e) {
            log.warn("Unable to initialize metrics context for file source enumerator.", e);
        }
        this.postSyncSubmittedCounter = initCounter(metricsContext, METRIC_POST_SYNC_SUBMITTED);
        this.postSyncSucceededCounter = initCounter(metricsContext, METRIC_POST_SYNC_SUCCEEDED);
        this.postSyncFailedCounter = initCounter(metricsContext, METRIC_POST_SYNC_FAILED);
        this.postSyncStaleSkippedCounter =
                initCounter(metricsContext, METRIC_POST_SYNC_STALE_SKIPPED);
        this.retentionDeletedCounter = initCounter(metricsContext, METRIC_RETENTION_DELETED);
        this.retentionFailedCounter = initCounter(metricsContext, METRIC_RETENTION_FAILED);

        this.jobStartTimeMillis =
                checkpointState.getDiscoveryStartTimeMillis() > 0
                        ? checkpointState.getDiscoveryStartTimeMillis()
                        : System.currentTimeMillis();
        Set<FileSourceSplit> restoredInFlightSplits =
                new HashSet<>(checkpointState.getAssignedSplit());
        this.inFlightSplits = new HashSet<>();

        List<BaseFileSourceConfig> fileSourceConfigs =

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check the wrapped exception (logged with this warning) to find why getMetricsContext() threw and fix the runtime/metrics configuration
  2. Upgrade or align the SeaTunnel engine version so the metrics context is provided to split enumerators
  3. Ignore safely if metrics are not needed — the enumerator continues with null counters
Defensive patterns

Strategy: fallback

Type guard

// Treat metrics as optional everywhere
if (metricsContext != null) {
    counter = metricsContext.getCounter(name);
} else {
    counter = noopCounter;
}

Try / catch

try {
    metricsContext = context.getMetricsContext();
} catch (Exception e) {
    log.warn("Unable to initialize metrics context for file source enumerator.", e);
    metricsContext = null; // counters degrade to no-ops
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/65513da7cc78f54d. Report an issue: GitHub.