Class: EventUtils
Defined in: core/src/TelemetryUtils.ts:103
Provides a common set of static functions for recording and working with telemetry Event instances.
The init function must be called before any other function can be called.
The record function is used to send an event to a configured telemetry_services service for permanent storage.
The on function allows code within the same application or service to listen for outgoing events that have been
sent via the record function.
The utility uses an application specific JWT access token for sending telemetry events. The purpose of using an application specific JWT token versus user token is to identify a potentially compromised application server. This also allows the server to send telemetry events on behalf of the user that the user may not otherwise have permission to send.
Note: This class is considered a runtime singleton and intentionally uses static state. Do not initialize this class more than once in your application.
Constructors
Constructor
new EventUtils():
EventUtils
Returns
EventUtils
Methods
init()
staticinit(config,logger,jwtToken):Promise<void>
Defined in: core/src/TelemetryUtils.ts:118
Initializes EventUtils with the provided defaults.
Parameters
config
any
The application configuration to use.
logger
any
The logging utility to use.
jwtToken
string
The application's JWT token to send telemetry events on behalf of.
Returns
Promise<void>
off()
staticoff(type,callback):void
Defined in: core/src/TelemetryUtils.ts:219
Unregisters a callback previously registered via on() for the given event type. Since EventUtils is
a long-lived process-wide singleton, any listener registered dynamically (rather than once at startup) must
eventually be removed via this method or its closure - and anything it captures - is retained for the life
of the process.
Parameters
type
string
The type of event the callback was registered for.
callback
Function
The exact function reference passed to on().
Returns
void
on()
staticon(type,callback):void
Defined in: core/src/TelemetryUtils.ts:191
Registers a callback function to receive notifications of recorded events of the given type. Note that only
events originating from the same application or service will be notified.
Parameters
type
string
The type of event to be notified of.
callback
Function
The function to call when an event is recorded.
Returns
void
record()
staticrecord(evt,type?):Promise<void>
Defined in: core/src/TelemetryUtils.ts:137
Sends the given event to the telemetry service for permanent recording.
Parameters
evt
any
The event to send and record.
type?
string
The type of event to record. Overrides any type value set in evt.
Returns
Promise<void>