• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLKnowledge Workmonitoring

otel-migration

プラグイン
Honeycomb
ソース
GitHub で見る ↗
説明

既存のアプリケーションに 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 移行の計画や順序を決めるとき
本文(日本語訳)

既存アプリケーションへのOpenTelemetry移行ガイド

計測機能がない既存アプリケーションにOpenTelemetryを導入するための手引きです。段階的な移行の方法、コンテキスト伝播(トレース情報の関数間での受け渡し)の改修、ログとメトリクスの連携、そして検証までをカバーしています。ゼロからのOTel導入(otel-instrumentationスキル参照)やBeehive固有の移行(beeline-migrationスキル参照)とは異なります。

このスキルを使う場面

以下のような既存アプリケーションがある場合に使用してください:

  • OpenTelemetryの計測がなく、これを追加する必要がある
  • 既存のログ出力、メトリクス、コンテキスト処理パターンがあり、これらをOTelと共存させる必要がある
  • 関数のシグネチャを改修し、呼び出しチェーン全体でトレース情報を受け渡す必要がある
  • OTelミドルウェアに落とし穴があるフレームワーク(Fiber、Gin、Expressなど)を使用している

ゼロからのOTel導入には、otel-instrumentationスキルを使用してください。 BeehiveからOTelへの移行には、beeline-migrationスキルを使用してください。 計測が必要な理由を理解したい場合は、observability-fundamentalsスキルを参照してください。

移行の6つのステップ

移行は6つのフェーズで進みます。各フェーズは独立して導入・検証できます。 コンテキスト伝播(フェーズ3)が全体作業の約60%を占めるのが一般的です。

フェーズ1: SDK初期化とシャットダウン

TracerProvider、MeterProvider、LoggerProviderをOTLPエクスポーター(テレメトリー送信機能)を使って設定します。初期化をアプリケーションの起動時に、シャットダウンをシグナルハンドラー内に組み込みます。

重要なポイント:

  • SDK初期化は、スパン(トレース単位)を生成する可能性のあるアプリケーションコードより前に実行する必要があります。起動ポイント内で最初の処理にしてください(設定ロードやストレージ初期化より前)
  • シャットダウン順序が重要です。トレースをフラッシュ(送信)してからメトリクス、最後にログという順序で行います。タイムアウトを設定してください(10~30秒)
  • 初期化に失敗した場合でも、アプリケーションは動作し続ける必要があります。エラーをログに記録し、テレメトリーなしで続行してください
  • 言語別のSDK設定について、${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/sdk-setup-by-language.mdを参照してください

フェーズ2: HTTPミドルウェア(自動計測)

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 自動(スレッド局所変数) 計測ライブラリ使用時は特になし

フェーズ3: コンテキスト伝播の改修

トレース情報をHTTPハンドラー(または起点)から呼び出しチェーンを通じてI/O操作まで受け渡します。これが最も難しいフェーズです — 全体作業の約60%を占めることが多いです。

このフェーズの難易度は言語によって大きく異なります:

  • Go:最難関。呼び出しチェーン内のすべての関数にcontext.Contextパラメーターを追加する必要があります
  • Java:中程度。スレッド局所変数のコンテキストは1つのスレッド内では自動的に伝播しますが、スレッドプール、CompletableFuture、リアクティブストリーム(非同期処理パターン)間では断絶します
  • Python:比較的容易。contextvarsはスレッド内では自動的に伝播します。スレッドプールとマルチプロセッシングが課題です
  • Node.js:比較的容易。AsyncLocalStorageがasync/awaitを通じて自動的に伝播します。課題は古いコールバックベースのコードです
  • .NET:最も容易。ActivityがAsyncLocal<T>を通じてasync/awaitで自動的に伝播します
  • Ruby:比較的容易。スレッド局所変数のコンテキストは自動的に伝播します。手動スレッド作成時に課題があります

言語別のパターンとコード例については、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/context-propagation-patterns.mdを参照してください。

フェーズ4: カスタムスパン

自動計測がカバーしないビジネスロジック操作にスパンを追加します。スパン作成の仕組みについてはotel-instrumentationスキルを参照してください。移行固有のポイント:

  1. I/Oの境界から始める — データベース呼び出し、外部HTTP呼び出し、キャッシュ操作
  2. 次にビジネスロジックを追加 — なぜ時間がかかるのかを説明する操作
  3. 属性を自由に追加 — あらゆるコンテキスト情報が調査時に役立ちます
  4. スパンに結果を記録 — ステータス、エラー数、期間を属性として記録

属性の命名とスパン作成パターンについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/custom-instrumentation.mdを参照してください。

フェーズ5: ログの移行

既存のログライブラリをOTelに置き換えるか、OTelに連携させ、ログをトレースに関連付けます。

重要なポイント:

  • ほぼ確実に、ログを標準エラー出力(ローカルデバッグ用)とOTel(トレース関連付け用)の両方に出力したいはずです。複数出力先への分岐パターンが必要です
  • OTelログ連携はキー・バリュー形式の構造化ログで機能します。既存ログがprintf形式の文字列フォーマットを使っている場合は、先に構造化形式に変換してください
  • printf形式から構造化ログへの変換は単調な作業ですが、機械的です。自動リファクタリングの候補になります

言語別のログ連携とマルチハンドラーパターンについては、${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.mdを参照してください。

フェーズ6: メトリクスの連携

既存のPrometheus(別のメトリクスライブラリ)がある場合は、書き直すのではなく、OTelに連携させます。

重要なポイント:

  • Prometheusブリッジ(連携機構)は既存のレジストリから読み取り、OTelメトリクスを生成します。既存のprometheus.NewCounterVec(...)呼び出しは変わりません
  • 既存のスクレイパーがある場合、Prometheus/metricsエンドポイントを維持してください。ブリッジはスクレイピングに加えてOTLP送信を追加します
  • 将来的にPrometheusの依存関係を削除したい場合は、別途の移行を計画してください。ブリッジで時間が稼げます

言語別のメトリクスブリッジについては、${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)の移行結果:

  • 変更ファイル: 約45ファイル、変更行数: +840行/-645行
  • 作業内訳: コンテキスト伝播~60%、カスタムスパン~15%、ログ移行~15%、その他~10%
  • 遭遇したバグ: Fiberのc.Context()対c.UserContext()の混同、printf形式のslogフォーマット文字列、span.End()呼び出し漏れ、ゴルーチンのコンテキスト再利用
原文(English)を表示

OpenTelemetry Migration for Existing Applications

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).

When to Use This Skill

Use this skill when the user has an existing application that:

  • Has no OpenTelemetry instrumentation and needs to add it
  • Has existing logging, metrics, or context patterns that must coexist with OTel
  • Needs to refactor function signatures to thread trace context through the call stack
  • Uses a framework with OTel middleware gotchas (e.g., Fiber, Gin, Express)

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.

Migration Phases

The migration follows six phases in order. Each phase is independently deployable and verifiable. Context propagation (Phase 3) is typically ~60% of the effort.

Phase 1: SDK Initialization and Shutdown

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:

  • SDK init must happen before any application code that might create spans — one of the first things in your entry point, before config loading or storage initialization
  • Shutdown ordering matters: flush traces, then metrics, then logs. Use a timeout (10-30s)
  • If init fails, the application should still work — log the error and continue without telemetry
  • For language-specific SDK setup, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/sdk-setup-by-language.md

Phase 2: HTTP Middleware (Auto-Instrumentation)

Add 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

Phase 3: Context Propagation Refactoring

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:

  • Go: Hardest. Requires adding context.Context parameter to every function in the call chain.
  • Java: Moderate. Thread-local context propagates automatically within a thread, but breaks across thread pools, CompletableFuture, and reactive streams.
  • Python: Easier. contextvars propagates automatically within a thread. Pain points are thread pools and multiprocessing.
  • Node.js: Easier. AsyncLocalStorage propagates through async/await automatically. Pain points are old callback-based code.
  • .NET: Easiest. Activity propagates through async/await via AsyncLocal<T> automatically.
  • Ruby: Easier. Thread-local context propagates automatically. Pain with manual thread creation.

For language-specific patterns and code examples, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/context-propagation-patterns.md.

Phase 4: Custom Spans

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:

  1. Start with I/O boundaries — database calls, external HTTP calls, cache operations
  2. Then add business logic — operations that explain why time is spent
  3. Add attributes liberally — every piece of context makes BubbleUp useful during investigations
  4. Record outcomes on spans — result status, error count, duration as attributes

For attribute naming and span creation patterns, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-instrumentation/references/custom-instrumentation.md.

Phase 5: Logging Migration

Replace or bridge your existing logging library into OTel so logs correlate with traces.

Key guidance:

  • You almost certainly want logs going to both stderr (local debugging) AND OTel (trace correlation). This requires a multi-handler/fan-out pattern.
  • OTel log bridges work with structured logging (key-value pairs). If your existing logging uses printf-style format strings, convert to structured format first.
  • Converting from printf-style to structured logging is tedious but mechanical — a good candidate for automated refactoring.

For language-specific logging bridges and the multi-handler pattern, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md.

Phase 6: Metrics Bridge

If you already have Prometheus metrics (or another metrics library), bridge them to OTel rather than rewriting.

Key guidance:

  • Prometheus bridge reads from the existing registry and produces OTel metrics — existing prometheus.NewCounterVec(...) calls continue unchanged
  • Keep the Prometheus /metrics endpoint if you have existing scrapers. The bridge adds OTLP export in addition to scraping.
  • If you want to eventually remove the Prometheus dependency, plan a separate migration later. The bridge buys you time.

For language-specific metrics bridges, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/bridge-libraries.md.

Verification

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.

Common Pitfalls

For a catalog of common mistakes and how to avoid them, consult ${CLAUDE_PLUGIN_ROOT}/skills/otel-migration/references/migration-pitfalls.md.

Real-World Calibration

For reference, a real migration of Gatus (~30k LOC Go, Fiber v2, SQLite/Postgres, Prometheus):

  • Files changed: ~45, Lines: +840/-645
  • Effort breakdown: Context propagation ~60%, Custom spans ~15%, Logging migration ~15%, Everything else ~10%
  • Bugs encountered: Fiber c.Context() vs c.UserContext(), printf-style slog format strings, missing span.End() calls, goroutine context reuse

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。