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

Commit abe3e64

Browse files
authored
Merge pull request #7 from lzap/new-opts
Add new options
2 parents 22731d7 + 322985f commit abe3e64

File tree

1 file changed

+81
-15
lines changed

1 file changed

+81
-15
lines changed

writer.go

+81-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package zlogsentry
22

33
import (
4+
"crypto/x509"
45
"io"
56
"time"
67
"unsafe"
@@ -152,15 +153,24 @@ type optionFunc func(*config)
152153

153154
func (fn optionFunc) apply(c *config) { fn(c) }
154155

156+
type EventHintCallback func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event
157+
155158
type config struct {
156-
levels []zerolog.Level
157-
sampleRate float64
158-
release string
159-
environment string
160-
serverName string
161-
ignoreErrors []string
162-
debug bool
163-
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
164174
}
165175

166176
// WithLevels configures zerolog levels that have to be sent to Sentry.
@@ -214,6 +224,55 @@ func WithDebug() WriterOption {
214224
})
215225
}
216226

227+
// WithTracing enables sentry client tracing.
228+
func WithTracing() WriterOption {
229+
return optionFunc(func(cfg *config) {
230+
cfg.tracing = true
231+
})
232+
}
233+
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+
248+
// WithDebugWriter enables sentry client tracing.
249+
func WithDebugWriter(w io.Writer) WriterOption {
250+
return optionFunc(func(cfg *config) {
251+
cfg.debugWriter = w
252+
})
253+
}
254+
255+
// WithHttpProxy enables sentry client tracing.
256+
func WithHttpProxy(proxy string) WriterOption {
257+
return optionFunc(func(cfg *config) {
258+
cfg.httpProxy = proxy
259+
})
260+
}
261+
262+
// WithHttpsProxy enables sentry client tracing.
263+
func WithHttpsProxy(proxy string) WriterOption {
264+
return optionFunc(func(cfg *config) {
265+
cfg.httpsProxy = proxy
266+
})
267+
}
268+
269+
// WithCaCerts enables sentry client tracing.
270+
func WithCaCerts(caCerts *x509.CertPool) WriterOption {
271+
return optionFunc(func(cfg *config) {
272+
cfg.caCerts = caCerts
273+
})
274+
}
275+
217276
// New creates writer with provided DSN and options.
218277
func New(dsn string, opts ...WriterOption) (*Writer, error) {
219278
cfg := newDefaultConfig()
@@ -222,13 +281,20 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
222281
}
223282

224283
err := sentry.Init(sentry.ClientOptions{
225-
Dsn: dsn,
226-
SampleRate: cfg.sampleRate,
227-
Release: cfg.release,
228-
Environment: cfg.environment,
229-
ServerName: cfg.serverName,
230-
IgnoreErrors: cfg.ignoreErrors,
231-
Debug: cfg.debug,
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,
232298
})
233299

234300
if err != nil {

0 commit comments

Comments
 (0)