Documentation
¶
Index ¶
- Variables
- func JSONHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handlerdeprecated
- func New(app *newrelic.Application, handler slog.Handler) *slog.Logger
- func TextHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handlerdeprecated
- func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger
- func WithTransaction(txn *newrelic.Transaction, logger *slog.Logger) *slog.Logger
- func WithTransactionFromContext(handler slog.Handler) slog.Handlerdeprecated
- func WrapHandler(app *newrelic.Application, handler slog.Handler) slog.Handler
- type NRHandler
- func (h *NRHandler) Clone() *NRHandler
- func (h *NRHandler) Enabled(ctx context.Context, lvl slog.Level) bool
- func (h *NRHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *NRHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *NRHandler) WithGroup(name string) slog.Handler
- func (h *NRHandler) WithTransaction(txn *newrelic.Transaction) *NRHandler
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyWrapped = errors.New("handler is already wrapped with a New Relic handler")
var ErrNilApp = errors.New("New Relic application cannot be nil")
var ErrNilHandler = errors.New("slog handler cannot be nil")
Functions ¶
func JSONHandler
deprecated
func JSONHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handler
JSONHandler creates a wrapped Slog JSONHandler, enabling it to both automatically capture logs and to enrich logs locally depending on your logs in context configuration in your New Relic application.
Deprecated: Use WrapHandler() instead.
func New ¶
New Returns a new slog.Logger object wrapped with a New Relic handler that controls logs in context features.
func TextHandler
deprecated
func TextHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handler
TextHandler creates a wrapped Slog TextHandler, enabling it to both automatically capture logs and to enrich logs locally depending on your logs in context configuration in your New Relic application.
Deprecated: Use WrapHandler() instead.
func WithContext ¶
WithTransaction creates a new Slog Logger object to be used for logging within a given transaction it its found in a context. Creating a transaction logger can have a performance benefit when transactions are long running, and have a high log volume in comparison to reading transactions from context on every log message.
Note: transaction contexts can also be passed to the logger without creating a new logger using logger.InfoContext() or similar commands.
func WithTransaction ¶
WithTransaction creates a new Slog Logger object to be used for logging within a given transaction. Creating a transaction logger can have a performance benefit when transactions are long running, and have a high log volume in comparison to reading transactions from context on every log message.
Note: transaction contexts can also be passed to the logger without creating a new logger using logger.InfoContext() or similar commands.
func WithTransactionFromContext
deprecated
func WrapHandler ¶
WrapHandler returns a new handler that is wrapped with New Relic tools to capture log data based on your application's logs in context settings.
Note: This function will silently error, and always return a valid handler to avoid service disruptions. If you would prefer to handle errors when wrapping your handler, use the Wrap() function instead.
Types ¶
type NRHandler ¶
type NRHandler struct {
// contains filtered or unexported fields
}
NRHandler is an Slog handler that includes logic to implement New Relic Logs in Context. Please always create a new handler using the Wrap() or WrapHandler() functions to ensure proper initialization.
Note: shallow coppies of this handler may not duplicate underlying datastructures, and may cause logical errors. Please use the Clone() method to create deep coppies, or use the WithTransaction, WithAttrs, or WithGroup methods to create new handlers with additional data.
func Wrap ¶
WrapHandler returns a new handler that is wrapped with New Relic tools to capture log data based on your application's logs in context settings.
func (*NRHandler) Clone ¶
Clone creates a deep copy of the original handler, including a copy of all cached data and the underlying handler.
Note: application, transaction, and handler pointers will be coppied, but the underlying data will not be duplicated.
func (*NRHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*NRHandler) Handle ¶
Handle handles the Record. It will only be called when Enabled returns true.
func (*NRHandler) WithAttrs ¶
WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.
This wraps the WithAttrs of the underlying handler, and will not modify the attributes slice in any way.
func (*NRHandler) WithGroup ¶
WithGroup returns a new Handler with the given group appended to the receiver's existing groups. The keys of all subsequent attributes, whether added by With or in a Record, should be qualified by the sequence of group names. If the name is empty, WithGroup returns the receiver.
func (*NRHandler) WithTransaction ¶
func (h *NRHandler) WithTransaction(txn *newrelic.Transaction) *NRHandler
WithTransaction returns a new handler that is configured to capture log data and attribute it to a specific transaction.