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
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
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
130
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
320
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
どこまでゆるくて許されるのか
tk3fftk
0
300
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.2k
dRuby over BLE
makicamel
2
400
The NotImplementedError Problem in Ruby
koic
1
1.1k
Vite+ Unified Toolchain for the Web
naokihaba
0
410
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.6k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
810
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
2
370
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
360
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
210
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Agile that works and the tools we love
rasmusluckow
331
22k
Navigating Team Friction
lara
192
16k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Un-Boring Meetings
codingconduct
0
330
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.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🙏