github.com/blend/go-sdk@v1.20220411.3/stats/event_collector.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stats
     9  
    10  import (
    11  	"time"
    12  
    13  	"github.com/blend/go-sdk/ex"
    14  )
    15  
    16  // EventCollector is a collector for events.
    17  type EventCollector interface {
    18  	Taggable
    19  	SendEvent(Event) error
    20  	CreateEvent(title, text string, tags ...string) Event
    21  }
    22  
    23  const (
    24  	// EventAlertTypeInfo is the "info" AlertType for events
    25  	EventAlertTypeInfo = "info"
    26  	// EventAlertTypeError is the "error" AlertType for events
    27  	EventAlertTypeError = "error"
    28  	// EventAlertTypeWarning is the "warning" AlertType for events
    29  	EventAlertTypeWarning = "warning"
    30  	// EventAlertTypeSuccess is the "success" AlertType for events
    31  	EventAlertTypeSuccess = "success"
    32  )
    33  
    34  const (
    35  	// EventPriorityNormal is the "normal" Priority for events.
    36  	EventPriorityNormal = "normal"
    37  	// EventPriorityLow is the "low" Priority for events.
    38  	EventPriorityLow = "low"
    39  )
    40  
    41  // Event is an event to be collected.
    42  type Event struct {
    43  	// Title of the event.  Required.
    44  	Title string
    45  	// Text is the description of the event.  Required.
    46  	Text string
    47  	// Timestamp is a timestamp for the event.  If not provided, the dogstatsd
    48  	// server will set this to the current time.
    49  	Timestamp time.Time
    50  	// Hostname for the event.
    51  	Hostname string
    52  	// AggregationKey groups this event with others of the same key.
    53  	AggregationKey string
    54  	// Priority of the event.  Can be statsd.Low or statsd.Normal.
    55  	Priority string
    56  	// SourceTypeName is a source type for the event.
    57  	SourceTypeName string
    58  	// AlertType can be statsd.Info, statsd.Error, statsd.Warning, or statsd.Success.
    59  	// If absent, the default value applied by the dogstatsd server is Info.
    60  	AlertType string
    61  	// Tags for the event.
    62  	Tags []string
    63  }
    64  
    65  // Check verifies that an event is valid.
    66  func (e Event) Check() error {
    67  	if len(e.Title) == 0 {
    68  		return ex.Class("event title is required")
    69  	}
    70  	if len(e.Text) == 0 {
    71  		return ex.Class("event text is required")
    72  	}
    73  	return nil
    74  }