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
340
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.2k
時系列分析と状態空間モデリングの基礎 / Foundations of Time Series Analysis and State Space Models 0
masso
1
650
わかりやすいパターン認識2章 / Pattern Recognition Manual Easy to understand SS 02
masso
0
1k
分析環境紹介LT / the introduction of as my analysis env is
masso
0
130
わかりやすいパターン認識1章 / Pattern Recognition Manual Easy to understand SS 01
masso
0
190
データ解析のための統計モデリング入門6章 / Handbook-of-statistical-modeling-for-data-analysis-section6
masso
0
550
DLGが目指すコミュニティの形 / DLG Community Objective
masso
0
2.7k
PowerAutomateによる社員健康状態集計システム / Employee health status tabulation system with Power Automate
masso
0
1.5k
Other Decks in Technology
See All in Technology
戦えるAIエージェントの作り方
iwiwi
23
11k
Master Dataグループ紹介資料
sansan33
PRO
1
3.8k
次世代のメールプロトコルの斜め読み
hirachan
3
410
Sansan BIが実践する AI on BI とセマンティックレイヤー / data_summit_findy
sansan_randd
0
110
メタプログラミングRuby問題集の活用
willnet
1
150
DMARCは導入したんだけど・・・現場のつぶやき 〜 BIMI?何それ美味しいの?
hirachan
1
170
OPENLOGI Company Profile for engineer
hr01
1
47k
Kotlinで型安全にバイテンポラルデータを扱いたい! ReladomoラッパーをAIと実装してみた話
itohiro73
3
290
從裝潢設計圖到 Home Assistant:打造智慧家庭的實戰與踩坑筆記
kewang
0
130
kotlin-lsp の開発開始に触発されて、Emacs で Kotlin 開発に挑戦した記録 / kotlin‑lsp as a Catalyst: My Journey to Kotlin Development in Emacs
nabeo
2
370
ソフトウェアエンジニアとデータエンジニアの違い・キャリアチェンジ
mtpooh
1
630
サブドメインテイクオーバー事例紹介と対策について
mikit
16
7.7k
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Site-Speed That Sticks
csswizardry
13
950
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Mobile First: as difficult as doing things right
swwweet
225
10k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Designing for humans not robots
tammielis
254
26k
Producing Creativity
orderedlist
PRO
348
40k
Java REST API Framework Comparison - PWX 2021
mraible
34
8.9k
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