From 9381b667b2f83b888e09783b702f2d839353a6cc Mon Sep 17 00:00:00 2001 From: Max Lord Date: Wed, 20 Nov 2024 11:25:44 -0500 Subject: [PATCH] Marking failed paths in google-cloud plugin telemetry --- .../google-cloud/src/gcpOpenTelemetry.ts | 19 ++++++++++++------- js/plugins/google-cloud/tests/traces_test.ts | 12 ++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts index 6fa67cf13..fd725fc67 100644 --- a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts +++ b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts @@ -312,7 +312,7 @@ class AdjustingTraceExporter implements SpanExporter { span = this.redactInputOutput(span); span = this.markErrorSpanAsError(span); - span = this.markFailedAction(span); + span = this.markFailedSpan(span); span = this.markGenkitFeature(span); span = this.markGenkitModel(span); span = this.normalizeLabels(span); @@ -401,20 +401,25 @@ class AdjustingTraceExporter implements SpanExporter { }; } - private markFailedAction(span: ReadableSpan): ReadableSpan { + private markFailedSpan(span: ReadableSpan): ReadableSpan { if ( span.attributes['genkit:state'] === 'error' && (span.attributes['genkit:type'] === 'action' || - span.attributes['genkit:type'] === 'flowStep') && - span.attributes['genkit:name'] + span.attributes['genkit:type'] === 'flowStep' || + span.attributes['genkit:type'] === 'helper') ) { - span.attributes['genkit:failedSpan'] = span.attributes['genkit:name']; + if (!!span.attributes['genkit:name']) { + span.attributes['genkit:failedSpan'] = span.attributes['genkit:name']; + } + if (!!span.attributes['genkit:path']) { + span.attributes['genkit:failedPath'] = span.attributes['genkit:path']; + } } return span; } private markGenkitFeature(span: ReadableSpan): ReadableSpan { - if (span.attributes['genkit:isRoot'] && span.attributes['genkit:name']) { + if (span.attributes['genkit:isRoot'] && !!span.attributes['genkit:name']) { span.attributes['genkit:feature'] = span.attributes['genkit:name']; } return span; @@ -423,7 +428,7 @@ class AdjustingTraceExporter implements SpanExporter { private markGenkitModel(span: ReadableSpan): ReadableSpan { if ( span.attributes['genkit:metadata:subtype'] === 'model' && - span.attributes['genkit:name'] + !!span.attributes['genkit:name'] ) { span.attributes['genkit:model'] = span.attributes['genkit:name']; } diff --git a/js/plugins/google-cloud/tests/traces_test.ts b/js/plugins/google-cloud/tests/traces_test.ts index 902f564b2..a1690bf80 100644 --- a/js/plugins/google-cloud/tests/traces_test.ts +++ b/js/plugins/google-cloud/tests/traces_test.ts @@ -134,9 +134,9 @@ describe('GoogleCloudTracing', () => { assert.equal(spans[1].parentSpanId, undefined); }); - it('labels failed actions', async () => { + it('labels failed spans', async () => { const testFlow = createFlow(ai, 'badFlow', async () => { - return await run('badAction', async () => { + return await run('badStep', async () => { throw new Error('oh no!'); }); }); @@ -146,8 +146,12 @@ describe('GoogleCloudTracing', () => { const spans = await getExportedSpans(); assert.equal(spans.length, 2); - assert.equal(spans[0].name, 'badAction'); - assert.equal(spans[0].attributes['genkit/failedSpan'], 'badAction'); + assert.equal(spans[0].name, 'badStep'); + assert.equal(spans[0].attributes['genkit/failedSpan'], 'badStep'); + assert.equal( + spans[0].attributes['genkit/failedPath'], + '/{badFlow,t:flow}/{badStep,t:flowStep}' + ); }); it('labels the root feature', async () => {