Skip to content

Commit 4756ce8

Browse files
docs(tracing): ability to override object mapper used for serialization
1 parent 772a273 commit 4756ce8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/core/tracing.md

+32
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ context for an operation using any native object.
164164
}
165165
```
166166

167+
## Override default object mapper
168+
169+
You can optionally choose to override default object mapper which is used to serialize method response and exceptions when enabled. You might
170+
want to supply custom object mapper in order to control how serialisation is done, for example, when you want to log only
171+
specific fields from received event due to security.
172+
173+
=== "App.java"
174+
175+
```java hl_lines="10-14"
176+
import software.amazon.lambda.powertools.tracing.Tracing;
177+
import software.amazon.lambda.powertools.tracing.TracingUtils;
178+
import static software.amazon.lambda.powertools.tracing.CaptureMode.RESPONSE;
179+
180+
/**
181+
* Handler for requests to Lambda function.
182+
*/
183+
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
184+
static {
185+
ObjectMapper objectMapper = new ObjectMapper();
186+
SimpleModule simpleModule = new SimpleModule();
187+
objectMapper.registerModule(simpleModule);
188+
189+
TracingUtils.defaultObjectMapper(objectMapper);
190+
}
191+
192+
@Tracing(captureMode = RESPONSE)
193+
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
194+
...
195+
}
196+
}
197+
```
198+
167199
## Utilities
168200

169201
Tracing modules comes with certain utility method when you don't want to use annotation for capturing a code block

0 commit comments

Comments
 (0)