Skip to content

SimpleSpanProcessor forceFlush resolves when export fails #6771

Description

@guilhem

What happened?

SimpleSpanProcessor.forceFlush() resolves even when the underlying exporter reports ExportResultCode.FAILED.

This makes it hard to use SimpleSpanProcessor for fail-closed workflows where the application must know that a span was actually exported before continuing. A concrete example is an admin audit trail: the write should be blocked if the audit span cannot be exported.

I understand that SimpleSpanProcessor is intended to export immediately, and that #5303 fixed waiting for pending exports. The remaining issue is that export failures are still routed through globalErrorHandler, so the pending export promise observed by forceFlush() resolves instead of rejecting.

Minimal reproduction

import { TraceFlags } from "@opentelemetry/api";
import { ExportResultCode } from "@opentelemetry/core";
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";

const exporter = {
  export: (_spans, callback) => {
    callback({
      code: ExportResultCode.FAILED,
      error: new Error("collector unavailable")
    });
  },
  forceFlush: async () => {},
  shutdown: async () => {}
};

const processor = new SimpleSpanProcessor(exporter);
processor.onEnd({
  resource: { asyncAttributesPending: false },
  spanContext: () => ({ traceFlags: TraceFlags.SAMPLED })
} as any);

await processor.forceFlush(); // resolves today

Expected behavior

There should be a native way for callers to know that a SimpleSpanProcessor export failed, ideally by having forceFlush() reject when one of the pending exports failed, or by offering an explicit configuration option for that behavior.

Environment

  • @opentelemetry/sdk-trace-base: 2.7.1
  • @opentelemetry/exporter-trace-otlp-http: 0.218.0
  • Runtime: Node.js / Next.js server instrumentation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions