Skip to content

Add request logging middleware with correlation ID injection #243

Description

@usmanimamu17-create

Labels / Complexity: observability · Trivial — 2 pts

Summary

The backend has a CorrelationMiddleware (app/middleware/correlation.py) that generates or propagates correlation IDs, but request logging does not include the correlation ID in every log entry. This makes it difficult to trace requests across services when debugging issues.

Proposal

  • Update app/core/logging_config.py to include correlation_id in the log format
  • Ensure all loggers use the correlation context from app/utils/correlation_ctx.py
  • Verify that the correlation ID is included in the X-Correlation-ID response header

Acceptance criteria

  • Every log entry includes the correlation_id field
  • The X-Correlation-ID header is present in all API responses
  • A test verifies correlation ID propagation from request to response

Out of scope

Distributed tracing with OpenTelemetry (already implemented via app/core/tracing.py).

Getting started

Files in scope:

  • app/core/logging_config.py
  • app/middleware/correlation.py
  • app/utils/correlation_ctx.py

Build/test commands:

pytest tests/test_correlation_exceptions.py

Good first files to read: app/middleware/correlation.py, app/core/logging_config.py.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaignarea/observabilityLogs, metrics, traces, alerting, dashboards, correlation IDs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions