🪢 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(otel-mapper): null model props shouldn't cause map to generation (#9308)
Nimarda51c01f3519
diff --git a/packages/shared/src/server/otel/ObservationTypeMapper.ts b/packages/shared/src/server/otel/ObservationTypeMapper.tsindex eafcfe2c14..9614777dee 100644--- a/packages/shared/src/server/otel/ObservationTypeMapper.ts+++ b/packages/shared/src/server/otel/ObservationTypeMapper.ts@@ -33,7 +33,8 @@ class SimpleAttributeMapper implements ObservationTypeMapper {_scopeData?: Record<string, unknown>,): boolean {return (- this.attributeKey in attributes && attributes[this.attributeKey] != null+ this.attributeKey in attributes &&+ hasMeaningfulValue(attributes[this.attributeKey]));}@@ -102,6 +103,20 @@ class CustomAttributeMapper implements ObservationTypeMapper {}}+// value is not null, undefined, empty string, or empty object/array+function hasMeaningfulValue(value: unknown): boolean {+ if (value === null || value === undefined || value === "") {+ return false;+ }+ if (Array.isArray(value)) {+ return value.length > 0;+ }+ if (typeof value === "object" && value !== null) {+ return Object.keys(value).length > 0;+ }+ return true;+}+/*** Registry to manage observation type mappers with a unified interface to map* span attributes to observation types.@@ -240,7 +255,7 @@ export class ObservationTypeMapperRegistry {"llm.model_name","model",];- return modelKeys.some((key) => attributes[key] != null);+ return modelKeys.some((key) => hasMeaningfulValue(attributes[key]));},() => "GENERATION",),diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex b50f293996..abbf3f5d08 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -1444,6 +1444,55 @@ describe("OTel Resource Span Mapping", () => {expect(retrieverEvent?.body.usageDetails.input).toBe(50);});+ it("should map tool-call spans with empty model-related attributes to span-create (not generation-create)", async () => {+ const resourceSpan = {+ scopeSpans: [+ {+ spans: [+ {+ ...defaultSpanProps,+ name: "tool-call",+ attributes: [+ { key: "model", value: { stringValue: "" } },+ { key: "provided_model_name", value: { stringValue: "" } },+ { key: "internal_model_id", value: { stringValue: "" } },+ { key: "model_parameters", value: { stringValue: "{}" } },+ {+ key: "provided_usage_details",+ value: { stringValue: "{}" },+ },+ { key: "usage_details", value: { stringValue: "{}" } },+ {+ key: "provided_cost_details",+ value: { stringValue: "{}" },+ },+ { key: "cost_details", value: { stringValue: "{}" } },+ { key: "total_cost", value: { stringValue: "" } },+ { key: "completion_start_time", value: { stringValue: "" } },+ { key: "prompt_id", value: { stringValue: "" } },+ { key: "prompt_name", value: { stringValue: "" } },+ { key: "prompt_version", value: { stringValue: "" } },+ { key: "token_count", value: { stringValue: "" } },+ ],+ },+ ],+ },+ ],+ };++ const langfuseEvents = await convertOtelSpanToIngestionEvent(+ resourceSpan,+ new Set(),+ );++ const observationEvent = langfuseEvents.find(+ (event) => event.type !== "trace-create",+ );++ // Tool-call spans with empty model-related attributes should remain as span-create+ expect(observationEvent?.type).toBe("span-create");+ });+it("should use logfire.msg as span name", async () => {const resourceSpan = {scopeSpans: [