eventexporter

package module
v0.0.0-...-8c411a9 Latest Latest
Warning

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

Go to latest
Published: May 22, 2017 License: MIT Imports: 6 Imported by: 3

README

eventexporter Build Status

eventexporter is a library to export events to 3rd party services.

Usage

key := "segment api token"
size := "size of events to accumulate before flushing"

event := &eventexporter.Event{
  Name: "test event",
  User: &eventexporter.User{
    Username:"indianajones", Email: "indiana@gmail.com"
  },
  Body: &eventexporter.Body{Content: "Hello world"},
  Properties: map[string]interface{}{"occupation" : "explorer" },
}

client := eventexporter.NewSegementIOExporter(key, size)
client.Send(event)

FakeExporter is an implementation of Exporter to be used in tests.

import (
  "github.com/koding/eventexporter"
)

event := &eventexporter.Event{Name: "test event"}

client := eventexporter.NewFakeExporter()
client.Send(event)

fmt.Println(client.Events)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SegmentIO
	ErrSegmentIOUsernameEmpty = errors.New("username is empty")
	ErrSegmentIOEmailEmpty    = errors.New("email is empty")
	ErrSegmentIOEventEmpty    = errors.New("event is empty")
	ErrSendgridBodyEmpty      = errors.New("email body is empty")

	//Druid
	ErrDruidAddressNotSet = errors.New("DruidExporter address is not set")
)
View Source
var DateLayout = "Jan 2, 2006"

Functions

This section is empty.

Types

type Body

type Body struct {
	Type    BodyType // text or html
	Content string
}

Body is used to send text or html of event directly to 3rd party. Ideally none of html should exist in codebase so it's easy to change, however legacy html code still exists.

type BodyType

type BodyType int
const (
	TextBodyType BodyType = iota
	HtmlBodyType
)

type DatadogExporter

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

DatadogExporter exports events to datadog

func NewDatadogExporter

func NewDatadogExporter(d *kodingmetrics.DogStatsD) *DatadogExporter

NewDatadogExporter initializes DatadogExporter struct and NewDatadogExporter implements Exporter interface with Send and Close functions

func (*DatadogExporter) Close

func (d *DatadogExporter) Close() error

Close closes the publisher. DogStatsD is treated as external resource so does nothing.

func (DatadogExporter) Name

func (DatadogExporter) Name() string

Name returns the name of the exporter.

func (*DatadogExporter) Send

func (d *DatadogExporter) Send(m *Event) error

Send publishes Events to Datad

type Event

type Event struct {
	Name       string                 // name of event
	User       *User                  // user who did event
	Body       *Body                  // body of event; text or html
	Properties map[string]interface{} // any additional properties
	Context    map[string]interface{} // any additional context

	Count    int64         // count of the event
	Duration time.Duration // duration of the event
	// Publish this events to only whitelisted upstreams
	WhitelistedUpstreams []string
}

Event represent an action in time that is done by an user, has body and optionally some properties.

type Exporter

type Exporter interface {
	Send(*Event) error
	Name() string
	Close() error
}

Exporter is the interface to export events to a 3rd party service. Currently third party services: SegementIO and Sendgrid are implemented.

type FakeExporter

type FakeExporter struct {
	Events []*Event
}

func NewFakeExporter

func NewFakeExporter() *FakeExporter

func (*FakeExporter) Close

func (l *FakeExporter) Close() error

func (FakeExporter) Name

func (FakeExporter) Name() string

Name returns the name of the exporter.

func (*FakeExporter) Send

func (l *FakeExporter) Send(event *Event) error

type MultiExporter

type MultiExporter []Exporter

func NewMultiExporter

func NewMultiExporter(e ...Exporter) MultiExporter

NewMultiExporter inits the exporter services like; segment, datadog etc.. and implements Exporter interface with Send and Close functions

func (MultiExporter) Close

func (m MultiExporter) Close() error

Close closes the upstreams.

func (MultiExporter) Name

func (MultiExporter) Name() string

Name returns the name of the exporter.

func (MultiExporter) Send

func (m MultiExporter) Send(event *Event) error

Send publishes the events to multiple upstreams, returns error on first occurence

type SegmentIOExporter

type SegmentIOExporter struct {
	Client *analytics.Client
}

func NewSegmentIOExporter

func NewSegmentIOExporter(key string, size int) *SegmentIOExporter

func (*SegmentIOExporter) Close

func (s *SegmentIOExporter) Close() error

func (SegmentIOExporter) Name

func (SegmentIOExporter) Name() string

Name returns the name of the exporter.

func (*SegmentIOExporter) Send

func (s *SegmentIOExporter) Send(event *Event) error

type User

type User struct {
	Email    string
	Username string
}

Jump to

Keyboard shortcuts

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