Skip to content

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

infra: add ingestion api attributes to span (#2968)

Max Deichmann06a7a4bfb2d6
diff --git a/web/src/pages/api/public/ingestion.ts b/web/src/pages/api/public/ingestion.ts
index c0d6683cd1..c413096143 100644
--- a/web/src/pages/api/public/ingestion.ts
+++ b/web/src/pages/api/public/ingestion.ts
@@ -13,6 +13,7 @@ import {
type ingestionBatchEvent,
handleBatch,
recordIncrement,
+ getCurrentSpan,
} from "@langfuse/shared/src/server";
import {
SdkLogProcessor,
@@ -76,6 +77,23 @@ export default async function handler(
parsedSchema.success ? parsedSchema.data.batch.length : 0,
);
+ // add context of api call to the span
+ const currentSpan = getCurrentSpan();
+
+ // get x-langfuse-xxx headers and add them to the span
+ Object.keys(req.headers).forEach((header) => {
+ if (header.toLowerCase().startsWith("x-langfuse")) {
+ currentSpan?.setAttributes({
+ [header]: req.headers[header],
+ });
+ }
+ });
+
+ // add number of events to the span
+ parsedSchema.data
+ ? currentSpan?.setAttribute("event_count", parsedSchema.data.batch.length)
+ : undefined;
+
await gaugePrismaStats();
if (!parsedSchema.success) {