events

package
v2.48.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package events provides a programmatic API for creating custom events in New Relic.

Authentication

You will need a valid Insights insert key to communicate with the backend New Relic API that provides this functionality. See the API key documentation below for more information on how to locate this key:

https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

Index

Constants

View Source
const (
	DefaultBatchWorkers = 1
	DefaultBatchSize    = 900
	DefaultBatchTimeout = 60 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchConfigOption

type BatchConfigOption func(*Events) error

func BatchConfigQueueSize

func BatchConfigQueueSize(size int) BatchConfigOption

BatchConfigQueueSize is how many events to queue before sending to New Relic. If this limit is hit before the Timeout, the queue is flushed.

func BatchConfigTimeout

func BatchConfigTimeout(seconds int) BatchConfigOption

BatchConfigTimeout is the maximum amount of time to queue events before sending to New Relic. If this is reached before the Size limit, the queue is flushed.

func BatchConfigWorkers

func BatchConfigWorkers(count int) BatchConfigOption

BatchConfigWorkers sets how many background workers will process events as they are queued

type Events

type Events struct {
	// contains filtered or unexported fields
}

Events is used to send custom events to NRDB.

func New

func New(cfg config.Config) Events

New is used to create a new Events client instance.

func NewEventsService added in v2.22.2

func NewEventsService(opts ...config.ConfigOption) (*Events, error)

Provides the EventsAPI operations for *Events

func (*Events) BatchMode

func (e *Events) BatchMode(ctx context.Context, accountID int, opts ...BatchConfigOption) (err error)

BatchMode enables the Events client to accept, queue, and post Events on behalf of the consuming application

func (*Events) CreateEvent

func (e *Events) CreateEvent(accountID int, event interface{}) error

CreateEvent reports a custom event to New Relic.

func (*Events) CreateEventWithContext

func (e *Events) CreateEventWithContext(ctx context.Context, accountID int, event interface{}) error

CreateEventWithContext reports a custom event to New Relic.

func (*Events) EnqueueEvent

func (e *Events) EnqueueEvent(ctx context.Context, event interface{}) (err error)

EnqueueEventContext handles the queueing. Only works in batch mode. If you wish to be able to avoid blocking forever until the event can be queued, provide a ctx with a deadline or timeout as this function will bail when ctx.Done() is closed and return and error.

func (*Events) Flush

func (e *Events) Flush() error

Flush gives the user a way to manually flush the queue in the foreground. This is also used by watchdog when the timer expires.

type EventsAPI added in v2.22.2

type EventsAPI interface {
	CreateEvent(accountID int, event interface{}) error
	CreateEventWithContext(ctx context.Context, accountID int, event interface{}) error
}

EventsAPI provides an interface to enable mocking the service implementation. You should use this interface to invoke methods and substitute with a mock having a compatible implementation for unit testing your usages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL