1
1
package zlogsentry
2
2
3
3
import (
4
+ "crypto/x509"
4
5
"io"
5
6
"time"
6
7
"unsafe"
@@ -152,15 +153,24 @@ type optionFunc func(*config)
152
153
153
154
func (fn optionFunc ) apply (c * config ) { fn (c ) }
154
155
156
+ type EventHintCallback func (event * sentry.Event , hint * sentry.EventHint ) * sentry.Event
157
+
155
158
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
164
174
}
165
175
166
176
// WithLevels configures zerolog levels that have to be sent to Sentry.
@@ -214,6 +224,55 @@ func WithDebug() WriterOption {
214
224
})
215
225
}
216
226
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
+
217
276
// New creates writer with provided DSN and options.
218
277
func New (dsn string , opts ... WriterOption ) (* Writer , error ) {
219
278
cfg := newDefaultConfig ()
@@ -222,13 +281,20 @@ func New(dsn string, opts ...WriterOption) (*Writer, error) {
222
281
}
223
282
224
283
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 ,
232
298
})
233
299
234
300
if err != nil {
0 commit comments