Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

use zerolog.LevelWriter interface for performance #9

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

krombel
Copy link
Contributor

@krombel krombel commented Jun 21, 2023

If we log something (e.g. as local log level got set to debug) but we only want to send events for Error to sentry, each event is parsed to check for the log level.

As there is the LevelWriter interface as zerolog suggests for multiple outputs here. That way we might skip parsing the event if the log level is disabled.

This PR implements this.

For reference I implemented benchmarks as well. This are the results on my device

# make benchmarks
[...]
pkg: github.com/archdx/zerolog-sentry
BenchmarkParseLogEvent-8                          272346              3806 ns/op            5136 B/op         14 allocs/op
BenchmarkParseLogEvent_DisabledLevel-8            253910              4014 ns/op            5136 B/op         14 allocs/op
BenchmarkWriteLogEvent-8                           65269             21795 ns/op           12586 B/op        109 allocs/op
BenchmarkWriteLogEvent_Disabled-8               20960934             57.01 ns/op               0 B/op          0 allocs/op
BenchmarkWriteLogLevelEvent-8                      68061             16895 ns/op           12618 B/op        109 allocs/op
BenchmarkWriteLogLevelEvent_DisabledLevel-8    167343889             6.876 ns/op               0 B/op          0 allocs/op
PASS
ok      github.com/archdx/zerolog-sentry        9.532s

@krombel krombel force-pushed the useLevelWriterInterface branch from 43ad775 to fde250b Compare June 21, 2023 15:40
@codecov-commenter
Copy link

Codecov Report

Merging #9 (fde250b) into master (22731d7) will decrease coverage by 5.73%.
The diff coverage is 18.51%.

@@            Coverage Diff             @@
##           master       #9      +/-   ##
==========================================
- Coverage   53.17%   47.44%   -5.73%     
==========================================
  Files           1        1              
  Lines         126      137      +11     
==========================================
- Hits           67       65       -2     
- Misses         51       67      +16     
+ Partials        8        5       -3     
Impacted Files Coverage Δ
writer.go 47.44% <18.51%> (-5.73%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@krombel krombel force-pushed the useLevelWriterInterface branch 2 times, most recently from 594f683 to b4bdddf Compare June 26, 2023 18:36
@krombel krombel force-pushed the useLevelWriterInterface branch from b4bdddf to e81a73f Compare June 26, 2023 19:32
@archdx archdx merged commit 1fa3486 into archdx:master Jul 6, 2023
@krombel krombel deleted the useLevelWriterInterface branch July 9, 2023 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants