@@ -25,20 +25,20 @@ class Tracer implements ClassThatTraces {
25
25
this . provider = new ProviderService ( ) ;
26
26
}
27
27
28
- public captureAWS < T > ( aws : T ) : void | T {
29
- if ( this . tracingEnabled === false ) return ;
28
+ public captureAWS < T > ( aws : T ) : T {
29
+ if ( this . tracingEnabled === false ) return aws ;
30
30
31
31
return this . provider . captureAWS ( aws ) ;
32
32
}
33
33
34
- public captureAWSClient < T > ( service : T ) : void | T {
35
- if ( this . tracingEnabled === false ) return ;
34
+ public captureAWSClient < T > ( service : T ) : T {
35
+ if ( this . tracingEnabled === false ) return service ;
36
36
37
37
return this . provider . captureAWSClient ( service ) ;
38
38
}
39
39
40
- public captureAWSv3Client < T > ( service : T ) : void | T {
41
- if ( this . tracingEnabled === false ) return ;
40
+ public captureAWSv3Client < T > ( service : T ) : T {
41
+ if ( this . tracingEnabled === false ) return service ;
42
42
43
43
return this . provider . captureAWSv3Client ( service ) ;
44
44
}
@@ -59,7 +59,7 @@ class Tracer implements ClassThatTraces {
59
59
result = await originalMethod ?. apply ( this , [ event , context , callback ] ) ;
60
60
this . addResponseAsMetadata ( result , context . functionName ) ;
61
61
} catch ( error ) {
62
- this . addErrorAsMetadata ( error ) ;
62
+ this . addErrorAsMetadata ( error as Error ) ;
63
63
// TODO: should this error be thrown?? If thrown we get a ERR_UNHANDLED_REJECTION. If not aren't we are basically catching a Customer error?
64
64
// throw error;
65
65
} finally {
@@ -85,8 +85,13 @@ class Tracer implements ClassThatTraces {
85
85
} ;
86
86
}
87
87
88
- public getSegment ( ) : Segment | Subsegment | undefined {
89
- return this . provider . getSegment ( ) ;
88
+ public getSegment ( ) : Segment | Subsegment {
89
+ const segment = this . provider . getSegment ( ) ;
90
+ if ( segment === undefined ) {
91
+ throw new Error ( 'Failed to get the current sub/segment from the context.' ) ;
92
+ }
93
+
94
+ return segment ;
90
95
}
91
96
92
97
public static isColdStart ( ) : boolean {
@@ -131,7 +136,9 @@ class Tracer implements ClassThatTraces {
131
136
132
137
private addErrorAsMetadata ( error : Error ) : void {
133
138
const subsegment = this . getSegment ( ) ;
134
- if ( this . captureError === false || subsegment === undefined || this . tracingEnabled === false ) {
139
+ if ( this . captureError === false ) {
140
+ subsegment . addErrorFlag ( ) ;
141
+
135
142
return ;
136
143
}
137
144
0 commit comments