elsa-workflows/elsa-core · error · InvalidDataException

The OTLP timestamp is outside the supported range.

Error message

The OTLP timestamp is outside the supported range.

What it means

When parsing OTLP protobuf payloads, 64-bit nanosecond timestamps are converted to DateTimeOffset via ticks added to UnixEpoch inside a checked block. Overflow or a resulting out-of-range value is caught and rethrown as InvalidDataException with this message, keeping the original exception as the inner exception.

Solutions

  1. Inspect the raw OTLP payload and correct or reject records with time_unix_nano values near 0 or outside 1970-10000.
  2. Fix the emitting SDK/exporter clock configuration so timestamps are real epoch nanoseconds.
  3. If malicious/unknown senders are expected, validate the timestamp range client-side before export or reject at the collector boundary.
Defensive patterns

Strategy: validation

Validate before calling

static bool IsPlausibleUnixNano(ulong nano) =>
    nano is > 0 and < 253_402_300_799_999_999_999; // within DateTimeOffset range

Try / catch

try { ParseAndIngest(payload); }
catch (InvalidDataException ex) { logger.LogWarning(ex, "Rejected OTLP payload with out-of-range timestamp."); }

Prevention

When it happens

Trigger: An OTLP record carries time_unix_nano / observed_time_unix_nano values that overflow DateTimeOffset's tick range (negative near-zero values, year-0 or year-10000+ dates) when converted from nanoseconds.

Common situations: Misconfigured SDKs emitting 0 or sentinel timestamps that become extreme dates; clock bugs producing negative durations; third-party exporters writing malformed nano timestamps.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/645b69be7b3fdb56. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.OpenTelemetry/Ingestion/HttpProtobuf/OtlpHttpProtobufParser.cs:566

            .Select(x => x!)
            .Distinct(StringComparer.OrdinalIgnoreCase)
            .ToList();

        return new TelemetryTrace(spans.Key, root.SpanId, root.Name, start, end, end - start, status, orderedSpans.Select(x => x.ResourceId).Distinct(StringComparer.OrdinalIgnoreCase).ToList(), workflowInstanceIds, orderedSpans.Count);
    }

    private static string? GetAttribute(IDictionary<string, string?> attributes, string key) => attributes.TryGetValue(key, out var value) ? value : null;

    private static DateTimeOffset FromUnixNanos(ulong value)
    {
        try
        {
            var ticks = checked((long)(value / 100));
            return DateTimeOffset.UnixEpoch.AddTicks(ticks);
        }
        catch (Exception e) when (e is OverflowException or ArgumentOutOfRangeException)
        {
            throw new InvalidDataException("The OTLP timestamp is outside the supported range.", e);
        }
    }

    private static string ToHex(ReadOnlySpan<byte> bytes)
    {
        return Convert.ToHexString(bytes).ToLowerInvariant();
    }

    private static string SpanKindName(ulong value) => value switch
    {
        1 => "internal",
        2 => "server",
        3 => "client",
        4 => "producer",
        5 => "consumer",
        _ => "unspecified"
    };

View on GitHub (pinned to fe9217bdfa)