Skip to content

Commit 86f72ff

Browse files
committed
lint
1 parent 4f31750 commit 86f72ff

File tree

2 files changed

+49
-54
lines changed

2 files changed

+49
-54
lines changed

src/trace/context.spec.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ describe("readStepFunctionContextFromEvent", () => {
671671
Execution: {
672672
Id: "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf",
673673
Input: {
674-
MyInput: "MyValue"
674+
MyInput: "MyValue",
675675
},
676676
Name: "85a9933e-9e11-83dc-6a61-b92367b6c3be",
677677
RoleArn: "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03",
@@ -691,10 +691,12 @@ describe("readStepFunctionContextFromEvent", () => {
691691
it("reads a step function context from event with Execution.Input", () => {
692692
const result = readStepFunctionContextFromEvent(stepFunctionEvent);
693693
expect(result).toEqual({
694-
"step_function.execution_id": "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf",
695-
"step_function.execution_input": { "MyInput": "MyValue" },
694+
"step_function.execution_id":
695+
"arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf",
696+
"step_function.execution_input": { MyInput: "MyValue" },
696697
"step_function.execution_name": "85a9933e-9e11-83dc-6a61-b92367b6c3be",
697-
"step_function.execution_role_arn": "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03",
698+
"step_function.execution_role_arn":
699+
"arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03",
698700
"step_function.execution_start_time": "2022-12-08T21:08:17.924Z",
699701
"step_function.state_entered_time": "2022-12-08T21:08:19.224Z",
700702
"step_function.state_machine_arn": "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential",
@@ -1071,25 +1073,25 @@ describe("extractTraceContext", () => {
10711073

10721074
it("adds step function metadata to xray", () => {
10731075
const stepFunctionEvent = {
1074-
Execution: {
1075-
Id: "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf",
1076-
Name: "85a9933e-9e11-83dc-6a61-b92367b6c3be",
1077-
RoleArn: "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03",
1078-
StartTime: "2022-12-08T21:08:17.924Z",
1079-
Input: {
1080-
MyInput: "MyValue"
1081-
}
1082-
},
1083-
State: {
1084-
Name: "step-one",
1085-
EnteredTime: "2022-12-08T21:08:19.224Z",
1086-
RetryCount: 2,
1087-
},
1088-
StateMachine: {
1089-
Id: "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential",
1090-
Name: "my-state-machine",
1091-
},
1092-
} as const;
1076+
Execution: {
1077+
Id: "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf",
1078+
Name: "85a9933e-9e11-83dc-6a61-b92367b6c3be",
1079+
RoleArn: "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03",
1080+
StartTime: "2022-12-08T21:08:17.924Z",
1081+
Input: {
1082+
MyInput: "MyValue",
1083+
},
1084+
},
1085+
State: {
1086+
Name: "step-one",
1087+
EnteredTime: "2022-12-08T21:08:19.224Z",
1088+
RetryCount: 2,
1089+
},
1090+
StateMachine: {
1091+
Id: "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential",
1092+
Name: "my-state-machine",
1093+
},
1094+
} as const;
10931095

10941096
jest.spyOn(Date, "now").mockImplementation(() => 1487076708000);
10951097
process.env[xrayTraceEnvVar] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1";

src/trace/context.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import {
2-
Context,
3-
EventBridgeEvent,
4-
KinesisStreamEvent,
5-
SNSEvent,
6-
SNSMessage,
7-
SQSEvent
8-
} from "aws-lambda";
9-
import {BigNumber} from "bignumber.js";
10-
import {randomBytes} from "crypto";
11-
import {createSocket, Socket} from "dgram";
12-
import {logDebug, logError} from "../utils";
1+
import { Context, EventBridgeEvent, KinesisStreamEvent, SNSEvent, SNSMessage, SQSEvent } from "aws-lambda";
2+
import { BigNumber } from "bignumber.js";
3+
import { randomBytes } from "crypto";
4+
import { createSocket, Socket } from "dgram";
5+
import { logDebug, logError } from "../utils";
136
import {
147
isAppSyncResolverEvent,
158
isEventBridgeEvent,
@@ -33,8 +26,8 @@ import {
3326
xraySubsegmentNamespace,
3427
xrayTraceEnvVar,
3528
} from "./constants";
36-
import {TraceExtractor} from "./listener";
37-
import {eventSubTypes, parseEventSourceSubType} from "./trigger";
29+
import { TraceExtractor } from "./listener";
30+
import { eventSubTypes, parseEventSourceSubType } from "./trigger";
3831

3932
export interface XRayTraceHeader {
4033
traceID: string;
@@ -50,11 +43,11 @@ export interface TraceContext {
5043
}
5144

5245
export interface StepFunctionContext {
53-
"step_function.execution_name": string,
54-
"step_function.execution_id": string,
55-
"step_function.execution_input": object,
56-
"step_function.execution_role_arn": string,
57-
"step_function.execution_start_time": string,
46+
"step_function.execution_name": string;
47+
"step_function.execution_id": string;
48+
"step_function.execution_input": object;
49+
"step_function.execution_role_arn": string;
50+
"step_function.execution_start_time": string;
5851
"step_function.state_machine_name": string;
5952
"step_function.state_machine_arn": string;
6053
"step_function.state_entered_time": string;
@@ -505,60 +498,60 @@ export function readStepFunctionContextFromEvent(event: any): StepFunctionContex
505498
}
506499
const executionID = execution.Id;
507500
if (typeof executionID !== "string") {
508-
logDebug("event.Execution.Id is not a string.")
501+
logDebug("event.Execution.Id is not a string.");
509502
return;
510503
}
511504
const executionInput = execution.Input;
512505
const executionName = execution.Name;
513506
if (typeof executionName !== "string") {
514-
logDebug("event.Execution.Name is not a string.")
507+
logDebug("event.Execution.Name is not a string.");
515508
return;
516509
}
517510
const executionRoleArn = execution.RoleArn;
518511
if (typeof executionRoleArn !== "string") {
519-
logDebug("event.Execution.RoleArn is not a string.")
512+
logDebug("event.Execution.RoleArn is not a string.");
520513
return;
521514
}
522515
const executionStartTime = execution.StartTime;
523516
if (typeof executionStartTime !== "string") {
524-
logDebug("event.Execution.StartTime is not a string.")
517+
logDebug("event.Execution.StartTime is not a string.");
525518
return;
526519
}
527520

528521
const state = event.State;
529522
if (typeof state !== "object") {
530-
logDebug("event.State is not an object.")
523+
logDebug("event.State is not an object.");
531524
return;
532525
}
533526
const stateRetryCount = state.RetryCount;
534527
if (typeof stateRetryCount !== "number") {
535-
logDebug("event.State.RetryCount is not a string.")
528+
logDebug("event.State.RetryCount is not a string.");
536529
return;
537530
}
538531
const stateEnteredTime = state.EnteredTime;
539532
if (typeof stateEnteredTime !== "string") {
540-
logDebug("event.State.EnteredTime is not a string.")
533+
logDebug("event.State.EnteredTime is not a string.");
541534
return;
542535
}
543536
const stateName = state.Name;
544537
if (typeof stateName !== "string") {
545-
logDebug("event.State.Name is not a string.")
538+
logDebug("event.State.Name is not a string.");
546539
return;
547540
}
548541

549542
const stateMachine = event.StateMachine;
550543
if (typeof stateMachine !== "object") {
551-
logDebug("event.StateMachine is not an object.")
544+
logDebug("event.StateMachine is not an object.");
552545
return;
553546
}
554547
const stateMachineArn = stateMachine.Id;
555548
if (typeof stateMachineArn !== "string") {
556-
logDebug("event.StateMachine.Id is not a string.")
549+
logDebug("event.StateMachine.Id is not a string.");
557550
return;
558551
}
559552
const stateMachineName = stateMachine.Name;
560553
if (typeof stateMachineName !== "string") {
561-
logDebug("event.StateMachine.Name is not a string.")
554+
logDebug("event.StateMachine.Name is not a string.");
562555
return;
563556
}
564557

@@ -572,7 +565,7 @@ export function readStepFunctionContextFromEvent(event: any): StepFunctionContex
572565
"step_function.state_machine_arn": stateMachineArn,
573566
"step_function.state_machine_name": stateMachineName,
574567
"step_function.state_name": stateName,
575-
"step_function.state_retry_count": stateRetryCount
568+
"step_function.state_retry_count": stateRetryCount,
576569
};
577570
}
578571

0 commit comments

Comments
 (0)