Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: avoid read after end errors in otel ingest (#9754)

Steffen Schmitz9f5b4cf787fd
diff --git a/web/src/pages/api/public/otel/v1/traces/index.ts b/web/src/pages/api/public/otel/v1/traces/index.ts
index 0763b5125b..bc14a10670 100644
--- a/web/src/pages/api/public/otel/v1/traces/index.ts
+++ b/web/src/pages/api/public/otel/v1/traces/index.ts
@@ -36,7 +36,8 @@ export default withMiddlewares({
});
} catch (e) {
logger.error(`Failed to read request body`, e);
- return res.status(400).json({ error: "Failed to read request body" });
+ res.status(400);
+ return { error: "Failed to read request body" };
}
if (req.headers["content-encoding"]?.includes("gzip")) {
@@ -48,9 +49,8 @@ export default withMiddlewares({
});
} catch (e) {
logger.error(`Failed to decompress request body`, e);
- return res
- .status(400)
- .json({ error: "Failed to decompress request body" });
+ res.status(400);
+ return { error: "Failed to decompress request body" };
}
}
@@ -62,7 +62,9 @@ export default withMiddlewares({
(!contentType.includes("application/json") &&
!contentType.includes("application/x-protobuf"))
) {
- return res.status(400).json({ error: "Invalid content type" });
+ logger.error(`Invalid content type: ${contentType}`);
+ res.status(400);
+ return { error: "Invalid content type" };
}
if (contentType.includes("application/x-protobuf")) {
try {
@@ -76,9 +78,8 @@ export default withMiddlewares({
).resourceSpans;
} catch (e) {
logger.error(`Failed to parse OTel Protobuf`, e);
- return res
- .status(400)
- .json({ error: "Failed to parse OTel Protobuf Trace" });
+ res.status(400);
+ return { error: "Failed to parse OTel Protobuf Trace" };
}
}
if (contentType.includes("application/json")) {
@@ -86,14 +87,13 @@ export default withMiddlewares({
resourceSpans = JSON.parse(body.toString()).resourceSpans;
} catch (e) {
logger.error(`Failed to parse OTel JSON`, e);
- return res
- .status(400)
- .json({ error: "Failed to parse OTel JSON Trace" });
+ res.status(400);
+ return { error: "Failed to parse OTel JSON Trace" };
}
}
if (!resourceSpans || resourceSpans.length === 0) {
- return res.status(200).json({});
+ return {};
}
const processor = new OtelIngestionProcessor({