- Home
- Skills
- DevOps & Cloud
- Structured Logging Setup with PII Redaction and Trace IDs
Works with the AI Agents you already use
Structured Logging Setup with PII Redaction and Trace IDs
Find passwords, tokens and personal data leaking into logs, add tested redaction, structured JSON with request and trace IDs, and cut noisy log cost. OBSERVABLE / NOISY / LEAKING.
$5
Structured Logging Setup with PII Redaction and Trace IDs
Example session with this skill installed
Audit logging in our Express API (pino → Datadog). Security review next month. Also our Datadog log bill doubled.
- Read your context and instructions
- Compiled the structured logging setup
Logging: api — VERDICT: LEAKING
Stack: pino 9 + pino-http → Datadog, retention 30 days
Leaks found
| # | Severity | Data | Where | Masked sample | Fix |
|---|---|---|---|---|---|
| 1 | Critical | Bearer tokens | lib/http.ts:52 logs axios err whole (includes config.headers) | Bearer eyJh…x9Qk | serializer logs err.message, status, url only |
| 2 | Critical | Stripe secret key | same axios errors to the Stripe API | sk_l…T2fA | rotate key now; then fix 1 |
| 3 | High | Session cookies | pino-http default req.headers | sid=s%3A… | redact req.headers.cookie, authorization |
| 4 | Medium | Customer emails and phones | orders/service.ts:88 logs full user | j***@gmail.com | log user.id only |
Sample-log scan (24 h export you provided): 1,912 JWT matches, 37 Stripe live-key matches, 4,420 emails. gitleaks + regex, a sample of each type checked by hand.
Structure
| Check | Before | After |
|---|---|---|
| JSON in prod | yes | yes |
| request_id on every line | handlers only | all lines via child logger |
| trace_id / span_id | no | yes (OTel instrumentation-pino) |
| ID in BullMQ jobs | no | passed in job data |
Redaction
11 explicit pino paths, error serializer, Sentry beforeSend scrub. Test logging.redaction.test.ts logs a fake request with all sensitive fields: 0 found in output.
Noise and cost
| Source | Lines/day | Action | Est. saving |
|---|---|---|---|
/health access logs | 8.6 M | drop | ~41% of volume |
order loop debug in prod | 2.1 M | level → info summary | ~10% |
Next steps for you
Rotate the Stripe key first, then ask Datadog to delete logs containing it (or let 30-day retention expire).
Connects securely to your tools. The creator never sees your data.
About this skill
Logs are where secrets go to hide. An axios error logged whole carries the Authorization header. A debug line prints the user object with the email and phone. A request logger stores cookies. All of it lands in a third-party log service for months, readable by everyone with access. Meanwhile the logs that matter are unstructured text with no request ID.
This skill gives your coding agent a logging procedure and a reference file checked against library docs and the OWASP Logging Cheat Sheet. It:
- Inventories loggers, formats, destinations, retention and correlation across services and background jobs
- Scans for leaks in code (whole request, user, config and HTTP-error objects, known sensitive fields, interpolated messages) and in sample logs (secret scanners plus JWT, bearer, email and card patterns)
- Fixes structure: JSON in production, standard fields, request_id and OpenTelemetry trace_id/span_id on every line, context binding, sane levels, errors logged once
- Adds redaction with tests: pino
redact, structlog processors, slogReplaceAttr, Railsfilter_parameters, Serilog, Logback, plus SentrybeforeSendand OpenTelemetry Collector scrubbing as a second layer - Cuts noise and cost: health checks, polling, chatty libraries and per-item loops
- Returns a verdict: OBSERVABLE, NOISY or LEAKING
Works with: pino, winston, Python logging and structlog, Rails, Laravel/Monolog, Go slog and zap, Java Logback/Log4j2, .NET Serilog, OpenTelemetry.
Safety: never prints secrets or personal data it finds (masked samples only), never deletes stored logs, and tells you to rotate any exposed secret before purging.
Honesty note: redaction is a safety net; the first fix is always to stop logging the sensitive object.
Requires read-only access to log providers. Cannot automatically delete or purge existing stored logs. User must provide log samples for analysis.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 28 days ago
Requires