0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

OpenTelemetry(Java)のチュートリアルをやってみた

Posted at

はじめに

以下のOpenTelemetry(Java)のチュートリアルをやってみました

実施内容

サンプルソースの取得・コンパイル・テスト実行

  • サンプルソースの取得
$ git clone -b v1.49.0 --depth 1 https://github.com/grpc/grpc-java
  • コンパイル
$ cd grpc-java/examples/
$ ./gradlew installDist
  • サーバサイドプログラムの起動
$ ./build/install/examples/bin/hello-world-server
Sep 18, 2022 1:16:17 AM io.grpc.examples.helloworld.HelloWorldServer start
INFO: Server started, listening on 50051
  • (サーバサイドプログラムを起動した状態で別プロンプトを立ち上げて)クライアントプログラムの起動
$ ./build/install/examples/bin/hello-world-client
Sep 18, 2022 1:16:24 AM io.grpc.examples.helloworld.HelloWorldClient greet
INFO: Will try to greet world ...
Sep 18, 2022 1:16:25 AM io.grpc.examples.helloworld.HelloWorldClient greet
INFO: Greeting: Hello world
  • Ctrl+Cでサーバサイドプログラムを停止

OpenTelemetiryの実行

アプリケーションのソースコード変更が不要な「Automatic Instrumentation」と、アプリケーションのソースコード変更が必要な「Manual Instrumentation」があるが、本チュートリアルでは「Automatic Instrumentation」を使うことになる

  • ライブラリのダウンロード
$ wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

$ ls
opentelemetry-javaagent.jar
  • 環境変数の設定(jarのPATHは自分の環境に合わせて要変更)
$ export JAVA_OPTS="-javaagent:/home/azureuser/opentelemetry-java/lib/opentelemetry-javaagent.jar"
$ export OTEL_TRACES_EXPORTER=logging
  • サーバサイドプログラムの起動
$  ./build/install/examples/bin/hello-world-server
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[otel.javaagent 2022-09-18 01:25:31:075 +0000] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 1.18.0
Sep 18, 2022 1:25:34 AM io.grpc.examples.helloworld.HelloWorldServer start
INFO: Server started, listening on 50051
  • (サーバサイドプログラムを起動した状態で別プロンプトを立ち上げて)クライアントプログラムの起動
$ ./build/install/examples/bin/hello-world-client
Sep 18, 2022 1:25:39 AM io.grpc.examples.helloworld.HelloWorldClient greet
INFO: Will try to greet world ...
Sep 18, 2022 1:25:40 AM io.grpc.examples.helloworld.HelloWorldClient greet
INFO: Greeting: Hello world
  • クライアントプログラムを起動すると、サーバサイドプログラム側のプロンプトでOpenTelemetryのログが出力される
[otel.javaagent 2022-09-18 01:25:40:370 +0000] [grpc-default-executor-0] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'helloworld.Greeter/SayHello' : a236cb09aafc95ec81ee4a09092709bd f3c0cd70d0411a33 SERVER [tracer: io.opentelemetry.grpc-1.6:1.18.0-alpha] AttributesMap{data={thread.id=16, net.sock.peer.port=50190, rpc.grpc.status_code=0, rpc.system=grpc, thread.name=grpc-default-executor-0, net.host.port=50051, net.transport=ip_tcp, net.host.name=localhost, rpc.method=SayHello, rpc.service=helloworld.Greeter, net.sock.peer.addr=127.0.0.1}, capacity=128, totalAddedValues=11}

適当に整形すると以下

[otel.javaagent 2022-09-18 01:25:40:370 +0000] [grpc-default-executor-0] INFO 
io.opentelemetry.exporter.logging.LoggingSpanExporter - 'helloworld.Greeter/SayHello' : 
   a236cb09aafc95ec81ee4a09092709bd    # TraceID
   f3c0cd70d0411a33    # SpanID
   SERVER [tracer: io.opentelemetry.grpc-1.6:1.18.0-alpha]
   AttributesMap {    # 属性 
     data = { 
       thread.id=16,
       net.sock.peer.port=50190,
       rpc.grpc.status_code=0,
       rpc.system=grpc,
       thread.name
         = grpc-default-executor-0,
           net.host.port=50051,
           net.transport=ip_tcp,
           net.host.name=localhost,
           rpc.method=SayHello,
           rpc.service=helloworld.Greeter,
           net.sock.peer.addr=127.0.0.1
     },
     capacity=128,
     totalAddedValues=11
   }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?