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

Commit 322985f

Browse files
committed
Add more options
1 parent 5a39a2b commit 322985f

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

writer.go

+45-25
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,24 @@ type optionFunc func(*config)
153153

154154
func (fn optionFunc) apply(c *config) { fn(c) }
155155

156+
type EventHintCallback func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event
157+
156158
type config struct {
157-
levels []zerolog.Level
158-
sampleRate float64
159-
release string
160-
environment string
161-
serverName string
162-
ignoreErrors []string
163-
debug bool
164-
tracing bool
165-
debugWriter io.Writer
166-
httpProxy string
167-
httpsProxy string
168-
caCerts *x509.CertPool
169-
flushTimeout time.Duration
159+
levels []zerolog.Level
160+
sampleRate float64
161+
release string
162+
environment string
163+
serverName string
164+
ignoreErrors []string
165+
debug bool
166+
tracing bool
167+
debugWriter io.Writer
168+
httpProxy string
169+
httpsProxy string
170+
caCerts *x509.CertPool
171+
flushTimeout time.Duration
172+
beforeSend sentry.EventProcessor
173+
tracesSampleRate float64
170174
}
171175

172176
// WithLevels configures zerolog levels that have to be sent to Sentry.
@@ -227,6 +231,20 @@ func WithTracing() WriterOption {
227231
})
228232
}
229233

234+
// WithTracingSampleRate sets tracing sample rate.
235+
func WithTracingSampleRate(tsr float64) WriterOption {
236+
return optionFunc(func(cfg *config) {
237+
cfg.tracesSampleRate = tsr
238+
})
239+
}
240+
241+
// WithBeforeSend sets a callback which is called before event is sent.
242+
func WithBeforeSend(beforeSend sentry.EventProcessor) WriterOption {
243+
return optionFunc(func(cfg *config) {
244+
cfg.beforeSend = beforeSend
245+
})
246+
}
247+
230248
// WithDebugWriter enables sentry client tracing.
231249
func WithDebugWriter(w io.Writer) WriterOption {
232250
return optionFunc(func(cfg *config) {
@@ -263,18 +281,20 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
263281
}
264282

265283
err := sentry.Init(sentry.ClientOptions{
266-
Dsn: dsn,
267-
SampleRate: cfg.sampleRate,
268-
Release: cfg.release,
269-
Environment: cfg.environment,
270-
ServerName: cfg.serverName,
271-
IgnoreErrors: cfg.ignoreErrors,
272-
Debug: cfg.debug,
273-
EnableTracing: cfg.tracing,
274-
DebugWriter: cfg.debugWriter,
275-
HTTPProxy: cfg.httpProxy,
276-
HTTPSProxy: cfg.httpsProxy,
277-
CaCerts: cfg.caCerts,
284+
Dsn: dsn,
285+
SampleRate: cfg.sampleRate,
286+
Release: cfg.release,
287+
Environment: cfg.environment,
288+
ServerName: cfg.serverName,
289+
IgnoreErrors: cfg.ignoreErrors,
290+
Debug: cfg.debug,
291+
EnableTracing: cfg.tracing,
292+
DebugWriter: cfg.debugWriter,
293+
HTTPProxy: cfg.httpProxy,
294+
HTTPSProxy: cfg.httpsProxy,
295+
CaCerts: cfg.caCerts,
296+
BeforeSend: cfg.beforeSend,
297+
TracesSampleRate: cfg.tracesSampleRate,
278298
})
279299

280300
if err != nil {

0 commit comments

Comments
 (0)