1
- import type { Integration , Options , Scope , Span } from '@sentry/core' ;
2
- import {
3
- applySdkMetadata ,
4
- debug ,
5
- getSDKSource ,
6
- SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
7
- SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
8
- } from '@sentry/core' ;
1
+ import type { Integration , Options , Scope } from '@sentry/core' ;
2
+ import { applySdkMetadata , debug , getSDKSource } from '@sentry/core' ;
9
3
import type { NodeClient , NodeOptions } from '@sentry/node' ;
10
4
import {
11
5
captureException ,
12
6
captureMessage ,
13
- continueTrace ,
14
7
flush ,
15
8
getCurrentScope ,
16
9
getDefaultIntegrationsWithoutPerformance ,
17
10
initWithoutDefaultIntegrations ,
18
- startSpanManual ,
19
11
withScope ,
20
12
} from '@sentry/node' ;
21
13
import type { Context , Handler } from 'aws-lambda' ;
22
14
import { existsSync } from 'fs' ;
23
- import { hostname } from 'os' ;
24
15
import { basename , resolve } from 'path' ;
25
16
import { performance } from 'perf_hooks' ;
26
17
import { types } from 'util' ;
27
18
import { DEBUG_BUILD } from './debug-build' ;
28
19
import { awsIntegration } from './integration/aws' ;
29
20
import { awsLambdaIntegration } from './integration/awslambda' ;
30
- import { getAwsTraceData , markEventUnhandled } from './utils' ;
21
+ import { markEventUnhandled } from './utils' ;
31
22
32
23
const { isPromise } = types ;
33
24
@@ -54,12 +45,6 @@ export interface WrapperOptions {
54
45
* @default false
55
46
*/
56
47
captureAllSettledReasons : boolean ;
57
- /**
58
- * Automatically trace all handler invocations.
59
- * You may want to disable this if you use express within Lambda.
60
- * @default true
61
- */
62
- startTrace : boolean ;
63
48
}
64
49
65
50
/**
@@ -207,18 +192,6 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi
207
192
} ) ;
208
193
}
209
194
210
- /**
211
- * Adds additional transaction-related information from the environment and AWS Context to the Sentry Scope.
212
- *
213
- * @param scope Scope that should be enhanced
214
- * @param context AWS Lambda context that will be used to extract some part of the data
215
- */
216
- function enhanceScopeWithTransactionData ( scope : Scope , context : Context ) : void {
217
- scope . setTransactionName ( context . functionName ) ;
218
- scope . setTag ( 'server_name' , process . env . _AWS_XRAY_DAEMON_ADDRESS || process . env . SENTRY_NAME || hostname ( ) ) ;
219
- scope . setTag ( 'url' , `awslambda:///${ context . functionName } ` ) ;
220
- }
221
-
222
195
/**
223
196
* Wraps a lambda handler adding it error capture and tracing capabilities.
224
197
*
@@ -237,7 +210,6 @@ export function wrapHandler<TEvent, TResult>(
237
210
captureTimeoutWarning : true ,
238
211
timeoutWarningLimit : 500 ,
239
212
captureAllSettledReasons : false ,
240
- startTrace : true ,
241
213
...wrapOptions ,
242
214
} ;
243
215
let timeoutWarningTimer : NodeJS . Timeout ;
@@ -293,7 +265,7 @@ export function wrapHandler<TEvent, TResult>(
293
265
} , timeoutWarningDelay ) as unknown as NodeJS . Timeout ;
294
266
}
295
267
296
- async function processResult ( span ?: Span ) : Promise < TResult > {
268
+ async function processResult ( ) : Promise < TResult > {
297
269
const scope = getCurrentScope ( ) ;
298
270
299
271
let rv : TResult ;
@@ -314,60 +286,15 @@ export function wrapHandler<TEvent, TResult>(
314
286
throw e ;
315
287
} finally {
316
288
clearTimeout ( timeoutWarningTimer ) ;
317
- if ( span ?. isRecording ( ) ) {
318
- span . end ( ) ;
319
- }
320
289
await flush ( options . flushTimeout ) . catch ( e => {
321
290
DEBUG_BUILD && debug . error ( e ) ;
322
291
} ) ;
323
292
}
324
293
return rv ;
325
294
}
326
295
327
- // Only start a trace and root span if the handler is not already wrapped by Otel instrumentation
328
- // Otherwise, we create two root spans (one from otel, one from our wrapper).
329
- // If Otel instrumentation didn't work or was filtered by users, we still want to trace the handler.
330
- // TODO: Since bumping the OTEL Instrumentation, this is likely not needed anymore, we can possibly remove this (can be done whenever since it would be non-breaking)
331
- if ( options . startTrace && ! isWrappedByOtel ( handler ) ) {
332
- const traceData = getAwsTraceData ( event as { headers ?: Record < string , string > } , context ) ;
333
-
334
- return continueTrace ( { sentryTrace : traceData [ 'sentry-trace' ] , baggage : traceData . baggage } , ( ) => {
335
- return startSpanManual (
336
- {
337
- name : context . functionName ,
338
- op : 'function.aws.lambda' ,
339
- attributes : {
340
- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
341
- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.serverless' ,
342
- } ,
343
- } ,
344
- span => {
345
- enhanceScopeWithTransactionData ( getCurrentScope ( ) , context ) ;
346
-
347
- return processResult ( span ) ;
348
- } ,
349
- ) ;
350
- } ) ;
351
- }
352
-
353
296
return withScope ( async ( ) => {
354
- return processResult ( undefined ) ;
297
+ return processResult ( ) ;
355
298
} ) ;
356
299
} ;
357
300
}
358
-
359
- /**
360
- * Checks if Otel's AWSLambda instrumentation successfully wrapped the handler.
361
- * Check taken from @opentelemetry/core
362
- */
363
- function isWrappedByOtel (
364
- // eslint-disable-next-line @typescript-eslint/ban-types
365
- handler : Function & { __original ?: unknown ; __unwrap ?: unknown ; __wrapped ?: boolean } ,
366
- ) : boolean {
367
- return (
368
- typeof handler === 'function' &&
369
- typeof handler . __original === 'function' &&
370
- typeof handler . __unwrap === 'function' &&
371
- handler . __wrapped === true
372
- ) ;
373
- }
0 commit comments