Skip to content

Commit 657a192

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

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/core/tracing.md

+33
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ 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-15"
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+
ObjectMapper objectMapper = new ObjectMapper();
187+
SimpleModule simpleModule = new SimpleModule();
188+
objectMapper.registerModule(simpleModule);
189+
190+
TracingUtils.defaultObjectMapper(objectMapper);
191+
}
192+
193+
@Tracing(captureMode = RESPONSE)
194+
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
195+
...
196+
}
197+
}
198+
```
199+
167200
## Utilities
168201

169202
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)