ソースマップとスタックトレース
ベータStack traces ↗ help with debugging your code when your application encounters an unhandled exception. Stack traces show you the specific functions that were called, in what order, from which line and file, and with what arguments.
Most JavaScript code is first bundled, often transpiled, and then minified before being deployed to production. This process creates smaller bundles to optimize performance and converts code from Typescript to Javascript if needed.
Source maps translate compiled and minified code back to the original code that you wrote. Source maps are combined with the stack trace returned by the JavaScript runtime to present you with a stack trace.
ソースマップを有効にするには、ワーカーのwrangler.tomlファイルに以下を追加します:
upload_source_maps = trueupload_source_mapsがtrueに設定されている場合、Wranglerはwrangler deployまたはwrangler versions deployを実行するときに自動的にソースマップファイルを生成してアップロードします。
ワーカーが未処理の例外をスローすると、ソースマップを取得し、そのソースマップを使用して例外のスタックトレースをワーカーの元のソースコードの行にマッピングします。
その後、リアルタイムログをストリーミングする際や、Tail Workersでスタックトレースを表示できます。
Cloudflareがスタックトレースをワーカーのソースマップに再マッピングしようとする際、行ごとに再マッピングを行い、可能な限り多くの行を再マッピングします。スタックトレースの行が何らかの理由で再マッピングできない場合、Cloudflareはその行を変更せずにそのままにし、次の行のスタックトレースに進みます。
- Tail Workers - Tail Workersを接続してログを変換し、HTTPエンドポイントに送信する方法を学びます。
- リアルタイムログ - ワーカーのログをリアルタイムでキャプチャする方法を学びます。