Skip to content

docs(event_handler): demonstrate how to combine logger correlation ID and middleware #3064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def inject_correlation_id(app: APIGatewayRestResolver, next_middleware: NextMidd
request_id = app.current_event.request_context.request_id # (1)!

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

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


@logger.inject_lambda_context
@logger.inject_lambda_context(correlation_id_path='headers."x-correlation-id"')
def lambda_handler(event, context):
return app.resolve(event, context)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def inject_correlation_id(app: APIGatewayRestResolver, next_middleware: NextMidd
request_id = app.current_event.request_context.request_id

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

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