Skip to content

Commit 081a514

Browse files
authored
refactor(tracer): fix code quality issues (#4264)
Co-authored-by: David <[email protected]>
1 parent 5ef5c85 commit 081a514

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

packages/tracer/src/Tracer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,6 @@ class Tracer extends Utility implements TracerInterface {
822822

823823
if (this.#envConfig.captureHTTPsRequests.toLowerCase() === 'false') {
824824
this.captureHTTPsRequests = false;
825-
return;
826825
}
827826
}
828827

@@ -868,7 +867,7 @@ class Tracer extends Utility implements TracerInterface {
868867
*
869868
* @param options - Configuration passed to the tracer
870869
*/
871-
private setOptions(options: TracerOptions): Tracer {
870+
private setOptions(options: TracerOptions): this {
872871
const { enabled, serviceName, captureHTTPsRequests, customConfigService } =
873872
options;
874873

packages/tracer/tests/unit/Tracer.test.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,7 @@ describe('Class: Tracer', () => {
692692
.mockImplementation(() => ({}));
693693

694694
// Act
695-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
696-
'## foo.bar'
697-
);
695+
const newSubsegment = new Subsegment('## foo.bar');
698696
tracer.setSegment(newSubsegment);
699697

700698
// Assess
@@ -961,9 +959,7 @@ describe('Class: Tracer', () => {
961959
it('awaits async methods correctly', async () => {
962960
// Prepare
963961
const tracer: Tracer = new Tracer();
964-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
965-
'### dummyMethod'
966-
);
962+
const newSubsegment = new Subsegment('### dummyMethod');
967963

968964
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
969965
() => newSubsegment
@@ -975,7 +971,7 @@ describe('Class: Tracer', () => {
975971
createCaptureAsyncFuncMock(tracer.provider, newSubsegment);
976972

977973
class Lambda implements LambdaInterface {
978-
private memberVariable: string;
974+
private readonly memberVariable: string;
979975

980976
public constructor(memberVariable: string) {
981977
this.memberVariable = memberVariable;
@@ -1021,8 +1017,7 @@ describe('Class: Tracer', () => {
10211017
it('catches the error and logs a warning when a segment fails to close/serialize', async () => {
10221018
// Prepare
10231019
const tracer: Tracer = new Tracer();
1024-
const handlerSubsegment: Segment | Subsegment | undefined =
1025-
new Subsegment('### dummyMethod');
1020+
const handlerSubsegment = new Subsegment('### dummyMethod');
10261021
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
10271022
() => handlerSubsegment
10281023
);
@@ -1192,9 +1187,7 @@ describe('Class: Tracer', () => {
11921187
it('captures the exception correctly', async () => {
11931188
// Prepare
11941189
const tracer: Tracer = new Tracer();
1195-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
1196-
'### dummyMethod'
1197-
);
1190+
const newSubsegment = new Subsegment('### dummyMethod');
11981191
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
11991192
() => newSubsegment
12001193
);
@@ -1237,9 +1230,7 @@ describe('Class: Tracer', () => {
12371230
it('preserves the this scope correctly when used as decorator', async () => {
12381231
// Prepare
12391232
const tracer: Tracer = new Tracer();
1240-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
1241-
'### dummyMethod'
1242-
);
1233+
const newSubsegment = new Subsegment('### dummyMethod');
12431234
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
12441235
() => newSubsegment
12451236
);
@@ -1274,9 +1265,7 @@ describe('Class: Tracer', () => {
12741265
it('awaits the async method correctly when used as decorator', async () => {
12751266
// Prepare
12761267
const tracer: Tracer = new Tracer();
1277-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
1278-
'### dummyMethod'
1279-
);
1268+
const newSubsegment = new Subsegment('### dummyMethod');
12801269

12811270
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
12821271
() => newSubsegment
@@ -1375,9 +1364,7 @@ describe('Class: Tracer', () => {
13751364
it('sets the correct name for the subsegment when used as decorator and with a custom subSegmentName', async () => {
13761365
// Prepare
13771366
const tracer: Tracer = new Tracer();
1378-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment(
1379-
'### dummyMethod'
1380-
);
1367+
const newSubsegment = new Subsegment('### dummyMethod');
13811368
vi.spyOn(newSubsegment, 'flush').mockImplementation(() => null);
13821369
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
13831370
() => newSubsegment
@@ -1412,8 +1399,7 @@ describe('Class: Tracer', () => {
14121399
it('catches the error and logs a warning when a segment fails to close/serialize', async () => {
14131400
// Prepare
14141401
const tracer: Tracer = new Tracer();
1415-
const handlerSubsegment: Segment | Subsegment | undefined =
1416-
new Subsegment('### dummyMethod');
1402+
const handlerSubsegment = new Subsegment('### dummyMethod');
14171403
vi.spyOn(tracer.provider, 'getSegment').mockImplementation(
14181404
() => handlerSubsegment
14191405
);

0 commit comments

Comments
 (0)