Skip to content

Commit

Permalink
Code review improvements 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 26, 2024
1 parent 0d1aecb commit 6fab017
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
15 changes: 6 additions & 9 deletions src/trace/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -204,12 +201,12 @@ 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,
attributes.kind,
attributes.direction,
attributes.hash,
);
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/utils/span-pointers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];

Expand Down Expand Up @@ -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,
},
];

Expand Down Expand Up @@ -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,
},
];

Expand Down
12 changes: 6 additions & 6 deletions src/utils/span-pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6fab017

Please sign in to comment.