Documentation ¶
Overview ¶
Package instrument provides the tool to emit the events to the instrumentation destination. Currently it supports Segment or logger as a destination.
When enabling, make sure to follow the guideline specified in https://github.com/netlify/segment-events
In the config file, you can define the API key, as well as if it's enabled (use Segment) or not (use logger).
INSTRUMENT_ENABLED=true INSTRUMENT_KEY=segment_api_key
To use, you can import this package:
import "github.com/netlify/netlify-commons/instrument"
You will likely need to import the Segment's analytics package as well, to create new traits and properties.
import "gopkg.in/segmentio/analytics-go.v3"
Then call the functions:
instrument.Track("userid", "service:my_event", analytics.NewProperties().Set("color", "green"))
For testing, you can create your own mock instrument and use it:
func TestSomething (t *testing.T) { log := testutil.TL(t) old := instrument.GetGlobalClient() t.Cleanup(func(){ instrument.SetGlobalClient(old) }) instrument.SetGlobalClient(instrument.MockClient{Logger: log}) }
Index ¶
- func Alias(previousID string, userID string) error
- func Group(userID string, groupID string, traits analytics.Traits) error
- func Identify(userID string, traits analytics.Traits) error
- func Init(conf Config, log logrus.FieldLogger) error
- func Page(userID string, name string, properties analytics.Properties) error
- func SetGlobalClient(client Client)
- func Track(userID string, event string, properties analytics.Properties) error
- type Client
- type Config
- type MockClient
- func (c MockClient) Alias(previousID string, userID string) error
- func (c MockClient) Group(userID string, groupID string, traits analytics.Traits) error
- func (c MockClient) Identify(userID string, traits analytics.Traits) error
- func (c MockClient) Page(userID string, name string, properties analytics.Properties) error
- func (c MockClient) Track(userID string, event string, properties analytics.Properties) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(conf Config, log logrus.FieldLogger) error
Init will initialize global client with a segment client
func SetGlobalClient ¶
func SetGlobalClient(client Client)
Types ¶
type Client ¶
type Client interface { Identify(userID string, traits analytics.Traits) error Track(userID string, event string, properties analytics.Properties) error Page(userID string, name string, properties analytics.Properties) error Group(userID string, groupID string, traits analytics.Traits) error Alias(previousID string, userID string) error }
func GetGlobalClient ¶
func GetGlobalClient() Client
type MockClient ¶
type MockClient struct {
Logger logrus.FieldLogger
}
func (MockClient) Group ¶
func (c MockClient) Group(userID string, groupID string, traits analytics.Traits) error
func (MockClient) Identify ¶
func (c MockClient) Identify(userID string, traits analytics.Traits) error