Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Stacktrace for rs/zerolog users
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
masso
May 10, 2024
Technology
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stacktrace for rs/zerolog users
Asakusa.go #2 LT from masso
About:
- How to use stacktrace in rs/zerolog
masso
May 10, 2024
More Decks by masso
See All by masso
データ解釈学入門 第一部 / Data hermeneutics Part 1
masso
8
2.4k
時系列分析と状態空間モデリングの基礎 / Foundations of Time Series Analysis and State Space Models 0
masso
1
1k
わかりやすいパターン認識2章 / Pattern Recognition Manual Easy to understand SS 02
masso
0
1.2k
分析環境紹介LT / the introduction of as my analysis env is
masso
0
170
わかりやすいパターン認識1章 / Pattern Recognition Manual Easy to understand SS 01
masso
0
250
データ解析のための統計モデリング入門6章 / Handbook-of-statistical-modeling-for-data-analysis-section6
masso
0
640
DLGが目指すコミュニティの形 / DLG Community Objective
masso
0
3k
PowerAutomateによる社員健康状態集計システム / Employee health status tabulation system with Power Automate
masso
0
1.7k
Other Decks in Technology
See All in Technology
Kiro 入門 (1 つのエージェントを、どの画面からでも) | 目指せ Kiro マスター 01
inariku
PRO
4
830
AI AgentによるEmbedded SREの取り組み
tgidgd
1
350
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
610
現場を動かすAIエージェント#2_製造業現場でのAI活用から見た、ハマる罠と実践知
kintotechdev
2
180
自律的なチームを作るためにTechPMがやらないこと
ny7760
1
520
GCASアップデート(202607-202610)
techniczna
1
200
bpf_arenaとstruct_opsを使うのが難しかった話
masu_mi
0
200
セキュリティ専任チームなしで攻撃を先回りするSREが実践したSIEM on Amazon OpenSearch Service
cscengineer
PRO
0
420
AWS構成から考えるWebセキュリティ ― WordPressの構築経験から考える公開範囲と更新運用【JAWS FESTA 2026 in AKITA】
cscengineer
PRO
1
300
「いつか使う」の「いつか」は来ない 〜AI駆動開発における「作らない」判断について〜
ikki0006
0
140
AI Agent 時代のデータ基盤: ClickHouse で実現する 超高速分析とコスト削減の両立
jozono
0
200
eBPF 簡介 2026 版
shunghsiyu
0
190
Featured
See All Featured
Thoughts on Productivity
jonyablonski
76
5.5k
Everyday Curiosity
cassininazir
0
390
4 Signs Your Business is Dying
shpigford
187
23k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
300
BBQ
matthewcrist
90
10k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
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