1 package ldevents 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/launchdarkly/go-sdk-common/v3/ldtime" 8 ) 9 10 // EventProcessor defines the interface for dispatching analytics events. 11 type EventProcessor interface { 12 // RecordEvaluation records evaluation information asynchronously. Depending on the feature 13 // flag properties and event properties, this may be transmitted to the events service as an 14 // individual event, or may only be added into summary data. 15 RecordEvaluation(EvaluationData) 16 17 // RecordIdentifyEvent records an identify event asynchronously. 18 RecordIdentifyEvent(IdentifyEventData) 19 20 // RecordCustomEvent records a custom event asynchronously. 21 RecordCustomEvent(CustomEventData) 22 23 // RecordRawEvent adds an event to the output buffer that is not parsed or transformed in any way. 24 // This is used by the Relay Proxy when forwarding events. 25 RecordRawEvent(data json.RawMessage) 26 27 // Flush specifies that any buffered events should be sent as soon as possible, rather than waiting 28 // for the next flush interval. This method is asynchronous, so events still may not be sent 29 // until a later time. 30 Flush() 31 32 // FlushBlocking attempts to flush any buffered events, blocking until either they have been 33 // successfully delivered or delivery has failed. If there were no buffered events, it returns true 34 // immediately. The timeout parameter, if non-zero, specifies the maximum amount of time to wait 35 // before the method will return; a timeout does not stop the event processor from continuing to 36 // try to deliver the events in the background, if applicable. The method returns true on completion 37 // or false if timed out. 38 FlushBlocking(timeout time.Duration) bool 39 40 // Close shuts down all event processor activity, after first ensuring that all events have been 41 // delivered. Subsequent calls to SendEvent() or Flush() will be ignored. 42 Close() error 43 } 44 45 // EventSender defines the interface for delivering already-formatted analytics event data to the events service. 46 type EventSender interface { 47 // SendEventData attempts to deliver an event data payload. 48 SendEventData(kind EventDataKind, data []byte, eventCount int) EventSenderResult 49 } 50 51 // EventDataKind is a parameter passed to EventSender to indicate the type of event data payload. 52 type EventDataKind string 53 54 const ( 55 // AnalyticsEventDataKind denotes a payload of analytics event data. 56 AnalyticsEventDataKind EventDataKind = "analytics" 57 // DiagnosticEventDataKind denotes a payload of diagnostic event data. 58 DiagnosticEventDataKind EventDataKind = "diagnostic" 59 ) 60 61 // EventSenderResult is the return type for EventSender.SendEventData. 62 type EventSenderResult struct { 63 // Success is true if the event payload was delivered. 64 Success bool 65 // MustShutDown is true if the server returned an error indicating that no further event data should be sent. 66 // This normally means that the SDK key is invalid. 67 MustShutDown bool 68 // TimeFromServer is the last known date/time reported by the server, if available, otherwise zero. 69 TimeFromServer ldtime.UnixMillisecondTime 70 } 71