otel-instrumentation

โดย dash0hq

กำหนดค่า trace spans, กำหนด metrics แบบกำหนดเอง, ตั้งค่า log exporters, และปรับกลยุทธ์การสุ่มตัวอย่างให้เหมาะสมสำหรับการติดตั้ง OpenTelemetry ใช้เมื่อ...

npx skills add https://github.com/dash0hq/agent-skills --skill otel-instrumentation

OpenTelemetry Instrumentation Guide

Expert guidance for implementing high-quality, cost-efficient OpenTelemetry telemetry.

Rules & Quick Reference

Use Case / RuleDescription
telemetryEntrypoint — signal types, correlation, and navigation
resolve-valuesResolving configuration values from the codebase
verify-dependenciesVerifying instrumentation packages and versions exist before adding them
resourcesResource attributes — service identity and environment
k8sKubernetes deployment — downward API, pod spec
spansSpans — naming, kind, status, and hygiene
logsLogs — structured logging, severity, trace correlation
metricsMetrics — instrument types, naming, units, cardinality
sensitive-dataSensitive data — PII prevention, sanitization, redaction
capture-database-query-parametersPrepared-statement parameter capture per language (Java, .NET, Python, Node.js, Go)
validationTelemetry validation — post-deployment verification checklist
nodejsNode.js instrumentation setup
goGo instrumentation setup
pythonPython instrumentation setup
javaJava instrumentation setup
scalaScala instrumentation setup
dotnet.NET instrumentation setup
rubyRuby instrumentation setup
phpPHP instrumentation setup
browserBrowser instrumentation setup
nextjsNext.js full-stack instrumentation (App Router)

Official documentation

Getting started

Follow these steps when instrumenting an application from scratch:

  1. Pick your SDK rule — choose the language-specific rule from the table above (e.g., nodejs, python).
  2. Set up resource attributes — define service identity and environment per resources.
  3. Add spans, metrics, and logs — instrument your code following spans, metrics, and logs.
  4. Guard sensitive data — scrub PII before export per sensitive-data.
  5. Validate — confirm telemetry reaches the backend using the checklist in validation.

The snippet below shows a complete span with attributes and status for Node.js — see nodejs for full setup including SDK initialisation, exporter configuration, and auto-instrumentation:

import { trace, SpanStatusCode } from '@opentelemetry/api';
const tracer = trace.getTracer('my-service', '1.0.0');

tracer.startActiveSpan('operation-name', async (span) => {
  try {
    span.setAttribute('user.id', userId);
    span.setAttribute('order.id', orderId);

    const result = await processOrder(orderId);

    span.setAttribute('order.status', result.status);
    span.setStatus({ code: SpanStatusCode.OK });
    return result;
  } catch (err) {
    // Record the exception as a structured log record, not span.recordException — see rules/spans.md
    span.setStatus({ code: SpanStatusCode.ERROR, message: `${err.name}: ${err.message}` });
    const spanContext = span.spanContext();
    logger.error('operation-name.failed', {
      'trace_id': spanContext.traceId,
      'span_id': spanContext.spanId,
      'exception.type': err.name,
      'exception.message': err.message,
      'exception.stacktrace': err.stack,
    });
    throw err;
  } finally {
    span.end();
  }
});

Key principles

Signal density over volume

Every telemetry item should serve one of three purposes:

  • Detect - Help identify that something is wrong
  • Localize - Help pinpoint where the problem is
  • Explain - Help understand why it happened

If it doesn't serve one of these purposes, don't emit it.

Sample in the pipeline, not the SDK

Use the AlwaysOn sampler (the default) in every SDK. Do not configure SDK-side samplers — they make irreversible decisions before the outcome of a request is known. Defer all sampling to the Collector, where policies can be changed centrally without redeploying applications.

SDK (AlwaysOn)  →  Collector (sampling)  →  Backend (retention)
     ↓                    ↓                       ↓
  All spans         Head or tail            Storage policies
  exported          sampling applied

Skills เพิ่มเติมจาก dash0hq

dash0-cli
dash0hq
Use when working with Dash0 observability data or configuration via the dash0 CLI (the `dash0` binary) — querying logs, spans, traces, metrics, or failed…
official
dash0-sync-docs
dash0hq
เชื่อมต่อหรือดีบักการซิงค์เอกสารของรีポซิทอรีต้นทางไปยังเว็บไซต์ Dash0 ผ่าน composite action ของ dash0hq/sync-docs-action ใช้เมื่อเพิ่ม sync-docs-to-website…
official
otel-collector
dash0hq
คำแนะนำจากผู้เชี่ยวชาญสำหรับการกำหนดค่าและปรับใช้ OpenTelemetry Collector ใช้เมื่อตั้งค่าไปป์ไลน์ Collector กำหนดค่า receivers, exporters หรือ…
official
otel-ottl
dash0hq
ผู้เชี่ยวชาญด้านภาษาแปลง OpenTelemetry (OTTL) ใช้เมื่อเขียนหรือดีบักนิพจน์ OTTL สำหรับคอมโพเนนต์ OpenTelemetry Collector ใดๆ ที่รองรับ…
official
otel-semantic-conventions
dash0hq
ผู้เชี่ยวชาญด้านข้อกำหนดเชิงความหมายของ OpenTelemetry ใช้เมื่อเลือก ใช้ หรือตรวจสอบแอตทริบิวต์การวัดระยะไกล ทำงานเมื่อมีงานที่เกี่ยวข้องกับการเลือกแอตทริบิวต์…
official