jpskill.com
🛠️ 開発・MCP コミュニティ

otel-js

OpenTelemetryを用いてNode.jsアプリケーションに分散トレーシングやメトリクス収集を導入し、HTTPリクエストやデータベースクエリの追跡、マイクロサービス全体の可観測性を向上させる設定を支援するSkill。

📜 元の英語説明(参考)

Instrument Node.js apps with OpenTelemetry. Use when a user asks to add distributed tracing, collect metrics, instrument HTTP requests, trace database queries, or set up observability for microservices.

🇯🇵 日本人クリエイター向け解説

一言でいうと

OpenTelemetryを用いてNode.jsアプリケーションに分散トレーシングやメトリクス収集を導入し、HTTPリクエストやデータベースクエリの追跡、マイクロサービス全体の可観測性を向上させる設定を支援するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o otel-js.zip https://jpskill.com/download/15220.zip && unzip -o otel-js.zip && rm otel-js.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15220.zip -OutFile "$d\otel-js.zip"; Expand-Archive "$d\otel-js.zip" -DestinationPath $d -Force; ri "$d\otel-js.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して otel-js.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → otel-js フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Node.js向け OpenTelemetry

概要

OpenTelemetry (OTel) は、分散トレーシング、メトリクス、およびログの標準です。Node.js サービスを一度だけインストルメントし、テレメトリを任意のバックエンド (Jaeger、Grafana Tempo、Datadog、Honeycomb) に送信します。自動インストルメンテーションは、コードを変更することなく HTTP、データベース、および gRPC の呼び出しをキャプチャします。

手順

ステップ 1: 自動インストルメンテーション

npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node \
  @opentelemetry/exporter-trace-otlp-http @opentelemetry/exporter-metrics-otlp-http
// instrumentation.ts — OpenTelemetry のセットアップ (アプリのコードの前にインポート)
import { NodeSDK } from '@opentelemetry/sdk-node'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
import { Resource } from '@opentelemetry/resources'
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'

const sdk = new NodeSDK({
  resource: new Resource({
    [ATTR_SERVICE_NAME]: 'api-service',
    [ATTR_SERVICE_VERSION]: process.env.npm_package_version || '1.0.0',
  }),
  traceExporter: new OTLPTraceExporter({
    url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
  }),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter({
      url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/metrics',
    }),
    exportIntervalMillis: 30000,
  }),
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-http': {
        ignoreIncomingPaths: ['/health', '/ready'],    // ヘルスチェックをトレースしない
      },
      '@opentelemetry/instrumentation-express': { enabled: true },
      '@opentelemetry/instrumentation-pg': { enabled: true },
      '@opentelemetry/instrumentation-redis': { enabled: true },
    }),
  ],
})

sdk.start()
console.log('OpenTelemetry initialized')

process.on('SIGTERM', () => sdk.shutdown())

ステップ 2: カスタムスパン

// services/orders.ts — ビジネスロジックの手動インストルメンテーション
import { trace, SpanStatusCode } from '@opentelemetry/api'

const tracer = trace.getTracer('order-service')

export async function processOrder(orderId: string) {
  return tracer.startActiveSpan('processOrder', async (span) => {
    span.setAttribute('order.id', orderId)

    try {
      // 支払いの子スパン
      const payment = await tracer.startActiveSpan('chargePayment', async (paymentSpan) => {
        paymentSpan.setAttribute('payment.provider', 'stripe')
        const result = await stripe.charges.create({ amount: 9999 })
        paymentSpan.setAttribute('payment.id', result.id)
        paymentSpan.end()
        return result
      })

      span.setAttribute('order.status', 'completed')
      span.setAttribute('payment.id', payment.id)
      span.setStatus({ code: SpanStatusCode.OK })
    } catch (err) {
      span.recordException(err)
      span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
      throw err
    } finally {
      span.end()
    }
  })
}

ステップ 3: 実行

# 最初にインストルメンテーションをロードしてアプリを起動します
node --import ./instrumentation.ts src/server.ts

# または package.json で
# "start": "node --import ./instrumentation.ts dist/server.js"

ガイドライン

  • アプリのコードの前にインストルメンテーションをインポートします — 自動インストルメンテーションは、インポート時にライブラリにパッチを適用します。
  • 最初にインストルメンテーションをロードするには、--import フラグ (ESM) または -r フラグ (CJS) を使用します。
  • 自動インストルメンテーションは、HTTP、Express、Fastify、PostgreSQL、Redis、MongoDB、gRPC をカバーします。
  • ビジネスロジック (注文処理、支払いフロー) にカスタムスパンを追加します — 自動インストルメンテーションはインフラストラクチャのみをカバーします。
  • 複数のバックエンドへのルーティングのために、テレメトリを OTLP コレクター (Grafana Alloy、OTel Collector) に送信します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

OpenTelemetry for Node.js

Overview

OpenTelemetry (OTel) is the standard for distributed tracing, metrics, and logs. Instrument your Node.js services once, and send telemetry to any backend (Jaeger, Grafana Tempo, Datadog, Honeycomb). Auto-instrumentation captures HTTP, database, and gRPC calls without code changes.

Instructions

Step 1: Auto-Instrumentation

npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node \
  @opentelemetry/exporter-trace-otlp-http @opentelemetry/exporter-metrics-otlp-http
// instrumentation.ts — OpenTelemetry setup (import BEFORE app code)
import { NodeSDK } from '@opentelemetry/sdk-node'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
import { Resource } from '@opentelemetry/resources'
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'

const sdk = new NodeSDK({
  resource: new Resource({
    [ATTR_SERVICE_NAME]: 'api-service',
    [ATTR_SERVICE_VERSION]: process.env.npm_package_version || '1.0.0',
  }),
  traceExporter: new OTLPTraceExporter({
    url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
  }),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter({
      url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/metrics',
    }),
    exportIntervalMillis: 30000,
  }),
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-http': {
        ignoreIncomingPaths: ['/health', '/ready'],    // don't trace health checks
      },
      '@opentelemetry/instrumentation-express': { enabled: true },
      '@opentelemetry/instrumentation-pg': { enabled: true },
      '@opentelemetry/instrumentation-redis': { enabled: true },
    }),
  ],
})

sdk.start()
console.log('OpenTelemetry initialized')

process.on('SIGTERM', () => sdk.shutdown())

Step 2: Custom Spans

// services/orders.ts — Manual instrumentation for business logic
import { trace, SpanStatusCode } from '@opentelemetry/api'

const tracer = trace.getTracer('order-service')

export async function processOrder(orderId: string) {
  return tracer.startActiveSpan('processOrder', async (span) => {
    span.setAttribute('order.id', orderId)

    try {
      // Child span for payment
      const payment = await tracer.startActiveSpan('chargePayment', async (paymentSpan) => {
        paymentSpan.setAttribute('payment.provider', 'stripe')
        const result = await stripe.charges.create({ amount: 9999 })
        paymentSpan.setAttribute('payment.id', result.id)
        paymentSpan.end()
        return result
      })

      span.setAttribute('order.status', 'completed')
      span.setAttribute('payment.id', payment.id)
      span.setStatus({ code: SpanStatusCode.OK })
    } catch (err) {
      span.recordException(err)
      span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
      throw err
    } finally {
      span.end()
    }
  })
}

Step 3: Run

# Start app with instrumentation loaded first
node --import ./instrumentation.ts src/server.ts

# Or in package.json
# "start": "node --import ./instrumentation.ts dist/server.js"

Guidelines

  • Import instrumentation BEFORE your app code — auto-instrumentation patches libraries on import.
  • Use --import flag (ESM) or -r flag (CJS) to load instrumentation first.
  • Auto-instrumentation covers HTTP, Express, Fastify, PostgreSQL, Redis, MongoDB, gRPC.
  • Add custom spans for business logic (order processing, payment flows) — auto-instrumentation only covers infrastructure.
  • Send telemetry to an OTLP collector (Grafana Alloy, OTel Collector) for routing to multiple backends.