elsa-workflows/elsa-core · error · HubException

The OpenTelemetry filter 'from' timestamp must be earlier…

Error message

The OpenTelemetry filter 'from' timestamp must be earlier than or equal to 'to'.

What it means

ValidateFilter normalizes the OpenTelemetryTraceFilter passed to OpenTelemetryHub.SubscribeAsync and enforces chronological consistency: if both From and To timestamps are set and From is later than To, the filter can never match, so a HubException is thrown before subscribing.

Solutions

  1. Swap the values client-side when from > to before subscribing.
  2. Validate the date range in the UI/form before sending the subscribe request.
  3. If only one bound is needed, send only From or To instead of an inverted pair.

Example fix

// before
await hub.SubscribeAsync(new OpenTelemetryTraceFilter { From = to, To = from });

// after
var filter = new OpenTelemetryTraceFilter { From = from, To = to };
if (filter.From > filter.To)
    (filter.From, filter.To) = (filter.To, filter.From);
await hub.SubscribeAsync(filter);
Defensive patterns

Strategy: validation

Validate before calling

if (filter.From is { } f && filter.To is { } t && f > t)
    (filter.From, filter.To) = (t, f); // normalize before subscribing

Try / catch

try { await hub.SubscribeAsync(filter); }
catch (HubException ex) when (ex.Message.Contains("earlier than or equal to"))
{ logger.LogWarning(ex, "Invalid live-trace filter range rejected by hub."); }

Prevention

When it happens

Trigger: Calling SubscribeAsync with a filter where filter.From > filter.To, e.g. a Studio client passing swapped or user-entered date-range values over SignalR.

Common situations: UI sending 'last N minutes' ranges with from/to computed in the wrong order; timezone conversion flipping the range; string dates parsed into DateTimes in inconsistent kinds producing inverted comparisons.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.OpenTelemetry/RealTime/OpenTelemetryHub.cs:38

    }

    public Task UnsubscribeAsync()
    {
        return subscriptionManager.UnsubscribeAsync(Context.ConnectionId);
    }

    public override async Task OnDisconnectedAsync(Exception? exception)
    {
        await UnsubscribeAsync().ConfigureAwait(false);
        await base.OnDisconnectedAsync(exception).ConfigureAwait(false);
    }

    private static OpenTelemetryTraceFilter ValidateFilter(OpenTelemetryTraceFilter? filter)
    {
        filter ??= new();

        if (filter.From is { } from && filter.To is { } to && from > to)
            throw new HubException("The OpenTelemetry filter 'from' timestamp must be earlier than or equal to 'to'.");

        return filter;
    }

    private void EnsureCanReadOpenTelemetry()
    {
        var user = Context.User;

        if (user?.Identity?.IsAuthenticated != true || !PermissionEvaluator.Shared.HasPermission(user, ReadOpenTelemetry))
            throw new HubException("Access denied.");
    }
}

View on GitHub (pinned to fe9217bdfa)