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

Events and logs api #2676

Merged
merged 35 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44819cc
Events and Logs API spec
scheler Jun 23, 2022
27f96ea
API spec for events and logs
scheler Jul 13, 2022
e97b6ff
Semantic conventions for events
scheler Jul 13, 2022
00cf1f2
Deleting file
scheler Jul 13, 2022
90fd819
Adding experimental status
scheler Jul 13, 2022
89942b1
Adding event semantinc convention yaml
scheler Jul 19, 2022
6cc131d
Updating events-and-logs-api.png
scheler Jul 19, 2022
a54d1f9
Merge branch 'main' into events-and-logs-api
scheler Jul 19, 2022
f8e2424
Update specification/logs/api.md
scheler Jul 19, 2022
4df048e
Update specification/logs/api.md
scheler Jul 19, 2022
47609ef
Update specification/logs/semantic_conventions/events.md
scheler Jul 29, 2022
ad9a705
Update specification/logs/api.md
scheler Jul 29, 2022
73c5a06
Apply suggestions from code review
scheler Jul 29, 2022
d5b4697
Apply review suggestions
scheler Jul 29, 2022
4d688db
Add clarification on event name attribute handling
scheler Jul 29, 2022
ab7dab8
Replace with mermaid diagram
scheler Jul 29, 2022
b9f3313
Remove image, it's replacced with mermaid diagram
scheler Jul 29, 2022
cc74ab6
Remove blank line
scheler Jul 29, 2022
3895624
Using enum type for event.domain
scheler Aug 2, 2022
16de49c
Requiring event.domain attribute
scheler Aug 3, 2022
5d060e5
Fix typo
scheler Aug 4, 2022
97b7b69
Update events.md after yaml change.
scheler Aug 4, 2022
8acc5d0
Merge branch 'open-telemetry:main' into events-and-logs-api
scheler Aug 20, 2022
4c02cb1
Apply review suggestions
scheler Aug 20, 2022
0422aef
Add a reference to LogRecord data model
scheler Aug 22, 2022
14720a8
Updating TOC
scheler Aug 24, 2022
5f87b5e
Add changelog entry
scheler Aug 24, 2022
554fe00
Add a required blank line after a section
scheler Aug 24, 2022
8da45f0
Fix indentatation in the changelog entry
scheler Aug 24, 2022
8cd9fb8
Apply suggestions on formatting
scheler Aug 25, 2022
e711284
Merge branch 'main' into events-and-logs-api
scheler Aug 29, 2022
46e3570
Merge branch 'events-and-logs-api' of github.com:scheler/opentelemetr…
scheler Aug 29, 2022
7fb6616
Merge branch 'open-telemetry:main' into events-and-logs-api
scheler Aug 30, 2022
cc59dad
Fix typo with events
scheler Aug 30, 2022
fc4d7a3
Merge branch 'main' into events-and-logs-api
scheler Aug 30, 2022
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
17 changes: 17 additions & 0 deletions semantic_conventions/logs/events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
groups:
scheler marked this conversation as resolved.
Show resolved Hide resolved
- id: event
prefix: event
brief: >
This document defines attributes for Events represented using Log Records.
attributes:
- id: name
type: string
requirement_level: required
brief: >
The name identifies the event.
examples: ['click', 'exception']
- id: domain
type: string
brief: >
The domain identifies the context in which an event happened. An event name is unique only within a domain.
examples: ['browser', 'mobile', 'kubernetes']
65 changes: 65 additions & 0 deletions specification/logs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Events and Logs API Interface
scheler marked this conversation as resolved.
Show resolved Hide resolved

**Status**: [Experimental](../document-status.md)

scheler marked this conversation as resolved.
Show resolved Hide resolved
The Events and Logs API consist of these main classes:

* LoggerProvider is the entry point of the API. It provides access to Loggers.
* Logger is the class responsible for creating events and logs using Log records.

LoggerProvider/Logger are analogous to TracerProvider/Tracer.

![Events and Logs API classes](img/events-and-logs-api.png)
scheler marked this conversation as resolved.
Show resolved Hide resolved

### LoggerProvider
scheler marked this conversation as resolved.
Show resolved Hide resolved

Logger can be accessed with an LoggerProvider.
scheler marked this conversation as resolved.
Show resolved Hide resolved

In implementations of the API, the LoggerProvider is expected to be the stateful object that holds any configuration. (Note: The SDK implementation of this is what we currently call the [LogEmitterProvider](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/logging-library-sdk.md#logemitterprovider))
joaopgrassi marked this conversation as resolved.
Show resolved Hide resolved

Normally, the LoggerProvider is expected to be accessed from a central place. Thus, the API SHOULD provide a way to set/register and access a global default LoggerProvider.

Notwithstanding any global LoggerProvider, some applications may want to or have to use multiple LoggerProvider instances, e.g. to have different configuration (like LogRecordProcessors) for each (and consequently for the Loggers obtained from them), or because it's easier with dependency injection frameworks. Thus, implementations of LoggerProvider SHOULD allow creating an arbitrary number of instances.

#### LoggerProvider operations
scheler marked this conversation as resolved.
Show resolved Hide resolved

The LoggerProvider MUST provide the following functions:

* Get a Logger

##### Get a Logger
scheler marked this conversation as resolved.
Show resolved Hide resolved

This API MUST accept the following parameters that determine the scope for the `Logger` returned. Most of these are common with the scope parameters for `Tracer` and `Meter`, except for `event_domain` and `include_trace_context` which is specific to `Logger`.
scheler marked this conversation as resolved.
Show resolved Hide resolved

- `name` (required): This name SHOULD uniquely identify the [instrumentation scope](../glossary.md#instrumentation-scope), such as the [instrumentation library](../glossary.md#instrumentation-library) (e.g. `io.opentelemetry.contrib.mongodb`), package, module or class name. If an application or library has built-in OpenTelemetry instrumentation, both [Instrumented library](../glossary.md#instrumented-library) and [Instrumentation library](../glossary.md#instrumentation-library) may refer to the same library. In that scenario, the `name` denotes a module name or component name within that library or application. In case an invalid name (null or empty string) is specified, a working Logger implementation MUST be returned as a fallback rather than returning null or throwing an exception, its `name` property SHOULD be set to an empty string, and a message reporting that the specified value is invalid SHOULD be logged. A library implementing the OpenTelemetry API may also ignore this name and return a default instance for all calls, if it does not support "named" functionality (e.g. an implementation which is not even observability-related). A LoggerProvider could also return a no-op Logger here if application owners configure the SDK to suppress telemetry produced by this library.

scheler marked this conversation as resolved.
Show resolved Hide resolved
- `version` (optional): Specifies the version of the instrumentation scope if the scope has a version (e.g. a library version). Example value: 1.0.0.
- `schema_url` (optional): Specifies the Schema URL that should be recorded in the emitted telemetry
scheler marked this conversation as resolved.
Show resolved Hide resolved
- `event_domain` (optional): Specifies the domain for the events created, which should be added in the attribute `event.domain` in the instrumentation scope.
scheler marked this conversation as resolved.
Show resolved Hide resolved
- `include_trace_context` (optional): Specifies whether the Trace Context should automatically be passed on to the events and logs created by the Logger. This SHOULD be false by default.
scheler marked this conversation as resolved.
Show resolved Hide resolved
scheler marked this conversation as resolved.
Show resolved Hide resolved
- `attributes` (optional): Specifies the instrumentation scope attributes to associate with emitted telemetry.

Implementations MUST return different `Logger` instances when called repeatedly with different values of parameters. Note that always returning a new `Logger` instance is a valid implementation. The only exception to this rule is the no-op `Logger`: implementations MAY return the same instance regardless of parameter values.

Implementations MUST NOT require users to repeatedly obtain an Logger again with the same name+version+schema_url+event_domain+include_trace_context+attributes to pick up configuration changes. This can be achieved either by allowing to work with an outdated configuration or by ensuring that new configuration applies also to previously returned Loggers.

Note: This could, for example, be implemented by storing any mutable configuration in the LoggerProvider and having Logger implementation objects have a reference to the LoggerProvider from which they were obtained. If configuration must be stored per-Logger (such as disabling a certain Logger), the Logger could, for example, do a look-up with its name+version+schema_url+event_domain+include_trace_context+attributes in a map in the LoggerProvider, or the LoggerProvider could maintain a registry of all returned Loggers and actively update their configuration if it changes.

The effect of associating a Schema URL with a Logger MUST be that the telemetry emitted using the Logger will be associated with the Schema URL, provided that the emitted data format is capable of representing such association.

### Logger

The Logger is responsible for creating Events and Logs.
scheler marked this conversation as resolved.
Show resolved Hide resolved

Note that Loggers should not be responsible for configuration. This should be the responsibility of the LoggerProvider instead.

#### Logger operations

The Logger MUST provide functions to:

- Create an `Event` and emit it to the processing pipeline.
scheler marked this conversation as resolved.
Show resolved Hide resolved
- The API MUST accept an event name as a parameter. The event name provided should be inserted as an attribute with key `event.name`. Care MUST be taken to not override or delete this attribute while the `Event` is created. This function MAY be named `logEvent`.
scheler marked this conversation as resolved.
Show resolved Hide resolved
- Create a `Log Record` and emit it to the processing pipeline.
scheler marked this conversation as resolved.
Show resolved Hide resolved
- This function MAY be named `logRecord`.
- The intended users of this API is Log Appenders.
scheler marked this conversation as resolved.
Show resolved Hide resolved

Binary file added specification/logs/img/events-and-logs-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions specification/logs/semantic_conventions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The following semantic conventions for logs are defined:

* [Log Media](media.md): Semantic attributes that may be used in describing the source of a log.

The following semantic conventions for events are defined:

* [Events](events.md): Semantic attributes that must be used to represent Events using log data model.


Apart from semantic conventions for logs, [traces](../../trace/semantic_conventions/README.md), and [metrics](../../metrics/semantic_conventions/README.md),
OpenTelemetry also defines the concept of overarching [Resources](../../resource/sdk.md) with their own
[Resource Semantic Conventions](../../resource/semantic_conventions/README.md).
19 changes: 19 additions & 0 deletions specification/logs/semantic_conventions/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Semantic Convention for event attributes

**Status**: [Experimental](../../document-status.md)

This document describes the attributes of standalone Events that are represented by `LogRecord`s. All standalone Events have a name and a domain. The Event domain is used as a mechanism to avoid conflicts with event names.
scheler marked this conversation as resolved.
Show resolved Hide resolved

**type:** `event`

**Description:** Event attributes.

scheler marked this conversation as resolved.
Show resolved Hide resolved
| Attribute | Type | Description | Examples | Required |
scheler marked this conversation as resolved.
Show resolved Hide resolved
|---|---|---|---|---|
| `event.name` | string | Name or type of the event. | `network-change`; `button-click`; `exception` | Yes |
scheler marked this conversation as resolved.
Show resolved Hide resolved
| `event.domain` | string | Domain or scope for the event. | `profiling`; `browser`, `db`, `k8s` | No |

An `event.name` is supposed to be unique only in the context of an `event.domain`, so this allows for two events in different domains to have same `event.name`, yet be unrelated events. No claim is made about the uniqueness of `event.name`s in the absence of `event.domain`.

Note that Scope attributes are equivalent to the attributes at Span and LogRecord level, so recording the attribute `event.domain` on the Scope is equivalent to recording it on Spans and LogRecords within the Scope.