Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version string

Version is the build version, set by libhoney

Functions

This section is empty.

Types

type DiscardSender

type DiscardSender struct {
	WriterSender
}

DiscardSender implements the Sender interface and drops all events.

func (*DiscardSender) Add

func (d *DiscardSender) Add(ev *Event)

type Event

type Event struct {
	// APIKey, if set, overrides whatever is found in Config
	APIKey string
	// Dataset, if set, overrides whatever is found in Config
	Dataset string
	// SampleRate, if set, overrides whatever is found in Config
	SampleRate uint
	// APIHost, if set, overrides whatever is found in Config
	APIHost string
	// Timestamp, if set, specifies the time for this event. If unset, defaults
	// to Now()
	Timestamp time.Time
	// Metadata is a field for you to add in data that will be handed back to you
	// on the Response object read off the Responses channel. It is not sent to
	// Honeycomb with the event.
	Metadata interface{}

	// Data contains the content of the event (all the fields and their values)
	Data map[string]interface{}
}

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() ([]byte, error)

Marshaling an Event for batching up to the Honeycomb servers. Omits fields that aren't specific to this particular event, and allows for behavior like omitempty'ing a zero'ed out time.Time.

func (*Event) MarshalMsgpack

func (e *Event) MarshalMsgpack() (byts []byte, err error)

type Honeycomb

type Honeycomb struct {
	// how many events to collect into a batch before sending
	MaxBatchSize uint

	// how often to send off batches
	BatchTimeout time.Duration

	// how many batches can be inflight simultaneously
	MaxConcurrentBatches uint

	// how many events to allow to pile up
	// if not specified, then the work channel becomes blocking
	// and attempting to add an event to the queue can fail
	PendingWorkCapacity uint

	// whether to block or drop events when the queue fills
	BlockOnSend bool

	// whether to block or drop responses when the queue fills
	BlockOnResponse bool

	UserAgentAddition string

	// toggles compression when sending batches of events
	DisableCompression bool

	// Deprecated, synonymous with DisableCompression
	DisableGzipCompression bool

	// set true to send events with msgpack encoding
	EnableMsgpackEncoding bool

	Transport http.RoundTripper

	Logger  Logger
	Metrics Metrics
	// contains filtered or unexported fields
}

func (*Honeycomb) Add

func (h *Honeycomb) Add(ev *Event)

Add enqueues ev to be sent. If a Flush is in-progress, this will block until it completes. Similarly, if BlockOnSend is set and the pending work is more than the PendingWorkCapacity, this will block a Flush until more pending work can be enqueued.

func (*Honeycomb) Flush

func (h *Honeycomb) Flush() (err error)

func (*Honeycomb) SendResponse

func (h *Honeycomb) SendResponse(r Response) bool

func (*Honeycomb) Start

func (h *Honeycomb) Start() error

func (*Honeycomb) Stop

func (h *Honeycomb) Stop() error

func (*Honeycomb) TxResponses

func (h *Honeycomb) TxResponses() chan Response

type Logger

type Logger interface {
	// Printf accepts the same msg, args style as fmt.Printf().
	Printf(msg string, args ...interface{})
}

type Metrics

type Metrics interface {
	Gauge(string, interface{})
	Increment(string)
	Count(string, interface{})
}

Metrics is an interface that can be fulfilled by something like statsd

type MockSender

type MockSender struct {
	Started      int
	Stopped      int
	Flushed      int
	EventsCalled int

	BlockOnResponses bool
	sync.Mutex
	// contains filtered or unexported fields
}

MockSender implements the Sender interface by retaining a slice of added events, for use in unit tests.

func (*MockSender) Add

func (m *MockSender) Add(ev *Event)

func (*MockSender) Events

func (m *MockSender) Events() []*Event

func (*MockSender) Flush

func (m *MockSender) Flush() error

func (*MockSender) SendResponse

func (m *MockSender) SendResponse(r Response) bool

func (*MockSender) Start

func (m *MockSender) Start() error

func (*MockSender) Stop

func (m *MockSender) Stop() error

func (*MockSender) TxResponses

func (m *MockSender) TxResponses() chan Response

type Response

type Response struct {

	// Err contains any error returned by the httpClient on sending or an error
	// indicating queue overflow
	Err error

	// StatusCode contains the HTTP Status Code returned by the Honeycomb API
	// server
	StatusCode int

	// Body is the body of the HTTP response from the Honeycomb API server.
	Body []byte

	// Duration is a measurement of how long the HTTP request to send an event
	// took to process. The actual time it takes libhoney to send an event may
	// be longer due to any time the event spends waiting in the queue before
	// being sent.
	Duration time.Duration

	// Metadata is whatever content you put in the Metadata field of the event for
	// which this is the response. It is passed through unmodified.
	Metadata interface{}
}

Response is a record of an event sent. It includes information about sending the event - how long it took, whether it succeeded, and so on. It also has a metadata field that is just a pass through - populate an Event's Metadata field and what you put there will be on the Response that corresponds to that Event. This allows you to track specific events.

func (*Response) MarshalMsgpack

func (r *Response) MarshalMsgpack() ([]byte, error)

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(b []byte) error

func (*Response) UnmarshalMsgpack

func (r *Response) UnmarshalMsgpack(b []byte) error

type Sender

type Sender interface {

	// Add queues up an event to be sent
	Add(ev *Event)

	// Start initializes any background processes necessary to send events
	Start() error

	// Stop flushes any pending queues and blocks until everything in flight has
	// been sent. Once called, you cannot call Add unless Start has subsequently
	// been called.
	Stop() error

	// Flush flushes any pending queues and blocks until everything in flight has
	// been sent.
	Flush() error

	// Responses returns a channel that will contain a single Response for each
	// Event added. Note that they may not be in the same order as they came in
	TxResponses() chan Response

	// SendResponse adds a Response to the Responses queue. It should be added
	// for events handed to libhoney that are dropped before they even make it
	// to the Transmission Sender (for example because of sampling) to maintain
	// libhoney's guarantee that each event given to it will generate one event
	// in the Responses channel.
	SendResponse(Response) bool
}

Sender is responsible for handling events after Send() is called. Implementations of Add() must be safe for concurrent calls.

type WriterSender

type WriterSender struct {
	W io.Writer

	BlockOnResponses  bool
	ResponseQueueSize uint

	sync.Mutex
	// contains filtered or unexported fields
}

WriterSender implements the Sender interface by marshalling events to JSON and writing to STDOUT, or to the writer W if one is specified.

func (*WriterSender) Add

func (w *WriterSender) Add(ev *Event)

func (*WriterSender) Flush

func (w *WriterSender) Flush() error

func (*WriterSender) SendResponse

func (w *WriterSender) SendResponse(r Response) bool

func (*WriterSender) Start

func (w *WriterSender) Start() error

func (*WriterSender) Stop

func (w *WriterSender) Stop() error

func (*WriterSender) TxResponses

func (w *WriterSender) TxResponses() chan Response