@opentelemetry/sdk-events
v0.55.0
Published
OpenTelemetry events SDK
Downloads
2,875
Readme
OpenTelemetry Events SDK
Note: This is an experimental package under active development. New releases may include breaking changes.
This package provides an experimental Events SDK implementation. The Events SDK is implemented on top of the Logs SDK.
Installation
npm install --save @opentelemetry/api-logs
npm install --save @opentelemetry/api-events
npm install --save @opentelemetry/sdk-events
Usage
Here is an example of configuring and using the Events SDK:
const { logs } = require('@opentelemetry/api-logs');
const { events } = require('@opentelemetry/api-events');
const { EventLoggerProvider } = require('@opentelemetry/sdk-events');
const {
LoggerProvider,
SimpleLogRecordProcessor,
ConsoleLogRecordExporter,
} = require('@opentelemetry/sdk-logs');
// The Events SDK has a dependency on the Logs SDK.
// Any processing of events (e.g. export) is done through the Logs SDK.
const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
);
// Register a global EventLoggerProvider.
// This would be used by instrumentations, similar to how the global TracerProvider,
// LoggerProvider and MeterProvider work.
const eventLoggerProvider = new EventLoggerProvider(loggerProvider);
events.setGlobalEventLoggerProvider(eventLoggerProvider);
// Get an EventLogger from the global EventLoggerProvider
const eventLogger = events.getEventLogger('default');
// Emit an event
eventLogger.emit({
name: 'my-domain.my-event',
data: {
field1: 'abc',
field2: 123
}
});
// Shutdown is done directly on the LoggerProvider
loggerProvider.shutdown();
Example
See examples/events
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us in GitHub Discussions
License
Apache 2.0 - See LICENSE for more information.