🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix: improve parsing of tags for otel endpoint (#6345)
Steffen Schmitzf831d1ac21c6
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex e08fc55a00..30b28d07f5 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -874,6 +874,60 @@ describe("OTel Resource Span Mapping", () => {entityAttributeValue: "premium",},],+ [+ "should extract tags from single string from langfuse.tags to trace",+ {+ entity: "trace",+ otelAttributeKey: "langfuse.tags",+ otelAttributeValue: {+ stringValue: "2",+ },+ entityAttributeKey: "tags",+ entityAttributeValue: ["2"],+ },+ ],+ [+ "should extract array input on trace event attributes",+ {+ entity: "trace",+ otelAttributeKey: "langfuse.tags",+ otelAttributeValue: {+ arrayValue: {+ values: [+ {+ stringValue: "2",+ },+ ],+ },+ },+ entityAttributeKey: "tags",+ entityAttributeValue: ["2"],+ },+ ],+ [+ "should extract array input tags to trace",+ {+ entity: "trace",+ otelAttributeKey: "langfuse.tags",+ otelAttributeValue: {+ stringValue: '["2"]',+ },+ entityAttributeKey: "tags",+ entityAttributeValue: ["2"],+ },+ ],+ [+ "should extract array csv input tags to trace",+ {+ entity: "trace",+ otelAttributeKey: "langfuse.tags",+ otelAttributeValue: {+ stringValue: "2,3,4",+ },+ entityAttributeKey: "tags",+ entityAttributeValue: ["2", "3", "4"],+ },+ ],])("Attributes: %s",(diff --git a/web/src/features/otel/server/index.ts b/web/src/features/otel/server/index.tsindex 2623601fde..7efda97e30 100644--- a/web/src/features/otel/server/index.ts+++ b/web/src/features/otel/server/index.ts@@ -420,6 +420,47 @@ const extractCostDetails = (return {};};+const extractTags = (+ attributes: Record<string, unknown>,+): string[] => {+ const tagsValue = attributes["langfuse.tags"];++ // If no tags, return empty array+ if (tagsValue === undefined || tagsValue === null) {+ return [];+ }++ // If already an array (converted by convertValueToPlainJavascript)+ if (Array.isArray(tagsValue)) {+ return tagsValue.map(tag => String(tag));+ }++ // If JSON string array+ if (typeof tagsValue === "string" && tagsValue.trim().startsWith("[")) {+ try {+ const parsedTags = JSON.parse(tagsValue);+ if (Array.isArray(parsedTags)) {+ return parsedTags.map(tag => String(tag));+ }+ } catch (e) {+ // If parsing fails, continue with other methods+ }+ }++ // If CSV string+ if (typeof tagsValue === "string" && tagsValue.includes(",")) {+ return tagsValue.split(",").map(tag => tag.trim());+ }++ // If single string value+ if (typeof tagsValue === "string") {+ return [tagsValue];+ }++ // Fallback to empty array+ return [];+};+/*** Accepts an OpenTelemetry resourceSpan from a ExportTraceServiceRequest and* returns a list of Langfuse events.@@ -476,7 +517,7 @@ export const convertOtelSpanToIngestionEvent = (public:attributes?.["langfuse.public"] === true ||attributes?.["langfuse.public"] === "true",- tags: attributes?.["langfuse.tags"] ?? [],+ tags: extractTags(attributes),environment: extractEnvironment(attributes, resourceAttributes),