分散トレーシング
概要
最近は、複数のサービスが互いに連携し合う形態が増えている
多くのサービスやマイクロサービスに依存したアプリケーションのアーキテクチャを分散システムと呼ぶ
分散トレーシング (Distributed Tracing) は、アプリケーションへのリクエストの結果起こる動作のトラッキングを行うプロセスのこと。以下が特徴
複雑なシステム間を辿ったリクエストパスをトレースする
パス内のコンポーネントのレイテンシーを発見する
パス内のどのコンポーネントがボトルネックになっているのかを知る
https://docs.newrelic.com/docs/apm/distributed-tracing/getting-started/introduction-distributed-tracing#definition
歴史
Barham, Paul, et al. "Magpie: Online Modelling and Performance-aware Systems." HotOS. 2003.
Fonseca, Rodrigo, et al. "X-trace: A pervasive network tracing framework." Proceedings of the 4th USENIX conference on Networked systems design & implementation. USENIX Association, 2007.
Sigelman, Benjamin H., et al. Dapper, a large-scale distributed systems tracing infrastructure. Technical report, Google, Inc, 2010.
Google の Dapper, a Large-Scale Distributed Systems Tracing Ingrastructure という論文から、記載されているツール Dapper をベースに Zipkin、さらに Dapper, Zipkin をベースにした appdash、HSFS や HBase に使われている HTrace 等の OSS が開発された。
分散トレーシング の API 仕様をとりまとめた OpenTracing も登場している。
関連ソフトウェア/ツール
たぶんクライアントとライブラリが混在しているのであとで分ける。
Zipkin
概要
分散トレーシングシステム。
https://zipkin.io/
アーキテクチャ
Reporter : ログを送信する。
Collector : ログを収集する。HTTP, Kafka, RabbitMQ, Scribe がサポートされている
Storage : ログを永続化する。In-Memory, MySQL, Cassandra, Elasticsearch がサポートされている
API : Storage から様々な方法でデータを抽出する
UI : ログの検索、可視化を行える
https://zipkin.io/public/img/architecture-1.png
https://zipkin.io/pages/architecture.html
Jeager
概要
分散トレーシングシステム。
https://github.com/jaegertracing/jaeger
https://www.jaegertracing.io/
アーキテクチャ
Jaeger client libraries : 特定言語における OpenTracing API の実装
Agent : UDP 経由で Span を送信するネットワークデーモン
Collector : agent から trace を受け取る。Storage には Cassandra, Elasticsearch, Kafna がサポートされている
https://www.jaegertracing.io/img/architecture.png
https://www.jaegertracing.io/docs/1.9/architecture/
AWS X-Ray
概要
分散アプリケーションの分析、デバッグ用サービス
https://aws.amazon.com/jp/xray/
アーキテクチャ
EC2, ECS, Lambda, Beanstalk で実行されているアプリケーションに利用可能
アプリケーションに X-Ray SDK を組み込み、環境にエージェントをインストールする
Beanstalk では事前にインストール済み
OpenCensus
概要
メトリクス収集、分散トレーシング のためのライブラリ群。データの収集までを担い、グラフ化や分析は他のサービスを利用する。Google が車内で利用しているメトリクス収集、トレーシングのライブラリ集 Census の OSS バージョンとして2018/1 にリリースされた。
https://opencensus.io/
その他参考
https://heartbeats.jp/hbblog/2018/09/opencensus.html
モニタリングサービスとしては DataDog 等と組み合わせられる。
StackDriver Trace
概要
GCP 用の分散トレーシングシステム
https://cloud.google.com/trace/?hl=ja
NewRelic
2018 年夏に発表された。以前の corss application tracing feature の代替。違いは、サービス横断的なアクティビティの詳細と、E2Eの可視化。
https://docs.newrelic.com/docs/apm/distributed-tracing/getting-started/introduction-distributed-tracing#definition
必須項目
APM Pro のサブスクリプション
APM のバージョン
https://docs.newrelic.com/docs/apm/distributed-tracing/enable-configure/enable-distributed-tracing#compatibility-requirements
https://newrelic.degica.com/docs/apm/distributed-tracing/getting-started/how-new-relic-distributed-tracing-works
設定方法
https://github.com/polfliet/newrelic-k8s-guestbook/blob/efb684b19acbf5759fea352730e66d28e243f720/app/parser/newrelic.js#L600-L615
このままだと、当然ながら Resolver 毎の値はとれない
NewRelic APM 分散トレーシング
https://newrelic.degica.com/blog/2018-08-27-distributed-tracing-general-availability
参考ポスト
https://blog.newrelic.com/engineering/understanding-distributed-tracing/
NewRelic の分散トレーシングの仕組み
https://newrelic.degica.com/docs/apm/distributed-tracing/getting-started/how-new-relic-distributed-tracing-works#example-queries
カスタムで追加する場合
https://docs.newrelic.com/docs/apm/distributed-tracing/enable-configure/enable-distributed-tracing#agent-apis
なんか色々追加するようだが、よくわからない
https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api#transaction-handle-createDistributedTracePayload
追加のためのサンプルコード
https://github.com/newrelic/node-newrelic/blob/1d24bda251809904f597b0466cb9dc2836ffee18/examples/api/distributed-tracing/example1-background.js
newrelic ようの apollo
https://github.com/localshred/apollo-newrelic-extension
参考サイト
https://www.slideshare.net/td-nttcom/open-tracingjaeger
https://speakerdeck.com/fujiwara3/yapc-tokyo-2019