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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akari
June 06, 2024
Programming
450
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
390
Other Decks in Programming
See All in Programming
AI 輔助遺留系統現代化的經驗分享
jame2408
1
940
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
6.1k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
170
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
140
1B+ /day規模のログを管理する技術
broadleaf
0
100
AIで効率化できた業務・日常
ochtum
0
140
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
210
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
600
dRuby over BLE
makicamel
2
380
ふつうのFeature Flag実践入門
irof
8
4.1k
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.4k
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
260
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Design in an AI World
tapps
1
250
Code Reviewing Like a Champion
maltzj
528
40k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Claude Code のすすめ
schroneko
67
230k
Abbi's Birthday
coloredviolet
2
8.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
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🙏