Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Exploring the OpenTelemetry Client Library for Go
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Akari
June 06, 2024
Programming
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Exploring the OpenTelemetry Client Library for Go
Akari
June 06, 2024
More Decks by Akari
See All by Akari
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
2
410
EC2 からの脱出劇:多用途なサーバの全役割をサーバレス・コンテナ環境へ
akarin
2
1.6k
RAILS_ENVを統合する取り組み: 開発用デプロイ環境をよりシンプルに
akarin
3
1.8k
モノレポを採用しているマイクロサービスのCI/CDの現状と課題
akarin
2
400
Other Decks in Programming
See All in Programming
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
240
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
570
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
200
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
170
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
170
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
180
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
470
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
9
5.7k
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.2k
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
190
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
410
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
660
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Done Done
chrislema
186
16k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
230
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
BBQ
matthewcrist
89
10k
Navigating Team Friction
lara
192
16k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Accessibility Awareness
sabderemane
1
160
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Context Engineering - Making Every Token Count
addyosmani
9
1k
Transcript
Exploring the OpenTelemetry Client Library for Go (Unofficial)Go Conference 2024
Pre Party 7 June, 2024 Keisuke Akari @k-akari @akarin0519
1. Reference Please refer the following blog post if you’d
like to know this topic in more detail. - Exploring the OpenTelemetry Client Library for Go
2. What is the OpenTelemetry? There are two key points:
1. Vendor- and Tool-agnostic 2. Focused on the generation, collection, management, and export of telemetry
3. Looking More Specifically Image Source: https://opentelemetry.io/docs/specs/otel/library-guidelines/
4. Where Should We Delve into? - One Signal (I’m
going to single out Tracing here) - Context Propagation Image Source: https://opentelemetry.io/docs/specs/otel/overview/#opentelemetry-client-architecture
5. Structure of the Client Library ./opentelemetry-go ├── internal #
Unexported Detailed Implementation │ └── global │ ├── trace.go │ └── state.go ├── sdk # Core Functionalities │ ├── trace │ │ ├── span.go │ │ └── tracer.go │ ├── go.mod │ └── go.sum ├── trace # Trace API │ ├── config.go │ ├── context.go │ ├── trace.go │ ├── go.sum │ └── go.mod ├── trace.go # API ├── go.mod └── go.sum
6. How Apps Use the Client Library for Tracing package
main import ( "go.opentelemetry.io/otel" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) func main() { // tp := sdktrace.NewTracerProvider( sdktrace.WithSampler(sdktrace.AlwaysSample()), ) otel.SetTracerProvider(tp) ctx, span := otel.Tracer("example").Start(ctx, "span name") defer span.End() // }
7. What is the Context Propagation?
8. Diving into Context Propagation package main import ( "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" "google.golang.org/grpc" ) func main() { // s := grpc.NewServer(grpc.StatsHandler(otelgrpc.NewServerHandler( otelgrpc.WithPropagators(otel.GetTextMapPropagator()), ))) conn, err := grpc.NewClient("endpoint", grpc.WithStatsHandler(otelgrpc.NewClientHandler( otelgrpc.WithPropagators(otel.GetTextMapPropagator()), ))) // }
NewServerHandler returns stats.Handler. 9. otelgrpc.NewServerHandler package otelgrpc import "google.golang.org/grpc/stats" type
serverHandler struct { *config } func NewServerHandler(opts ...Option) stats.Handler { h := &serverHandler{ config: newConfig(opts, "server"), } return h } package stats type Handler interface { TagRPC(context.Context, *RPCTagInfo) context.Context HandleRPC(context.Context, RPCStats) TagConn(context.Context, *ConnTagInfo) context.Context HandleConn(context.Context, ConnStats) }
In TagRPC method, propagator extracts context from metadata and embed
it to context.Context. 10. Extracting Context func (h *serverHandler) TagRPC( ctx context.Context, info *stats.RPCTagInfo, ) context.Context { ctx = extract(ctx, h.config.Propagators) // omitted ctx, _ = h.tracer.Start( trace.ContextWithRemoteSpanContext( ctx, trace.SpanContextFromContext(ctx), ), // omitted ) // omitted return context.WithValue(ctx, gRPCContextKey{}, &gctx) } import ( "google.golang.org/grpc/metadata" "go.opentelemetry.io/otel/propagation" ) func extract( ctx context.Context, propagators propagation.TextMapPropagator, ) context.Context { md, ok := metadata.FromIncomingContext(ctx) if !ok { md = metadata.MD{} } return propagators.Extract(ctx, &metadataSupplier{ metadata: &md, }) }
NewClientHandler returns stats.Handler. 11. otelgrpc.NewClientHandler package otelgrpc import "google.golang.org/grpc/stats" type
clientHandler struct { *config } func NewClientHandler(opts ...Option) stats.Handler { h := &clientHandler{ config: newConfig(opts, "client"), } return h } package stats type Handler interface { TagRPC(context.Context, *RPCTagInfo) context.Context HandleRPC(context.Context, RPCStats) TagConn(context.Context, *ConnTagInfo) context.Context HandleConn(context.Context, ConnStats) }
In TagRPC method, propagator retrieves context from context.Context and inject
it to metadata. 12. Injecting Context func (h *clientHandler) TagRPC( ctx context.Context, info *stats.RPCTagInfo, ) context.Context { // omitted ctx, _ = h.tracer.Start( ctx, // omitted ) // omitted return inject( context.WithValue(ctx, gRPCContextKey{}, &gctx), h.config.Propagators, ) } import ( "google.golang.org/grpc/metadata" "go.opentelemetry.io/otel/propagation"re ) func inject(ctx context.Context, propagators propagation.TextMapPropagator, ) context.Context { md, ok := metadata.FromOutgoingContext(ctx) if !ok { md = metadata.MD{} } propagators.Inject(ctx, &metadataSupplier{ metadata: &md, }) return metadata.NewOutgoingContext(ctx, md) }
Thank you for your attention🙏