package sentry

import (
	"github.com/TheZeroSlave/zapsentry"
	"github.com/getsentry/sentry-go"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func AddSentrytoLogger(dsn string, env string) (zap.Option, error) {
	sentryClient, err := sentry.NewClient(sentry.ClientOptions{
		Dsn:              dsn,
		TracesSampleRate: 1.0,
		Environment:      env,
	})
	if err != nil {
		return nil, err
	}
	cfg := zapsentry.Configuration{
		Level:             zapcore.ErrorLevel, // when to send message to sentry
		EnableBreadcrumbs: true,               // enable sending breadcrumbs to Sentry
		BreadcrumbLevel:   zapcore.InfoLevel,  // at what level should we sent breadcrumbs to sentry
	}
	sentryCore, err := zapsentry.NewCore(cfg, zapsentry.NewSentryClientFromClient(sentryClient))
	if err != nil {
		return nil, err
	}
	return zap.WrapCore(func(core zapcore.Core) zapcore.Core {
		return zapcore.NewTee(core, sentryCore)
	}), nil
}
