OpenTelemetry Manual Instrumentation & Span Design Prompt
Design high-quality manual spans and attributes with the OpenTelemetry API where auto-instrumentation falls short, covering span granularity, status/error recording, span links, and cardinality control.
- Target user
- Senior application engineers adding manual OTel spans
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior application engineer who writes precise, low-overhead manual OpenTelemetry instrumentation. I will provide: - The language/framework and a code excerpt of the operation to instrument - What auto-instrumentation already covers for this path - The business questions the trace must answer (which step is slow, why a request failed, tenant impact) - Any PII/compliance constraints on what can be recorded Your job: 1. **Span boundaries** — decide which operations deserve their own span vs an event/attribute on an existing span, avoiding both under- and over-instrumentation. Justify the granularity. 2. **Naming** — apply low-cardinality span names (operation, not parameterized values) that align with semantic conventions. 3. **Attributes** — choose attributes that answer the business questions, mapping to semantic conventions where they exist and using a clear namespace for custom ones; keep them bounded-cardinality. 4. **Status & errors** — set span status correctly, record exceptions with record_exception, and distinguish handled vs unhandled failures. 5. **Context & links** — ensure spans nest under the active context, and use span links for fan-out/batch/async cases that aren't a simple parent-child. 6. **Cardinality & PII** — flag any attribute that risks high cardinality or leaks PII, and give a safe alternative (hashing, bucketing, redaction). 7. **Correctness** — guarantee spans end on every path (context managers/defer/try-finally) and show the idiomatic pattern for the language. Output as: (a) the instrumented code using the OTel API, (b) a table of spans/attributes with cardinality and PII notes, (c) the naming/status conventions applied, (d) a review checklist for other engineers instrumenting similar code. Call out anything that would create cardinality blowups, leak sensitive data, or leave spans unended under errors.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
OpenTelemetry Auto-Instrumentation Rollout Prompt
Plan a safe, incremental rollout of OpenTelemetry auto-instrumentation across polyglot services, including the Operator injection model, version pinning, and where manual spans must supplement the agents.
-
OpenTelemetry Context Propagation Strategy Prompt
Fix broken distributed traces by designing correct context propagation across HTTP, gRPC, messaging queues, and async boundaries, standardizing on W3C tracecontext/baggage and handling gateways that strip headers.
-
OpenTelemetry Metrics Instrumentation Design Prompt
Design a metrics instrumentation plan with the OpenTelemetry SDK: pick the right instrument types, choose temporality and aggregation, define views to rename and bucket, and control cardinality before metrics reach the backend.
-
OpenTelemetry Collector Gateway Scaling & HA Prompt
Design a horizontally scalable, highly available OpenTelemetry Collector gateway tier — autoscaling, load balancing, queue persistence, and zero-loss rolling upgrades — so telemetry survives replica churn and traffic spikes.
More OpenTelemetry prompts & error guides
Browse every OpenTelemetry prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.