Skip to content

Commit 9ddbc12

Browse files
committed
docs(event_handler): combine correlation id with logger for a more powerful example
1 parent b5e1f79 commit 9ddbc12

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

examples/event_handler_rest/src/middleware_getting_started.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def inject_correlation_id(app: APIGatewayRestResolver, next_middleware: NextMidd
1212
request_id = app.current_event.request_context.request_id # (1)!
1313

1414
# Use API Gateway REST API request ID if caller didn't include a correlation ID
15-
correlation_id = app.current_event.headers.get("x-correlation-id", request_id)
15+
correlation_id = logger.get_correlation_id() or request_id
1616

1717
# Inject correlation ID in shared context and Logger
1818
app.append_context(correlation_id=correlation_id) # (2)!
@@ -35,6 +35,6 @@ def get_todos():
3535
return {"todos": todos.json()[:10]}
3636

3737

38-
@logger.inject_lambda_context
38+
@logger.inject_lambda_context(correlation_id_path='headers."x-correlation-id"')
3939
def lambda_handler(event, context):
4040
return app.resolve(event, context)

examples/event_handler_rest/src/middleware_global_middlewares_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def inject_correlation_id(app: APIGatewayRestResolver, next_middleware: NextMidd
1818
request_id = app.current_event.request_context.request_id
1919

2020
# Use API Gateway REST API request ID if caller didn't include a correlation ID
21-
correlation_id = app.current_event.headers.get("x-correlation-id", request_id)
21+
correlation_id = logger.get_correlation_id() or request_id
2222

2323
# Inject correlation ID in shared context and Logger
2424
app.append_context(correlation_id=correlation_id)

0 commit comments

Comments
 (0)