OpenTelemetry(包括的な監視データ収集システム)を既存の未計測アプリケーションに後付けする際のガイドです。 **次のような場合に使用:** - 既存アプリを OpenTelemetry に移行したい - 既存プロジェクトに OpenTelemetry を追加したい - OpenTelemetry を既存コードベースに後付けしたい - コード内でコンテキスト(処理の流れに付随する情報)を引き継ぎたい - コンテキスト伝播(情報の引き継ぎ)について知りたい - Prometheus メトリクス(性能指標)を OpenTelemetry に橋渡ししたい - ログを OpenTelemetry に移行したい - 既存のログシステム(slog、logback など)と OpenTelemetry を連携させたい - 計測が正しく動作しているか検証したい - トレース(処理の追跡データ)が途切れている - 孤立した span(処理の一単位)が発生している - OpenTelemetry への移行計画を立てたい - 移行を段階的に進める方法を知りたい - 既存コードにトレース機能を追加したい - コンテキスト伝播に対応するよう既存コードをリファクタリングしたい - Fiber フレームワークのコンテキスト処理の注意点を知りたい - 既存のログシステムを OpenTelemetry と共存させたい - 既存の Prometheus 監視を壊さずに OpenTelemetry を追加したい - その他、既存アプリケーションへの OpenTelemetry 後付けに関する質問 **注記:** このスキルは既存システムへの統合向けです。新規構築時の計測(otel-instrumentation スキル参照)や Beeline からの移行(beeline-migration スキル参照)には対応していません。
Guide for retrofitting OpenTelemetry into an existing, uninstrumented application. Trigger phrases: "migrate existing app to OTel", "add OpenTelemetry to existing project", "retrofit OTel into my codebase", "thread context through my code", "context propagation", "bridge Prometheus metrics to OTel", "logging bridge", "migrate logging to OTel", "slog bridge", "logback bridge", "verify my instrumentation", "traces are disconnected", "orphaned spans", "migrate to OpenTelemetry", "OTel migration plan", "how do I sequence an OTel migration", "add tracing to existing code", "refactor for context propagation", "Fiber context gotcha", "keep existing logging working with OTel", "add OTel without breaking Prometheus", "bridge existing metrics", "coexist with existing monitoring", or any request about retrofitting OpenTelemetry into an existing application. This skill is for migrating existing codebases, NOT greenfield instrumentation (use otel-instrumentation) or Beeline-specific migration (use beeline-migration).
計測機能のないアプリケーションにOpenTelemetry(テレメトリーを自動収集するための仕組み)を組み込むための手順書です。段階的な移行アプローチ、コンテキスト伝播のリファクタリング、ログとメトリクスのブリッジ(データ連携)、検証について説明しています。これは新規プロジェクト向けのOTel導入(otel-instrumentationスキルを参照)やBeehive特有の移行(beeline-migrationスキルを参照)とは異なります。
以下のいずれかに該当する既存アプリケーションを扱う場合にこのスキルを使用します。
新規プロジェクト向けのOTel導入は otel-instrumentation スキルを、Beehiveから OTelへの移行は beeline-migration スキルを、計測の必要性についての理解は observability-fundamentals スキルを参照してください。
移行は6つのフェーズを順番に進めます。各フェーズは独立したスケジュールで本番導入でき、検証も可能です。コンテキスト伝播(フェーズ3)が通常、全体作業量の約60%を占めます。
TracerProvider、MeterProvider、LoggerProviderをOTLPエクスポーター(データ送信機)とともに設定します。初期化はアプリケーションの起動時点で行い、シャットダウンはシグナルハンドラ(終了信号の処理)で実行します。
重要なポイント:
${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/sdk-setup-by-language.md を参照してくださいOTelミドルウェアをHTTPフレームワークに追加します。これにより、ハンドラーのコード変更なしにすべての受け取りリクエストに対して自動的にスパンが作成されます。最も効率的なステップです。
重要な注意:
異なるフレームワークではOTelで拡張されたコンテキストの取得方法が異なります。これは隠れたトレース停止の最も一般的な原因です。${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/framework-middleware.md でフレームワーク固有の詳細を確認してください。
| フレームワーク | OTelコンテキストの取得方法 | よくある間違い |
|---|---|---|
| Go net/http | r.Context() |
なし(標準) |
| Go Fiber v2 | c.UserContext() |
c.Context() を使用(OTelスパンなしのfasthtpコンテキストが返る) |
| Go Gin | c.Request.Context() |
c を直接使用 |
| Go Echo | c.Request().Context() |
なし |
| Python Flask | 自動(スレッドローカル変数) | 計測ライブラリ使用時はなし |
| Python Django | 自動(スレッドローカル変数) | 計測ライブラリ使用時はなし |
| Node.js Express | 自動(AsyncLocalStorage) | 計測ライブラリ使用時はなし |
| Java Spring | 自動(スレッドローカル変数) | スレッドプール間でのコンテキスト喪失 |
| .NET ASP.NET Core | 自動(AsyncLocal) | なし |
| Ruby Rails | 自動(スレッドローカル変数) | 計測ライブラリ使用時はなし |
HTTPハンドラー(または開始ポイント)から入出力操作まで、呼び出し階層全体にトレース情報を渡します。このフェーズが最も難しく、通常、移行作業全体の約60%を占めます。
このフェーズの難易度は言語によって大きく異なります。
context.Context パラメーターを追加する必要がありますcontextvars はスレッド内で自動的に伝播します。スレッドプールとマルチプロセッシングが痛い部分ですAsyncLocalStorage はasync/awaitを通じて自動的に伝播します。古いコールバック方式のコードが痛い部分ですActivity はAsync/awaitを通じて AsyncLocal<T> で自動的に伝播します言語別のパターンとコード例については、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/context-propagation-patterns.md を参照してください。
自動計測では対応しないビジネスロジック操作にスパンを追加します。スパン作成の仕組みについては otel-instrumentation スキルに従います。移行固有のガイダンス:
属性の名付けルールとスパン作成パターンについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/custom-instrumentation.md を参照してください。
既存のログライブラリをOTelに置き換えるか、ブリッジさせてログとトレースを関連付けます。
重要なポイント:
言語別のログブリッジとマルチハンドラーパターンについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md を参照してください。
既存のPrometheus(監視メトリクス)またはその他のメトリクスライブラリがある場合、ブリッジでOTelに接続してください。書き直す必要はありません。
重要なポイント:
prometheus.NewCounterVec(...) 呼び出しは変更不要です/metrics エンドポイントは維持してください。ブリッジはスクレイピングに加えてOTLPエクスポートを追加します言語別のメトリクスブリッジについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md を参照してください。
各フェーズの完了後、計測が正しく、完全であることを確認します。${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/verification-checklist.md で全チェックリストとクエリパターンを確認してください。
Honeycombアカウントなしでローカルで検証するには、付属のコレクタースクリプトを使用してスパンをデバッグ出力とNDJSON(改行区切りのJSON)として取得できます。使用方法は ${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/local-collector-debug-test.md を、完全なスクリプトは ${CLAUDE_PLUGIN_ROOT}/scripts/start-collector.sh を参照してください。
Honeycomb固有の検証クエリについては、query-patterns スキルも参照してください。
一般的な間違いとその回避方法については、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/migration-pitfalls.md を参照してください。
参考として、実際のGatusプロジェクト(約30,000行のGoコード、Fiber v2、SQLite/Postgres、Prometheus)の移行:
c.Context() 対 c.UserContext() の混淆、printf形式のslogフォーマット文字列、スパンの End() 呼び出し忘れ、ゴルーチン(Go言語の軽量スレッド)のコンテキスト再利用Guide for retrofitting OpenTelemetry into an existing, uninstrumented application. This covers the phased migration approach, context propagation refactoring, logging and metrics bridges, and verification. This is distinct from greenfield OTel setup (see otel-instrumentation skill) and Beeline-specific migration (see beeline-migration skill).
Use this skill when the user has an existing application that:
For greenfield OTel setup, use the otel-instrumentation skill instead.
For Beeline-to-OTel migration, use the beeline-migration skill instead.
For understanding why to instrument, see the observability-fundamentals skill.
The migration follows six phases in order. Each phase is independently deployable and verifiable. Context propagation (Phase 3) is typically ~60% of the effort.
Set up TracerProvider, MeterProvider, and LoggerProvider with OTLP exporters. Wire initialization early in the application's entry point and shutdown in signal handlers.
Key guidance:
${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/sdk-setup-by-language.mdAdd OTel middleware to your HTTP framework. This gives you automatic spans for every inbound request with zero code changes to handlers. This is the highest-ROI step.
Critical: Different frameworks expose the OTel-enriched context differently. This is the #1
source of silent trace breaks. Consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/framework-middleware.md for
framework-specific details.
| Framework | How to get OTel context | Common mistake |
|---|---|---|
| Go net/http | r.Context() |
N/A (standard) |
| Go Fiber v2 | c.UserContext() |
Using c.Context() (returns fasthttp context without OTel span) |
| Go Gin | c.Request.Context() |
Using c directly |
| Go Echo | c.Request().Context() |
N/A |
| Python Flask | Automatic (thread-local) | N/A with instrumentation library |
| Python Django | Automatic (thread-local) | N/A with instrumentation library |
| Node.js Express | Automatic (AsyncLocalStorage) | N/A with instrumentation library |
| Java Spring | Automatic (thread-local) | Thread pool context loss |
| .NET ASP.NET Core | Automatic (AsyncLocal) | N/A |
| Ruby Rails | Automatic (thread-local) | N/A with instrumentation library |
Thread trace context through your call chain from HTTP handlers (or entry points) down to I/O operations. This is the hardest phase — typically ~60% of migration effort.
The difficulty of this phase varies dramatically by language:
context.Context parameter to every function in the call chain.contextvars propagates automatically within a thread. Pain points are
thread pools and multiprocessing.AsyncLocalStorage propagates through async/await automatically.
Pain points are old callback-based code.Activity propagates through async/await via AsyncLocal<T> automatically.For language-specific patterns and code examples, consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/context-propagation-patterns.md.
Add spans to business logic operations that auto-instrumentation doesn't cover. Defer to the
otel-instrumentation skill for span creation mechanics. Migration-specific guidance:
For attribute naming and span creation patterns, consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/custom-instrumentation.md.
Replace or bridge your existing logging library into OTel so logs correlate with traces.
Key guidance:
For language-specific logging bridges and the multi-handler pattern, consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md.
If you already have Prometheus metrics (or another metrics library), bridge them to OTel rather than rewriting.
Key guidance:
prometheus.NewCounterVec(...) calls continue unchanged/metrics endpoint if you have existing scrapers. The bridge adds OTLP
export in addition to scraping.For language-specific metrics bridges, consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md.
After each phase, verify that instrumentation is correct and complete. Consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/verification-checklist.md for the
full checklist and query patterns.
To verify locally without a Honeycomb account, use the bundled collector script to capture
spans as debug output and NDJSON. Consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/local-collector-debug-test.md for usage, and
${CLAUDE_PLUGIN_ROOT}/scripts/start-collector.sh for the full script.
For Honeycomb-specific verification queries, also consult the query-patterns skill.
For a catalog of common mistakes and how to avoid them, consult
${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/migration-pitfalls.md.
For reference, a real migration of Gatus (~30k LOC Go, Fiber v2, SQLite/Postgres, Prometheus):
c.Context() vs c.UserContext(), printf-style slog format strings,
missing span.End() calls, goroutine context reuse原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。