Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe the use cases for events in greater detail #3969

Merged
merged 21 commits into from
Jun 3, 2024
Merged
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 54 additions & 22 deletions specification/logs/event-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,76 @@

<!-- toc -->

- [Data model](#data-model)
- [EventLoggerProvider](#eventloggerprovider)
* [EventLoggerProvider operations](#eventloggerprovider-operations)
+ [Get an EventLogger](#get-an-eventlogger)
- [EventLogger](#eventlogger)
* [EventLogger Operations](#eventlogger-operations)
+ [Emit Event](#emit-event)
- [Optional and required parameters](#optional-and-required-parameters)
- [References](#references)
- [Events API](#events-api)
- [Event Data model](#event-data-model)
- [Event API use cases](#event-api-use-cases)
- [EventLoggerProvider](#eventloggerprovider)
- [EventLoggerProvider operations](#eventloggerprovider-operations)
- [Get an EventLogger](#get-an-eventlogger)
- [EventLogger](#eventlogger)
- [EventLogger Operations](#eventlogger-operations)
- [Emit Event](#emit-event)
- [Optional and required parameters](#optional-and-required-parameters)
- [References](#references)

<!-- tocstop -->

</details>

The Event API consists of these main components:

* [EventLoggerProvider](#eventloggerprovider) is the entry point of the API. It provides access to `EventLogger`s.
* [EventLoggerProvider](#eventloggerprovider) is the entry point of the API. It
provides access to `EventLogger`s.
* [EventLogger](#eventlogger) is the component responsible for emitting events.

## Data model
## Event Data model

Wikipedia’s [definition of log file](https://en.wikipedia.org/wiki/Log_file):

>In computing, a log file is a file that records either events that occur in an
>operating system or other software runs.

From OpenTelemetry's perspective LogRecords and Events are both represented
using the same [data model](./data-model.md).

However, OpenTelemetry does recognize a subtle semantic difference between
LogRecords and Events: Events are LogRecords which have a `name` which uniquely
defines a particular class or type of event. All events with the same `name`
have `Body` that conform to the same schema, which assists in analysis in
observability platforms. Events are described in more detail in
the [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/events.md).

Unlike the [Logs Bridge API](./bridge-api.md), application developers and
instrumentation authors are encouraged to call this API directly.
using the same [data model](./data-model.md). An Event is a specialized type
of LogRecord, not a separate concept.

Events are OpenTelemetry's standardized semantic formatting for LogRecords.
Beyond the structure provided by the LogRecord data model, it is helpful for
logs to have a common format within that structure. When OpenTelemetry
instrumentation emits logs, those logs SHOULD be formatted as Events. All
semantic conventions defined for logs MUST be formatted as Events.

The Event format is as follows. All Events have a `name` attribute, and all
Events with the same `name` MUST conform to the same schema for both their
`Attributes` and their `Body`.

## Event API use cases

The Events API was designed to allow shared libraries to emit high quality
logs without needing to depend on a third party logger. Unlike the
[Logs Bridge API](./bridge-api.md), instrumentation authors and application
developers are encouraged to call this API directly. It is appropriate to
use the Event API when these properties fit your requirements:

* Logging from a shared library that must run in many applications.
* A semantic convention needs to be defined. We do not define semantic
conventions for LogRecords that are not Events.
* Analysis by an observability platform is the intended use case. For
example: statistics, indexing, machine learning, session replay.
* Normalizing logging and having a consistent schema across a large
application is helpful.

If any of these properties fit your requirements, we recommend using the Event API.
tedsuo marked this conversation as resolved.
Show resolved Hide resolved
Events are described in more detail in the [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/events.md).

Please note that the OpenTelemetry Log SDK currently lacks a number of advanced
features present in popular log frameworks. For example: pattern logging, file
tedsuo marked this conversation as resolved.
Show resolved Hide resolved
rotation, network appenders, etc. These features cannot be used with the
OpenTelemetry Event SDK at this time.

If a logging library is capable of creating logs which correctly map
to the Event data model, logging in this manner is also an acceptable way to
create Events.

## EventLoggerProvider

Expand Down
Loading