Skip to content

Commit ae72d52

Browse files
committed
chore: remove all captureLambdaHandler decorator changes
1 parent 14ccc2f commit ae72d52

File tree

4 files changed

+5
-71
lines changed

4 files changed

+5
-71
lines changed

Diff for: docs/core/tracer.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Use **`POWERTOOLS_TRACER_CAPTURE_RESPONSE=false`** environment variable to instr
414414

415415
### Disabling response capture for targeted methods and handlers
416416

417-
Use the `captureResponse: false` option in both `tracer.captureLambdaHandler()` and `tracer.captureMethod()` decorators to instruct Tracer **not** to serialize function responses as metadata.
417+
Use the `captureResponse: false` option in `tracer.captureMethod()` decorators to instruct Tracer **not** to serialize function responses as metadata.
418418

419419
=== "method.ts"
420420

@@ -431,21 +431,6 @@ Use the `captureResponse: false` option in both `tracer.captureLambdaHandler()`
431431
}
432432
```
433433

434-
=== "handler.ts"
435-
436-
```typescript hl_lines="6"
437-
import { Tracer } from '@aws-lambda-powertools/tracer';
438-
import { LambdaInterface } from '@aws-lambda-powertools/commons';
439-
440-
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
441-
class MyHandler implements LambdaInterface {
442-
@tracer.captureLambdaHandler({ captureResponse: false })
443-
async handler(_event: any, _context: any): Promise<void> {
444-
/* ... */
445-
}
446-
}
447-
```
448-
449434
### Disabling exception auto-capture
450435

451436
Use **`POWERTOOLS_TRACER_CAPTURE_ERROR=false`** environment variable to instruct Tracer **not** to serialize exceptions as metadata.

Diff for: packages/tracer/src/Tracer.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Handler } from 'aws-lambda';
22
import { AsyncHandler, SyncHandler, Utility } from '@aws-lambda-powertools/commons';
33
import { TracerInterface } from '.';
44
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
5-
import { HandlerMethodDecorator, TracerOptions, TracerCaptureMethodOptions, TracerCaptureLambdaHandlerOptions, MethodDecorator } from './types';
5+
import { HandlerMethodDecorator, TracerOptions, TracerCaptureMethodOptions, MethodDecorator } from './types';
66
import { ProviderService, ProviderServiceInterface } from './provider';
77
import { Segment, Subsegment } from 'aws-xray-sdk-core';
88

@@ -339,7 +339,7 @@ class Tracer extends Utility implements TracerInterface {
339339
*
340340
* @decorator Class
341341
*/
342-
public captureLambdaHandler(options?: TracerCaptureLambdaHandlerOptions): HandlerMethodDecorator {
342+
public captureLambdaHandler(): HandlerMethodDecorator {
343343
return (_target, _propertyKey, descriptor) => {
344344
/**
345345
* The descriptor.value is the method this decorator decorates, it cannot be undefined.
@@ -365,10 +365,7 @@ class Tracer extends Utility implements TracerInterface {
365365
let result: unknown;
366366
try {
367367
result = await originalMethod.apply(handlerRef, [ event, context, callback ]);
368-
if (options?.captureResponse ?? true) {
369-
tracerRef.addResponseAsMetadata(result, process.env._HANDLER);
370-
}
371-
368+
tracerRef.addResponseAsMetadata(result, process.env._HANDLER);
372369
} catch (error) {
373370
tracerRef.addErrorAsMetadata(error as Error);
374371
throw error;
@@ -444,6 +441,7 @@ class Tracer extends Utility implements TracerInterface {
444441

445442
} catch (error) {
446443
tracerRef.addErrorAsMetadata(error as Error);
444+
447445
throw error;
448446
} finally {
449447
subsegment?.close();

Diff for: packages/tracer/src/types/Tracer.ts

-19
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ type TracerCaptureMethodOptions = {
4646
captureResponse?: boolean
4747
};
4848

49-
/**
50-
* Options for the captureLambdaHandler decorator to be used when decorating a method.
51-
*
52-
* Usage:
53-
* @example
54-
* ```typescript
55-
* const tracer = new Tracer();
56-
*
57-
* class MyThing implements LambdaInterface {
58-
* @tracer.captureLambdaHandler({ captureResponse: false })
59-
* async handler(_event: any, _context: any): Promise<void> {}
60-
* }
61-
* ```
62-
*/
63-
type TracerCaptureLambdaHandlerOptions = {
64-
captureResponse?: boolean
65-
};
66-
6749
type HandlerMethodDecorator = (
6850
target: LambdaInterface,
6951
propertyKey: string | symbol,
@@ -76,7 +58,6 @@ type MethodDecorator = (target: any, propertyKey: string | symbol, descriptor: T
7658

7759
export {
7860
TracerOptions,
79-
TracerCaptureLambdaHandlerOptions,
8061
TracerCaptureMethodOptions,
8162
HandlerMethodDecorator,
8263
MethodDecorator

Diff for: packages/tracer/tests/unit/Tracer.test.ts

-30
Original file line numberDiff line numberDiff line change
@@ -648,36 +648,6 @@ describe('Class: Tracer', () => {
648648

649649
});
650650

651-
test('when used as decorator while captureResponse is set to false, it does not capture the response as metadata', async () => {
652-
653-
// Prepare
654-
const tracer: Tracer = new Tracer();
655-
const newSubsegment: Segment | Subsegment | undefined = new Subsegment('## index.handler');
656-
jest.spyOn(tracer.provider, 'getSegment').mockImplementation(() => newSubsegment);
657-
setContextMissingStrategy(() => null);
658-
const captureAsyncFuncSpy = jest.spyOn(tracer.provider, 'captureAsyncFunc');
659-
class Lambda implements LambdaInterface {
660-
661-
@tracer.captureLambdaHandler({ captureResponse: false })
662-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
663-
// @ts-ignore
664-
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> {
665-
return new Promise((resolve, _reject) => resolve({
666-
foo: 'bar'
667-
} as unknown as TResult));
668-
}
669-
670-
}
671-
672-
// Act
673-
await new Lambda().handler(event, context, () => console.log('Lambda invoked!'));
674-
675-
// Assess
676-
expect(captureAsyncFuncSpy).toHaveBeenCalledTimes(1);
677-
expect('metadata' in newSubsegment).toBe(false);
678-
679-
});
680-
681651
test('when used as decorator and with standard config, it captures the response as metadata', async () => {
682652

683653
// Prepare

0 commit comments

Comments
 (0)