Documentation
¶
Index ¶
- func FlushSentry(timeout time.Duration)
- func GetSentryClient() *sentry.Client
- func GetSentryClientOptions() *sentry.ClientOptions
- func GetSentryDataMap() (dt map[string]interface{})
- func InitSentry(options SentryOptions) *sentry.Client
- func InitSentryOptions(options SentryOptions)
- func NewSentryData(dt *SentryData)
- func ReceiveLog(level, message string)
- func RegisterSentryLogHook()
- func SendSentryDebug(err error, args ...string)
- func SendSentryError(err error, args ...string)
- func SendSentryErrorWithContext(ctx context.Context, err error, args ...string)
- func SendSentryEvent(event *sentry.Event, args ...string)
- func SendSentryMessage(msg string, args ...string)
- func SendSentryWarning(err error, args ...string)
- func SendToSentryDebug(err error, service, module, function string)
- func SendToSentryError(err error, service, module, function string)
- func SendToSentryEvent(event *sentry.Event, service, module, function string)
- func SendToSentryMessage(message string, service, module, function string)
- func SendToSentryWarning(err error, service, module, function string)
- func SentryEnabled() bool
- type SentryData
- type SentryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlushSentry ¶
FlushSentry waits for buffered Sentry events to be sent, up to timeout. Call this before process exit (e.g. in shutdown handler) to avoid losing events.
func GetSentryClient ¶
func GetSentryClientOptions ¶
func GetSentryClientOptions() *sentry.ClientOptions
func GetSentryDataMap ¶
func GetSentryDataMap() (dt map[string]interface{})
func InitSentry ¶
func InitSentry(options SentryOptions) *sentry.Client
InitSentry creates the global Sentry client. Returns nil when Dsn is empty. For SDK verbose logging, set options.Debug (often from a service-level SENTRY_DEBUG env); see SentryOptions.
func InitSentryOptions ¶
func InitSentryOptions(options SentryOptions)
InitSentryOptions merges options into the package-level sentry.ClientOptions without creating a client. No-op when Dsn is empty. See SentryOptions.Debug for the meaning of the Debug field (SDK diagnostics).
func NewSentryData ¶
func NewSentryData(dt *SentryData)
func ReceiveLog ¶
func ReceiveLog(level, message string)
ReceiveLog forwards a log event to Sentry based on the level. This is called by log hook subscribers — do not call directly. level: "debug" | "info" | "warn" | "error" | "fatal" message: formatted log string
For error and fatal levels the event is sent as a structured exception so that Sentry populates the "error message" field and splits the issue title cleanly:
- Exception.Type → the [FunctionName] bracket prefix (e.g. "ReadyCheck")
- Exception.Value → the rest of the message (the actual error detail)
All other levels are sent as plain messages.
func RegisterSentryLogHook ¶
func RegisterSentryLogHook()
RegisterSentryLogHook registers the Sentry log hook with phlogger. This allows all logs emitted via phlogger (LogI, LogE, etc.) to be forwarded to Sentry. Multiple calls are safe; only the first call takes effect.
The hook integrates with the Sentry SDK's structured logging by: - Forwarding info/debug/warn logs as breadcrumbs - Forwarding error/fatal logs as exception events - Extracting [FunctionName] prefixes for issue grouping
Call this function during service initialization after InitSentry() has completed. If called before InitSentry(), the hook will silently skip until a Sentry client is initialized.
Example:
phsentry.InitSentry(options)
phsentry.RegisterSentryLogHook()
phlogger.LogE("[main] database error: %v", err) // forwarded to Sentry
func SendSentryDebug ¶
SendSentryDebug captures err at Sentry LevelDebug. Not the same as SentryOptions.Debug (SDK diagnostics).
func SendSentryError ¶
func SendSentryErrorWithContext ¶
SendSentryErrorWithContext sends an error to Sentry with request context. ctx may carry a Sentry Hub (set by middleware); falls back to global client.
func SendSentryEvent ¶
func SendSentryMessage ¶
func SendSentryWarning ¶
func SendToSentryDebug ¶
SendToSentryDebug captures an error as a Sentry event at LevelDebug (a product event). This is unrelated to SentryOptions.Debug, which only enables SDK transport/client log output.
func SendToSentryError ¶
func SendToSentryEvent ¶
func SendToSentryMessage ¶
func SendToSentryWarning ¶
func SentryEnabled ¶
func SentryEnabled() bool
SentryEnabled returns true if a Sentry client has been initialized. Use this to guard expensive error construction before calling SendSentryError.
Types ¶
type SentryData ¶
type SentryData struct {
Service string `json:"service"`
Module string `json:"module"`
Function string `json:"function"`
}
func GetSentryData ¶
func GetSentryData() *SentryData
type SentryOptions ¶
type SentryOptions struct {
Dsn string
Environment string
Release string
// Debug turns on verbose diagnostic logging inside sentry-go (transport, event submission).
// It does not control SendSentryDebug / SendToSentryDebug, which emit debug-level Sentry events.
// When true, SDK output is written to DebugWriter (default sentryDiagnosticWriter → info logs).
// Prefer false in production; use true only while troubleshooting client connectivity or delivery.
Debug bool
Options *sentry.ClientOptions
Data *SentryData
}
SentryOptions configures the global Sentry client for InitSentry / InitSentryOptions. Consumer services usually map their own environment variables into this struct; paycloudhelper does not read os.Getenv for Dsn, Debug, etc. (except broader app identity via phhelper).