Skip to content

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

fix: support gzip encoding on otel endpoint (#5710)

Steffen Schmitz668ca24d5ece
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 9a772e0428..15f02d188a 100644
--- a/web/src/pages/api/public/otel/v1/traces/index.ts
+++ b/web/src/pages/api/public/otel/v1/traces/index.ts
@@ -8,6 +8,7 @@ import {
import { z } from "zod";
import { $root } from "@/src/pages/api/public/otel/otlp-proto/generated/root";
import { convertOtelSpanToIngestionEvent } from "@/src/features/otel/server";
+import { gunzip } from "node:zlib";
export const config = {
api: {
@@ -36,6 +37,21 @@ export default withMiddlewares({
return res.status(400).json({ error: "Failed to read request body" });
}
+ if (req.headers["content-encoding"]?.includes("gzip")) {
+ try {
+ body = await new Promise((resolve, reject) => {
+ gunzip(body, (err, result) =>
+ err ? reject(err) : resolve(result),
+ );
+ });
+ } catch (e) {
+ logger.error(`Failed to decompress request body`, e);
+ return res
+ .status(400)
+ .json({ error: "Failed to decompress request body" });
+ }
+ }
+
let resourceSpans: any;
const contentType = req.headers["content-type"]?.toLowerCase();
// Strict content-type matching does not work if something like `content-type: text/javascript; charset=utf-8` is sent.