tenant-aware-logging

Attach tenant context to log entries across HTTP handlers and background jobs.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/marquesfelip/agents-and-skills --skill tenant-aware-logging
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tenant-aware-logging
Source: https://github.com/marquesfelip/agents-and-skills/tree/main/skills/tenant-aware-logging
Command: npx skills add https://github.com/marquesfelip/agents-and-skills --skill tenant-aware-logging

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tenant-aware logging ensures every log carries tenant context to enable per-tenant filtering, auditing, and compliance across microservices in multi-tenant SaaS environments.

Core Features & Use Cases

  • Attach tenant_id to logs across HTTP handlers, background jobs, and async tasks
  • Propagate tenant context through context.Context or similar across goroutines and service boundaries
  • Enable per-tenant log filtering in Loki, Datadog, CloudWatch; enforce PII masking
  • Reconstruct tenant context in background workers for traceability and isolation

Quick Start

Instrument your HTTP handlers to attach tenant_id to the request context and emit tenant-enriched logs in all services.

Frequently Asked Questions about tenant-aware-logging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I attach tenant_id to logs across HTTP handlers and background jobs?

To attach tenant_id to logs, instrument HTTP middleware to inject the tenant context into the request context. A Logger helper then extracts this context to enrich all log entries across HTTP handlers, background workers, and asynchronous tasks.

What is the best way to propagate tenant context across microservices for observability?

Propagating tenant context across microservices requires passing a shared tenant_id key through context boundaries. This enables consistent per-tenant log filtering and traceability across distributed SaaS stack components.

Can I filter per-tenant logs in Loki, Datadog, and CloudWatch?

Yes, per-tenant log filtering works in Loki, Datadog, and CloudWatch. By injecting tenant_id into every log entry, you can query and isolate specific tenant activity across your observability platforms.

Do I need shared context keys for tenant-aware logging in a SaaS stack?

Yes, shared context keys are required for tenant-aware logging. A standardized tenant_id key allows middleware and Logger helpers to consistently inject, propagate, and reconstruct tenant context across all services.

Why does tenant context get lost in asynchronous tasks and background workers?

Tenant context gets lost in asynchronous tasks when it is not explicitly propagated. Reconstructing tenant context in background workers requires injecting the tenant_id into the job payload and re-establishing it in the worker's logging context.