既存のアプリケーションに OpenTelemetry(アプリケーションの動作状況を詳細に記録するための仕組み)を後付けするためのガイド。 **使用する場合:** 「既存アプリを OTel に移行したい」「既存プロジェクトに OpenTelemetry を追加したい」「現在のコードベースに OTel を組み込みたい」「コード内でコンテキスト情報を引き継ぎたい」「コンテキスト伝播(異なる処理間で情報を受け渡すこと)」「Prometheus メトリクス(計測データ)を OTel に橋渡ししたい」「ログシステムを接続し直したい」「ログ出力を OTel に移行したい」「slog 対応」「logback 対応」「計測内容を確認したい」「トレース(処理の流れを記録したもの)が断片化している」「孤立したスパン(個別の処理記録)が生じている」「OpenTelemetry への移行」「OTel 移行計画を立てたい」「OTel 移行の順序を決めるには」「既存コードにトレース機能を追加したい」「コンテキスト伝播に向けてコードを整理したい」「Fiber フレームワークでのコンテキスト処理の落とし穴」「既存ログシステムを OTel と共存させたい」「Prometheus メトリクスを破損させずに OTel を追加したい」「既存メトリクスを接続し直したい」「現在の監視システムと両立させたい」、またはその他既存アプリケーションへの 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ハンドラー(または起点)から呼び出しチェーンを通じてI/O操作まで受け渡します。これが最も難しいフェーズです — 全体作業の約60%を占めることが多いです。
このフェーズの難易度は言語によって大きく異なります:
context.Contextパラメーターを追加する必要がありますcontextvarsはスレッド内では自動的に伝播します。スレッドプールとマルチプロセッシングが課題ですAsyncLocalStorageがasync/awaitを通じて自動的に伝播します。課題は古いコールバックベースのコードですActivityがAsyncLocal<T>を通じてasync/awaitで自動的に伝播します言語別のパターンとコード例については、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/context-propagation-patterns.mdを参照してください。
自動計測がカバーしないビジネスロジック操作にスパンを追加します。スパン作成の仕組みについてはotel-instrumentationスキルを参照してください。移行固有のポイント:
属性の命名とスパン作成パターンについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/custom-instrumentation.mdを参照してください。
既存のログライブラリをOTelに置き換えるか、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形式で取得できます。使用法は${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フォーマット文字列、span.End()呼び出し漏れ、ゴルーチンのコンテキスト再利用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 による自動翻訳です。