pinpoint-apm/pinpoint · error · IllegalStateException

span event end time is not set

Error message

span event end time is not set

What it means

getEndTimeNanos returns the absolute end time in nanos, available only for TRACE_V3 span events whose endTime was explicitly set (not the DEFAULT_END_TIME sentinel). Otherwise the value is undefined and the method throws IllegalStateException.

Solutions

  1. Call hasEndTime() before getEndTimeNanos() and compute the end from parent start + elapsed when absent
  2. Build TRACE_V3 events exclusively with the absolute-time setTraceTime overload
  3. Verify the decode path assigns V3 events both start and end absolute times

Example fix

// before
long end = spanEventBo.getEndTimeNanos();
// after
long end = spanEventBo.hasEndTime()
    ? spanEventBo.getEndTimeNanos()
    : parentStartTime + TimeUnit.MILLISECONDS.toNanos(spanEventBo.getStartElapsed() + spanEventBo.getEndElapsed());
Defensive patterns

Strategy: type-guard

Validate before calling

long end = spanEventBo.hasEndTime()
    ? spanEventBo.getEndTimeNanos()
    : fallbackEndTime(spanEventBo);

Type guard

boolean canReadEndTime(SpanEventBo e) {
    return e.hasEndTime();
}

Try / catch

try {
    return spanEventBo.getEndTimeNanos();
} catch (IllegalStateException e) {
    return parentStartTime + TimeUnit.MILLISECONDS.toNanos(spanEventBo.getStartElapsed() + spanEventBo.getEndElapsed());
}

Prevention

When it happens

Trigger: Calling getEndTimeNanos on a non-TRACE_V3 span event, or a V3 event created with the relative-elapsed overload where endTime remained DEFAULT_END_TIME.

Common situations: UI/collector code computing event durations reading V2 events; callers not checking hasEndTime() first; V3 events decoded through the wrong (relative-time) branch.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/0623eef7f2f632ca. Report an issue: GitHub.

Appendix: source

Thrown at commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanEventBo.java:164

    public boolean hasStartTime() {
        return Byte.toUnsignedInt(version) == SpanVersion.TRACE_V3 && startTime != DEFAULT_START_TIME;
    }

    public long getStartTimeNanos() {
        if (!hasStartTime()) {
            throw new IllegalStateException("span event start time is not set");
        }
        return startTime;
    }

    public boolean hasEndTime() {
        return Byte.toUnsignedInt(version) == SpanVersion.TRACE_V3 && endTime != DEFAULT_END_TIME;
    }

    public long getEndTimeNanos() {
        if (!hasEndTime()) {
            throw new IllegalStateException("span event end time is not set");
        }
        return endTime;
    }

    public int getServiceType() {
        return serviceType;
    }

    public void setServiceType(int serviceType) {
        this.serviceType = serviceType;
    }

    public String getEndPoint() {
        return endPoint;
    }

    public void setEndPoint(String endPoint) {
        this.endPoint = endPoint;

View on GitHub (pinned to 744c3d3075)