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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
masso
May 10, 2024
Technology
0
380
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.3k
時系列分析と状態空間モデリングの基礎 / Foundations of Time Series Analysis and State Space Models 0
masso
1
670
わかりやすいパターン認識2章 / Pattern Recognition Manual Easy to understand SS 02
masso
0
1.1k
分析環境紹介LT / the introduction of as my analysis env is
masso
0
140
わかりやすいパターン認識1章 / Pattern Recognition Manual Easy to understand SS 01
masso
0
200
データ解析のための統計モデリング入門6章 / Handbook-of-statistical-modeling-for-data-analysis-section6
masso
0
570
DLGが目指すコミュニティの形 / DLG Community Objective
masso
0
2.8k
PowerAutomateによる社員健康状態集計システム / Employee health status tabulation system with Power Automate
masso
0
1.6k
Other Decks in Technology
See All in Technology
Bill One 開発エンジニア 紹介資料
sansan33
PRO
4
17k
Claude in Chromeで始める自律的フロントエンド開発
diggymo
1
240
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
Riverpod3.xで実現する実践的UI実装
fumiyasac0921
1
270
持続可能な開発のためのミニマリズム
sansantech
PRO
3
480
The Engineer with a Three-Year Cycle - 2
e99h2121
0
160
さくらのクラウドでのシークレット管理を考える/tamachi.sre#2
fujiwara3
1
210
20260120 Amazon VPC のパブリックサブネットを無くしたい!
masaruogura
2
150
VRTと真面目に向き合う
hiragram
1
380
AI アクセラレータチップ AWS Trainium/Inferentia に 今こそ入門
yoshimi0227
1
310
「違う現場で格闘する二人」——社内コミュニティがつないだトヨタ流アジャイルの実践とその先
shinichitakeuchi
0
550
クラウドセキュリティの進化 — AWSの20年を振り返る
kei4eva4
0
150
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
0
1.9k
Building the Perfect Custom Keyboard
takai
2
670
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
100
Making Projects Easy
brettharned
120
6.6k
Docker and Python
trallard
47
3.7k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
430
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Google's AI Overviews - The New Search
badams
0
890
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
160
Utilizing Notion as your number one productivity tool
mfonobong
2
200
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