Skip to content

Commit 44b737a

Browse files
committed
Code review improvements 2
1 parent 0d1aecb commit 44b737a

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

src/trace/listener.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class TraceListener {
8181
private wrappedCurrentSpan?: SpanWrapper;
8282
private triggerTags?: { [key: string]: string };
8383
private lambdaSpanParentContext?: SpanContext;
84-
private spanPointerAttributesList: SpanPointerAttributes[] = [];
84+
private spanPointerAttributesList: SpanPointerAttributes[] | undefined;
8585

8686
public get currentTraceHeaders() {
8787
return this.contextService.currentTraceHeaders;
@@ -137,10 +137,7 @@ export class TraceListener {
137137
this.triggerTags = extractTriggerTags(event, context, eventSource);
138138
this.stepFunctionContext = StepFunctionContextService.instance().context;
139139

140-
const result = getSpanPointerAttributes(eventSource, event);
141-
if (result) {
142-
this.spanPointerAttributesList = result;
143-
}
140+
this.spanPointerAttributesList = getSpanPointerAttributes(eventSource, event);
144141
}
145142

146143
/**
@@ -204,13 +201,9 @@ export class TraceListener {
204201
}
205202
}
206203

207-
if (this.wrappedCurrentSpan) {
204+
if (this.wrappedCurrentSpan && this.spanPointerAttributesList) {
208205
for (const attributes of this.spanPointerAttributesList) {
209-
this.wrappedCurrentSpan.span.addSpanPointer(
210-
attributes.pointerKind,
211-
attributes.pointerDirection,
212-
attributes.pointerHash,
213-
);
206+
this.wrappedCurrentSpan.span.addSpanPointer(attributes.kind, attributes.direction, attributes.hash);
214207
}
215208
}
216209
return false;

src/utils/span-pointers.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ describe("span-pointers utils", () => {
5252

5353
const expected: SpanPointerAttributes[] = [
5454
{
55-
pointerKind: S3_PTR_KIND,
56-
pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM,
57-
pointerHash: mockPointerHash,
55+
kind: S3_PTR_KIND,
56+
direction: SPAN_POINTER_DIRECTION.UPSTREAM,
57+
hash: mockPointerHash,
5858
},
5959
];
6060

@@ -91,14 +91,14 @@ describe("span-pointers utils", () => {
9191

9292
const expected: SpanPointerAttributes[] = [
9393
{
94-
pointerKind: S3_PTR_KIND,
95-
pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM,
96-
pointerHash: mockPointerHash,
94+
kind: S3_PTR_KIND,
95+
direction: SPAN_POINTER_DIRECTION.UPSTREAM,
96+
hash: mockPointerHash,
9797
},
9898
{
99-
pointerKind: S3_PTR_KIND,
100-
pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM,
101-
pointerHash: mockPointerHash,
99+
kind: S3_PTR_KIND,
100+
direction: SPAN_POINTER_DIRECTION.UPSTREAM,
101+
hash: mockPointerHash,
102102
},
103103
];
104104

@@ -139,9 +139,9 @@ describe("span-pointers utils", () => {
139139

140140
const expected: SpanPointerAttributes[] = [
141141
{
142-
pointerKind: S3_PTR_KIND,
143-
pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM,
144-
pointerHash: mockPointerHash,
142+
kind: S3_PTR_KIND,
143+
direction: SPAN_POINTER_DIRECTION.UPSTREAM,
144+
hash: mockPointerHash,
145145
},
146146
];
147147

src/utils/span-pointers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { eventTypes } from "../trace/trigger";
22
import { logDebug } from "./log";
33

44
export interface SpanPointerAttributes {
5-
pointerKind: string;
6-
pointerDirection: string;
7-
pointerHash: string;
5+
kind: string;
6+
direction: string;
7+
hash: string;
88
}
99

1010
/**
@@ -72,9 +72,9 @@ function processS3Event(event: any): SpanPointerAttributes[] {
7272
}
7373
const pointerHash = generatePointerHash([bucketName, objectKey, eTag]);
7474
const spanPointerAttributes: SpanPointerAttributes = {
75-
pointerKind: S3_PTR_KIND,
76-
pointerDirection: SPAN_POINTER_DIRECTION.UPSTREAM,
77-
pointerHash,
75+
kind: S3_PTR_KIND,
76+
direction: SPAN_POINTER_DIRECTION.UPSTREAM,
77+
hash: pointerHash,
7878
};
7979
spanPointerAttributesList.push(spanPointerAttributes);
8080
}

0 commit comments

Comments
 (0)