diff --git a/src/trace/listener.ts b/src/trace/listener.ts index a6c60590..c03fb50c 100644 --- a/src/trace/listener.ts +++ b/src/trace/listener.ts @@ -81,7 +81,7 @@ export class TraceListener { private wrappedCurrentSpan?: SpanWrapper; private triggerTags?: { [key: string]: string }; private lambdaSpanParentContext?: SpanContext; - private spanPointerAttributesList: SpanPointerAttributes[] = []; + private spanPointerAttributesList: SpanPointerAttributes[] | undefined; public get currentTraceHeaders() { return this.contextService.currentTraceHeaders; @@ -137,10 +137,7 @@ export class TraceListener { this.triggerTags = extractTriggerTags(event, context, eventSource); this.stepFunctionContext = StepFunctionContextService.instance().context; - const result = getSpanPointerAttributes(eventSource, event); - if (result) { - this.spanPointerAttributesList = result; - } + this.spanPointerAttributesList = getSpanPointerAttributes(eventSource, event); } /** @@ -204,13 +201,9 @@ export class TraceListener { } } - if (this.wrappedCurrentSpan) { + if (this.wrappedCurrentSpan && this.spanPointerAttributesList) { for (const attributes of this.spanPointerAttributesList) { - this.wrappedCurrentSpan.span.addSpanPointer( - attributes.pointerKind, - attributes.pointerDirection, - attributes.pointerHash, - ); + this.wrappedCurrentSpan.span.addSpanPointer(attributes.kind, attributes.direction, attributes.hash); } } return false; diff --git a/src/utils/span-pointers.spec.ts b/src/utils/span-pointers.spec.ts index 491182ae..3b6974bc 100644 --- a/src/utils/span-pointers.spec.ts +++ b/src/utils/span-pointers.spec.ts @@ -52,9 +52,9 @@ describe("span-pointers utils", () => { const expected: SpanPointerAttributes[] = [ { - pointerKind: S3_PTR_KIND, - pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM, - pointerHash: mockPointerHash, + kind: S3_PTR_KIND, + direction: SPAN_POINTER_DIRECTION.UPSTREAM, + hash: mockPointerHash, }, ]; @@ -91,14 +91,14 @@ describe("span-pointers utils", () => { const expected: SpanPointerAttributes[] = [ { - pointerKind: S3_PTR_KIND, - pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM, - pointerHash: mockPointerHash, + kind: S3_PTR_KIND, + direction: SPAN_POINTER_DIRECTION.UPSTREAM, + hash: mockPointerHash, }, { - pointerKind: S3_PTR_KIND, - pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM, - pointerHash: mockPointerHash, + kind: S3_PTR_KIND, + direction: SPAN_POINTER_DIRECTION.UPSTREAM, + hash: mockPointerHash, }, ]; @@ -139,9 +139,9 @@ describe("span-pointers utils", () => { const expected: SpanPointerAttributes[] = [ { - pointerKind: S3_PTR_KIND, - pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM, - pointerHash: mockPointerHash, + kind: S3_PTR_KIND, + direction: SPAN_POINTER_DIRECTION.UPSTREAM, + hash: mockPointerHash, }, ]; diff --git a/src/utils/span-pointers.ts b/src/utils/span-pointers.ts index 94dba9be..daac15cb 100644 --- a/src/utils/span-pointers.ts +++ b/src/utils/span-pointers.ts @@ -2,9 +2,9 @@ import { eventTypes } from "../trace/trigger"; import { logDebug } from "./log"; export interface SpanPointerAttributes { - pointerKind: string; - pointerDirection: string; - pointerHash: string; + kind: string; + direction: string; + hash: string; } /** @@ -72,9 +72,9 @@ function processS3Event(event: any): SpanPointerAttributes[] { } const pointerHash = generatePointerHash([bucketName, objectKey, eTag]); const spanPointerAttributes: SpanPointerAttributes = { - pointerKind: S3_PTR_KIND, - pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM, - pointerHash, + kind: S3_PTR_KIND, + direction: SPAN_POINTER_DIRECTION.UPSTREAM, + hash: pointerHash, }; spanPointerAttributesList.push(spanPointerAttributes); }