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
Stacktrace for rs/zerolog users
Search
masso
May 10, 2024
Technology
0
260
Stacktrace for rs/zerolog users
Asakusa.go #2 LT from masso
About:
- How to use stacktrace in rs/zerolog
masso
May 10, 2024
Tweet
Share
More Decks by masso
See All by masso
データ解釈学入門 第一部 / Data hermeneutics Part 1
masso
8
2.1k
時系列分析と状態空間モデリングの基礎 / Foundations of Time Series Analysis and State Space Models 0
masso
0
580
わかりやすいパターン認識2章 / Pattern Recognition Manual Easy to understand SS 02
masso
0
930
分析環境紹介LT / the introduction of as my analysis env is
masso
0
120
わかりやすいパターン認識1章 / Pattern Recognition Manual Easy to understand SS 01
masso
0
160
データ解析のための統計モデリング入門6章 / Handbook-of-statistical-modeling-for-data-analysis-section6
masso
0
520
DLGが目指すコミュニティの形 / DLG Community Objective
masso
0
2.6k
PowerAutomateによる社員健康状態集計システム / Employee health status tabulation system with Power Automate
masso
0
1.5k
Other Decks in Technology
See All in Technology
MCPを理解する
yudai00
12
8.3k
バクラクの認証基盤の成長と現在地 / bakuraku-authn-platform
convto
4
860
営業向け誰でも話せるOCIセールストーク
oracle4engineer
PRO
2
140
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
2
420
Microsoft Fabric vs Databricks vs (Snowflake) -若手エンジニアがそれぞれの強みと違いを比較してみた- "A Young Engineer's Comparison of Their Strengths and Differences"
reireireijinjin6
1
120
Compose におけるパスワード自動入力とパスワード保存
tonionagauzzi
0
170
AIエージェント開発手法と業務導入のプラクティス
ykosaka
9
2.6k
白金鉱業Meetup_Vol.18_AIエージェント時代のUI/UX設計
brainpadpr
1
270
AIと共に乗り越える、 入社後2ヶ月の苦労と学習の軌跡
sai_kaneko
0
180
2025-04-14 Data & Analytics 井戸端会議 Multi tenant log platform with Iceberg
kamijin_fanta
0
150
より良い開発者体験を実現するために~開発初心者が感じた生成AIの可能性~
masakiokuda
0
230
コスト最適重視でAurora PostgreSQLのログ分析基盤を作ってみた #jawsug_tokyo
non97
1
830
Featured
See All Featured
Six Lessons from altMBA
skipperchong
28
3.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Designing for Performance
lara
608
69k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
A Tale of Four Properties
chriscoyier
158
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.4k
A designer walks into a library…
pauljervisheath
205
24k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
Rails Girls Zürich Keynote
gr2m
94
13k
RailsConf 2023
tenderlove
30
1.1k
We Have a Design System, Now What?
morganepeng
52
7.5k
The Pragmatic Product Professional
lauravandoore
33
6.6k
Transcript
stacktrace for zerolog users zerolog 使いのための stacktrace Asakusa.go #2 -
Title 2024/05/10 @masso 1
Index type Index struct { Title string PresentationLength float64 //
[minutes] } var indexes = []Index{ {"Self Introduction", 0.5}, {"We're using zerolog", 0.5}, {"The mechanism of stacktrace in zerolog", 1}, {"How to customize stacktrace in zerolog", 1.5}, {"Q&A", 1}, } Asakusa.go #2 - Title 2024/05/10 @masso 2
Self Introduction GitHub: @sota0121 I'm working at Money Forward, Inc.
as a full- stack software engineer. Go, TypeScript, React, Next.js, AWS, k8s, Terraform, etc. Asakusa.go #2 - Title 2024/05/10 @masso 3
We're using zerolog rs/zerolog: Zero Allocation JSON Logger Structured logging
with simple API that is inspired by go.uber.org/zap Main features are here Asakusa.go #2 - Title 2024/05/10 @masso 4
The mechanism of stacktrace in zerolog - basic usage import
( "github.com/rs/zerolog" "github.com/rs/zerolog/pkgerrors" ) zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack func printStackTrace(err error) { // setLogFields ze := log.WithLevel(zerolog.ErrorLevel).Caller(2) // Stacktrace ze.Stack().Err(err).Msg("") } Asakusa.go #2 - Title 2024/05/10 @masso 5
The mechanism of stacktrace in zerolog details main codes rs/zerolog/event.go,
rs/zerolog/globals.go, rs/zerolog/pkgerrors/stacktrace.go stackTracer interface を満たすものを Unwrap しながら探る // pkgerrors/stacktrace.go import "github.com/pkg/errors" func MarshalStack(err error) interface{} { type stackTracer interface { StackTrace() errors.StackTrace } var sterr stackTracer var ok bool for err != nil { sterr, ok = err.(stackTracer) if ok { break } u, ok := err.(interface { Unwrap() error }) if !ok { return nil } err = u.Unwrap() } if sterr == nil { return nil } Asakusa.go #2 - Title 2024/05/10 @masso 6
How to customize stacktrace in zerolog 自前のスタックトレース処理を利用したい場合は、 zerolog.ErrorStackMarshaler に設定する signature:
func(err error) interface{} import "github.com/pkg/errors" func CustomFormatStackTrace(err error) string { if err, ok := err.(interface{ StackTrace() errors.StackTrace }); ok { stack := err.StackTrace() formatted := "" for _, frame := range stack { formatted += fmt.Sprintf("%+v\n", frame) } return formatted } return "No stack trace available" } Asakusa.go #2 - Title 2024/05/10 @masso 7
Q&A Asakusa.go #2 - Title 2024/05/10 @masso 8