DEV Community

Thanabodee Charoenpiriyakij
Thanabodee Charoenpiriyakij

Posted on

1 1

ใช้งาน Jaeger trace ร่วมกับ OpenTelemetry

จากบทความ ที่แล้วเราใช้ exporter เป็นแบบ stdout เพื่อส่ง traces ออกไปที่ stdout ของ os คราวนี้เราจะมาใช้งานร่วมกับ Jaeger กัน

ในบทความนี้ผมใช้ jaeger แบบ all-in-one เพื่อให้ง่ายต่อการ setup และทดสอบโดยสามารถได้ด้วย docker แบบนี้

$ docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
  -p 5775:5775/udp \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14268:14268 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.8

จากนั้นเราจะเปลี่ยน exporter จาก stdout เป็น jaeger โดยใช้ package go.opentelemetry.io/otel/exporter/trace/jaeger

$ go get -v go.opentelemetry.io/otel/exporter/trace/jaeger@v0.2.1
import (
    // ...
    "go.opentelemetry.io/otel/exporter/trace/jaeger"
)

// in initTrace().
exporter, err := jaeger.NewExporter(
    jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"),
    jaeger.WithProcess(
        jaeger.Process{
            ServiceName: "github.com/wingyplus/basic",
        },
    ),
)
if err != nil {
    log.Fatalf("have some problems while creating jaeger exporter: %v", err)
}

จากนั้นทำการรันด้วย go run และเปิด Jaeger UI มาดูผ่าน http://localhost:16686 จะเห็นแบบรูปด้านล่าง

Alt Text
Alt Text

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay