Review OpenAI and LLM API keys in logs, traces, and agent transcripts
Cursor or Claude Code applies a SKILL.md on logging and observability PRs: Authorization headers, provider SDK debug flags, prompt/response logging, and error handlers that stringify requests — with merge-blocking findings before merge.
Cursor, Claude Code, Sentry · Coding · 30 min · Working
Outcome
An api-key-logs SKILL.md linked from observability docs, a PR comment naming each new log site and redaction path, and no merge that ships full API keys into application logs, APM, or agent session exports.
Steps
- 1
Run the skill on a deliberate axios error log
Use a PR that logs error.config.headers on failed LLM calls. The skill should Block until redaction or removal is in the diff.
- 2
Add a shared sanitizeForLog helper
One function strips Authorization, api-key, and known env shapes. The skill references that helper by path so reviews stay consistent.
- 3
Pair with secrets-via-env and history-review skills
Keys in logs often started as keys in git. Link all three from observability onboarding so fixes do not stop at log redaction while history still holds the blob.
Copy prompt
The prompt to paste
Write SKILL.md for reviewing code that might leak OpenAI, Anthropic, or other LLM provider API keys into logs, traces, metrics, or agent transcripts. Focus on redaction and log shape — not model choice or prompt quality. Repository context: [LLM SDKs in use: openai, @anthropic-ai/sdk, Vercel AI SDK, LangChain — names only] [observability stack: Sentry, Datadog, CloudWatch, OpenTelemetry, console — list real sinks] [env var names for provider keys — names only, e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY] [whether agents run in Cursor cloud, local, or CI with transcript retention] PR or diff context (paste when using): [PR link, changed logging, middleware, error handlers, AI route handlers, OpenTelemetry spans] SKILL.md must include: 1. Purpose — provider keys in logs are bearer tokens; log aggregation, support exports, and agent transcripts copy them to systems with wider access than production env. 2. When to use — any PR touching logging config, catch blocks around LLM calls, HTTP client debug, OpenTelemetry attributes, Sentry breadcrumbs, prompt logging, or agent skill output templates. When not to use — model routing docs with no runtime logging changes. 3. Hard rules for findings: - Block: logging full request headers including Authorization or api-key; logging process.env.OPENAI_API_KEY or equivalent; SDK debug/verbose mode enabled in production paths; console.log(err) where err.config.headers contains secrets; OpenTelemetry span attributes or Sentry context set to key values or full connection strings; structured log fields named apiKey, secret, bearer, or authorization with unredacted values; agent SKILL.md or runbooks that instruct pasting live keys into tickets for debugging. - Warn: logging entire LLM request bodies that embed keys in custom headers; log level defaulting to debug in shared modules; error middleware that JSON.stringify's the whole request object; trace sampling that exports all attributes without an allowlist; logging token usage responses that include organization ids tied to billing without redaction policy; transcript or eval harness storing raw env dumps. - Note: log message wording, metric naming — never block on style alone. 4. Review steps the agent must execute: - List each new or changed log, logger.*, captureException, span.setAttribute, and breadcrumb call in the diff. - Trace LLM client construction: where the key is read and whether any wrapper logs on failure. - Flag SDK options: dangerouslyAllowBrowser, debug: true, logLevel, fetch logging interceptors. - Check redaction helpers: is there a central sanitize function and is it invoked on errors bubbling from providers? - For agent-specific paths: verify cloud agent rules and skills say env names only; scan for examples in comments that look like real sk- keys. - Map sinks: which transports receive ERROR vs INFO — keys often leak on INFO during retries. 5. PR comment template: log site table (location — sink — fields logged — redaction?), findings by severity, merge recommendation. 6. Safe patterns section: log provider name and request id only; use Sentry beforeSend / OTel attribute processors to strip authorization; read keys once into memory without logging config objects; document REDACTED placeholder in examples; pair with secrets-hygiene skill for chat paste rules. 7. Two example prompts: add retry logging around OpenAI chat completions vs enable LangChain verbose in a shared factory. 8. Pitfalls: logging axios/fetch error.response.config, copying tutorial snippets with sk- placeholders that match real key regex, assuming stderr is not collected in serverless, treating support ticket paste as out of scope when the app prints the same string to logs. 9. Done means: every Block resolved, redaction path named for each new log site, no live keys or bearer tokens in PR comment, production log level confirmed for SDK debug flags. Rules: - Never paste live API keys; reference env var names and redaction patterns only. - Do not suggest disabling logging entirely on production — redact instead. - Output only SKILL.md markdown.
OpenAI-shaped keys match a predictable prefix regex — scanners find them in log indexes after the fact. The skill must Block new log sites that emit header objects wholesale, not only obvious console.log(process.env) lines.
Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code or Sentry.
More in Coding
Get new cases in your inbox
Weekly notes on new use cases and agent workflows. No product pitches.