Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verbatim as the body of the matching GitHub release.

| Version | Date | Notes |
|---|---|---|
| v0.2.11 | 2026-11-24 | [changelog/v0.2.11.md](changelog/v0.2.11.md) |
| v0.2.10 | 2026-11-24 | [changelog/v0.2.10.md](changelog/v0.2.10.md) |
| v0.2.9 | 2026-11-24 | [changelog/v0.2.9.md](changelog/v0.2.9.md) |
| v0.2.8 | 2026-11-24 | [changelog/v0.2.8.md](changelog/v0.2.8.md) |
Expand Down
14 changes: 14 additions & 0 deletions changelog/v0.2.11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# v0.2.11

Request IDs on failed calls.

## Added

- Usage records now store the gateway `X-Request-Id` on successes, cache hits and errors.
- `/admin/usage` and `/v1/usage` expose `request_id`.
- The dashboard **Recent failures** table falls back to the gateway request id when the
upstream provider did not return its own request id.

## Fixed

- Failed calls no longer show `—` in the Request id column.
2 changes: 1 addition & 1 deletion deploy/dokploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ database. The console is always a plain Application.
3. Compose path: `deploy/dokploy/compose.yml`.
4. **Trigger Type: On Tag**, with auto-deploy enabled. The gateway is a production
service; a pull request or a push to `Develop` must not restart it. A release tag
(`v0.2.10`) is the only thing that deploys — see "When it deploys" below.
(`v0.2.11`) is the only thing that deploys — see "When it deploys" below.
5. **Environment** (the compose file references all of these):

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/SPRING-AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on Spring AI; the gateway never depends on it.
<dependency>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-spring-ai</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public Map<String, Object> usage(Long keyId, Long projectId, String endUser, Str
row.put("ttft_ms", r.getTtftMs());
row.put("tokens_per_second", r.getTokensPerSecond());
row.put("upstream_request_id", r.getUpstreamRequestId());
row.put("request_id", r.getRequestId());
row.put("finish_reason", r.getFinishReason());
row.put("attempts", r.getAttempts());
row.put("fallback_from", r.getFallbackFrom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public enum Status {SUCCESS, ERROR}
@Column(length = 128)
private String upstreamRequestId;

/** Gateway correlation id (X-Request-Id), present on both success and error rows. */
@Column(length = 128)
private String requestId;

@Column(length = 32)
private String finishReason;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public BigDecimal recordSuccess(ClientKey key, ChatRequestSpec spec, RouteResolv
record.setTokensPerSecond(throughput(u, meta));
record.setStreamed(meta.streamed());
record.setUpstreamRequestId(meta.requestId());
record.setRequestId(currentRequestId());
record.setFinishReason(meta.finishReason());
record.setAttempts(meta.attempts());
record.setFallbackFrom(meta.fallbackFrom());
Expand Down Expand Up @@ -154,6 +155,7 @@ public void recordCacheHit(ClientKey key, ChatRequestSpec spec, RouteResolver.Re
record.setAttempts(0);
record.setFinishReason("cache");
record.setCacheTier(tier);
record.setRequestId(currentRequestId());
record.setStatus(UsageRecord.Status.SUCCESS);
usage.save(record);
metrics.counter("path.cache.hits",
Expand All @@ -179,6 +181,7 @@ public void recordError(ClientKey key, ChatRequestSpec spec, String providerSlug
record.setStatus(UsageRecord.Status.ERROR);
record.setErrorCode(code);
record.setErrorMessage(message != null && message.length() > 500 ? message.substring(0, 500) : message);
record.setRequestId(currentRequestId());
usage.save(record);
// Kept separate from path_requests_total so an alert can tell a 4xx from a 5xx
// without a high-cardinality label on the request counter.
Expand Down Expand Up @@ -349,6 +352,9 @@ private List<Map<String, Object>> recentRecords(ClientKey key) {
if (r.getUpstreamRequestId() != null) {
row.put("upstream_request_id", r.getUpstreamRequestId());
}
if (r.getRequestId() != null) {
row.put("request_id", r.getRequestId());
}
if (r.getFinishReason() != null) {
row.put("finish_reason", r.getFinishReason());
}
Expand Down Expand Up @@ -452,4 +458,9 @@ private static double percentileOfDecimals(List<BigDecimal> sorted, double p) {
private static long nz(Long value) {
return value == null ? 0L : value;
}

private static String currentRequestId() {
String id = org.slf4j.MDC.get(com.anindra.path.config.RequestIdFilter.MDC_KEY);
return id == null || id.isBlank() ? null : id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table usage_records add column request_id varchar(128);
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.anindra.path.gateway;

import com.anindra.path.config.GatewayProperties;
import com.anindra.path.config.RequestIdFilter;
import com.anindra.path.domain.UsageRecord;
import com.anindra.path.repo.UsageRecordRepository;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.slf4j.MDC;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;

class ErrorMetricsTest {

Expand Down Expand Up @@ -39,4 +44,22 @@ void aMissingCodeIsUnknownRatherThanACardinalityBomb() {
assertThat(registry.counter("path.errors", "provider", "groq",
"class", "5xx", "code", "unknown").count()).isEqualTo(1.0);
}

@Test
void anErrorRecordCarriesTheGatewayRequestId() {
UsageRecordRepository repo = Mockito.mock(UsageRecordRepository.class);
UsageService service = new UsageService(repo, Mockito.mock(ApiKeyService.class),
registry, new GatewayProperties());
MDC.put(RequestIdFilter.MDC_KEY, "req-123");
try {
service.recordError(null, null, "openai", "gpt-4o", 12, false, 1, 500,
"upstream_error", "the provider fell over");
} finally {
MDC.remove(RequestIdFilter.MDC_KEY);
}

ArgumentCaptor<UsageRecord> saved = ArgumentCaptor.forClass(UsageRecord.class);
verify(repo).save(saved.capture());
assertThat(saved.getValue().getRequestId()).isEqualTo("req-123");
}
}
2 changes: 1 addition & 1 deletion path-spring-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
<packaging>pom</packaging>
<name>path-parent</name>
<description>Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter</description>
Expand Down
Loading