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
430
0
Share
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.3k
時系列分析と状態空間モデリングの基礎 / Foundations of Time Series Analysis and State Space Models 0
masso
1
940
わかりやすいパターン認識2章 / Pattern Recognition Manual Easy to understand SS 02
masso
0
1.1k
分析環境紹介LT / the introduction of as my analysis env is
masso
0
160
わかりやすいパターン認識1章 / Pattern Recognition Manual Easy to understand SS 01
masso
0
220
データ解析のための統計モデリング入門6章 / Handbook-of-statistical-modeling-for-data-analysis-section6
masso
0
610
DLGが目指すコミュニティの形 / DLG Community Objective
masso
0
2.9k
PowerAutomateによる社員健康状態集計システム / Employee health status tabulation system with Power Automate
masso
0
1.6k
Other Decks in Technology
See All in Technology
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
探して_入れて_作って_使う_Agent_Skills___LT.pdf
peintangos
2
160
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
180
プラットフォームエンジニア ワークショップ/ platform-workshop
databricksjapan
1
250
JJUG CCC 2026 Spring AI時代の開発こそ標準化を武器に! ― 方式・プロセス・プラットフォームの標準化
s27watanabe
2
710
AI フレンドリーなエラー監視を TypeScript で実現する
shinyaigeek
2
250
Ruby::Boxでできること、Refinementsでできること
joker1007
3
380
Platform Engineering as a Product: Criteria for Improvement and Multi-Tenant Design
kumorn5s
0
490
Javaコミュニティをもっと楽しむための9箇条
takasyou
0
1.2k
AI Engineering Summit Tokyo 2026 AIの前に、やることがある 〜医療データ企業の4フェーズ〜
dtaniwaki
0
1.7k
形式手法特論:公平性制約の位相的特徴づけ #kernelvm / Kernel VM Study Kansai 12th
ytaka23
1
710
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
3
990
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.8k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
400
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
A Soul's Torment
seathinner
6
2.9k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
320
Prompt Engineering for Job Search
mfonobong
0
330
Joys of Absence: A Defence of Solitary Play
codingconduct
1
380
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Bash Introduction
62gerente
615
210k
Between Models and Reality
mayunak
4
320
Utilizing Notion as your number one productivity tool
mfonobong
4
310
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