---
name: observability-logging
description: Design, add, or review production logs, traces, and metrics for operational questions, safe fields, and error ownership.
title: observability-logging
canonical_url: https://skilld.dev/gh/khoahyh/skills/observability-logging
last_updated: 2026-10-06T14:35:20.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install khoahyh/skills/observability-logging`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/observability-logging`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/khoahyh/skills/observability-logging) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/observability-logging`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/observability-logging --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/observability-logging --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Observability Logging

Use the least production telemetry that answers a defined operational question. If existing signals answer it, add nothing. Use `motel-debug` for temporary diagnostic probes rather than retaining them as production instrumentation.

## Signal And Scope

| Operational need | Signal |
| --- | --- |
| Duration and causal operation boundary | Span |
| Meaningful occurrence or state transition | Named event or structured log |
| Aggregate rate, count, or distribution | Metric |

A context-rich completion event can answer several known queries; it does not replace useful spans or point-in-time events by default.

Use static names such as `checkout.completed` or HTTP route templates. Put dynamic values in attributes, with bounded metric dimensions. Resource attributes describe the service and deployment, not individual requests. Use SDK trace/span correlation; an application request ID complements it.

Inbound middleware owns request lifecycle fields; application modules own business outcomes; outbound adapters classify dependency failures. Configure resources, exporters, sampling, and structured logging at the composition root. For Effect programs, use the installed version's span and scoped logging APIs rather than ad hoc global loggers.

## Safe Fields

Allowlist fields by operational need. Prefer operation, route template, state or typed error tag, dependency, retry count, and bounded numeric summaries. Opaque non-PII domain IDs belong only where an established allowlist permits them and incident lookup requires them.

Keep secrets, credentials, tokens, cookies, sessions, raw PII, payment data, bodies, SQL parameters, prompts/completions, arbitrary objects, and raw signed URLs out of telemetry. Capture headers or sanitized URL components only through an explicit allowlist. Bound and sanitize untrusted strings; preserve `Redacted` values through adapters without recording them.

## Error Ownership

Record a terminal failure once at the outermost owning boundary that classifies the final operational outcome, correlated with the active span. Include a stable typed error tag and safe context. Lower adapters translate failures rather than duplicating the terminal record at every catch and rethrow.

Handled retries and fallbacks do not make a successful enclosing operation fail. Intentional cancellation is an outcome, not an error. Use `WARN` for conditions needing operational attention and fatal severity only for process-ending failures.

## Completion

For a design or review, identify the operational question, needed signal or existing coverage, ownership, safe fields, and any evidence gaps. For implementation, continue through focused checks of emitted telemetry and fix attributable issues within scope.

The relevant boundary should demonstrate stable names, trace correlation, one terminal error record, accurate handled outcomes, safe fields, and bounded metric dimensions. Use an existing test collector or runtime query that can answer the original question; avoid building a telemetry test framework for a small edit. Report unavailable runtime evidence instead of claiming emission was verified. Repeat or broaden checks only when changes, failures, or unresolved risks warrant it.

## Conditional References

Consult version-matched SDK documentation when API behavior is uncertain, and the relevant standard when deciding schema, error, or data-handling policy:

- [OpenTelemetry logs data model](https://opentelemetry.io/docs/specs/otel/logs/data-model/)
- [OpenTelemetry events](https://opentelemetry.io/docs/specs/semconv/general/events/)
- [OpenTelemetry error recording](https://opentelemetry.io/docs/specs/semconv/general/recording-errors/)
- [OpenTelemetry sensitive data](https://opentelemetry.io/docs/security/handling-sensitive-data/)
- [OWASP logging guidance](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html)
