Skip to content

Commit d783245

Browse files
pellaredlmolkovajack-berg
authored
[Logs] Add optional Ergonomic API (#4741)
Fixes #4357 Fixes #4661 ## Changes Add optional Ergonomic API that it is better suited for direct usage by instrumentation libraries, instrumented libraries, and applications. ## Prototype Go: https://github.com/pellared/olog --------- Co-authored-by: Liudmila Molkova <neskazu@gmail.com> Co-authored-by: Jack Berg <34418638+jack-berg@users.noreply.github.com>
1 parent 09f9c23 commit d783245

6 files changed

Lines changed: 64 additions & 21 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ internal/tools/bin
2929
node_modules/
3030
package-lock.json
3131

32+
# Python virtual environment
33+
venv/
34+
3235
# Visual Studio Code
3336
.vscode
3437

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ release.
1818

1919
### Logs
2020

21+
- Add optional Ergonomic API.
22+
([#4741](https://github.com/open-telemetry/opentelemetry-specification/pull/4741))
23+
2124
### Baggage
2225

2326
### Profiles

spec-compliance-matrix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Disclaimer: this list of features is still a work in progress, please refer to t
202202
| Logger.Emit(LogRecord) | | + | + | + | + | + | | + | | + | - | |
203203
| LogRecord.Set EventName | | + | | | | | | | + | + | | |
204204
| Logger.Enabled | X | + | | | | | | + | + | + | | |
205+
| Ergonomic API | X | | | | | | | | | | | |
205206
| SimpleLogRecordProcessor | | + | + | + | + | + | | + | | + | | |
206207
| BatchLogRecordProcessor | | + | + | + | + | + | | + | | + | | |
207208
| Can plug custom LogRecordProcessor | | + | + | + | + | + | | + | | + | | |

spec-compliance-matrix/template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ sections:
237237
- name: LogRecord.Set EventName
238238
- name: Logger.Enabled
239239
optional: true
240+
- name: Ergonomic API
241+
optional: true
240242
- name: SimpleLogRecordProcessor
241243
- name: BatchLogRecordProcessor
242244
- name: Can plug custom LogRecordProcessor

specification/logs/README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,23 @@ Given the above state of the logging space we took the following approach:
143143
OpenTelemetry log data model. OpenTelemetry Collector can read such logs and
144144
translate them to OpenTelemetry log data model.
145145

146-
- OpenTelemetry defines a Logs API
147-
for [emitting LogRecords](./api.md#emit-a-logrecord). It is provided for
148-
library authors to build [log appender](../glossary.md#log-appender--bridge),
146+
- OpenTelemetry defines a [Logs API](./api.md)
147+
for [emitting LogRecords](./api.md#emit-a-logrecord). It was primarily designed
148+
for library authors to build [log appenders](../glossary.md#log-appender--bridge),
149149
which use the API to bridge between existing logging libraries and the
150-
OpenTelemetry log data model. Existing logging libraries generally provide
151-
a much richer set of features than what is defined in OpenTelemetry.
152-
It is NOT a goal of OpenTelemetry to ship a feature-rich logging library.
153-
Yet, the Logs API can also be used directly if one prefers to couple the code
154-
to it instead of using a bridged logging library.
150+
OpenTelemetry log data model. The Logs API can also be used directly by
151+
applications, which is particularly important for:
152+
153+
- **Instrumentation libraries** to avoid coupling to a particular logging library.
154+
- **Emitting structured events** following [semantic conventions](https://opentelemetry.io/docs/specs/semconv/),
155+
especially when the existing logging library cannot emit structured data or specify event names.
156+
- **Scenarios requiring direct control** over log emission without
157+
intermediary logging library.
158+
159+
Note that existing logging libraries generally provide a much richer set of
160+
features than what is defined in OpenTelemetry. Yet, languages may provide
161+
an [ergonomic API](./api.md#ergonomic-api) for better developer experience
162+
when using it directly.
155163

156164
- OpenTelemetry defines an [SDK](./sdk.md) implementation of the [API](./api.md),
157165
which enables configuration of [processing](./sdk.md#logrecordprocessor)
@@ -375,17 +383,30 @@ application startup.
375383

376384
These are greenfield developments. OpenTelemetry provides recommendations and
377385
best practices about how to emit logs (along with traces and metrics) from these
378-
applications. For applicable languages and frameworks the auto-instrumentation
379-
or simple configuration of a logging library to use an OpenTelemetry log appender
380-
will still be the easiest way to emit context-enriched logs. As
381-
already described earlier we provide extensions to some popular logging
382-
libraries languages to support the manual instrumentation cases. The extensions
383-
will support the inclusion of the trace context in the logs and allow to send
384-
logs using OTLP protocol to the backend or to the Collector, bypassing the need
385-
to have the logs represented as text files. Emitted logs are automatically
386-
augmented by application-specific resource context (e.g. process id, programming
387-
language, logging library name and version, etc). Full correlation across all
388-
context dimensions will be available for these logs.
386+
applications.
387+
388+
Applications have several options for emitting logs:
389+
390+
1. **Using existing logging libraries with OpenTelemetry log appenders**: For
391+
applicable languages and frameworks, auto-instrumentation or simple
392+
configuration of a logging library to use an OpenTelemetry log appender will
393+
be the easiest way to emit context-enriched logs. As already described earlier,
394+
we provide extensions to some popular logging libraries to support manual
395+
instrumentation cases. The extensions support the inclusion of the trace
396+
context in the logs and allow sending logs via OTLP protocol to the backend
397+
or to the Collector, bypassing the need to have the logs represented as text
398+
files.
399+
400+
2. **Using the OpenTelemetry Logs API directly**: Applications can use the
401+
[Logs API](./api.md) directly to emit structured logs and events. This approach
402+
works well for emitting events following [semantic conventions](https://opentelemetry.io/docs/specs/semconv/)
403+
and enables easier reuse of attributes used across different signals. Note
404+
that a language can provide a more convenient [ergonomic API](./api.md#ergonomic-api).
405+
406+
Regardless of the approach, emitted logs are automatically augmented by
407+
application-specific resource context (e.g. process id, programming language,
408+
logging library name and version, etc). Full correlation across all context
409+
dimensions will be available for these logs.
389410

390411
This is how a typical new application uses OpenTelemetry API, SDK and the
391412
existing log libraries:

specification/logs/api.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ aliases: [bridge-api]
66

77
# Logs API
88

9-
**Status**: [Stable](../document-status.md)
9+
**Status**: [Stable](../document-status.md), except where otherwise specified
1010

1111
<details>
1212
<summary>Table of Contents</summary>
@@ -23,6 +23,7 @@ aliases: [bridge-api]
2323
* [Enabled](#enabled)
2424
- [Optional and required parameters](#optional-and-required-parameters)
2525
- [Concurrency requirements](#concurrency-requirements)
26+
- [Ergonomic API](#ergonomic-api)
2627
- [References](#references)
2728

2829
<!-- tocstop -->
@@ -35,7 +36,8 @@ which use this API to bridge between existing logging libraries and the
3536
OpenTelemetry log data model.
3637

3738
The Logs API can also be directly called by instrumentation libraries
38-
as well as instrumented libraries or applications.
39+
as well as instrumented libraries or applications. However, languages are also
40+
free to provide a more [ergonomic API](#ergonomic-api) for direct usage.
3941

4042
The Logs API consist of these main components:
4143

@@ -167,6 +169,17 @@ specific guarantees and safeties.
167169

168170
**Logger** - all methods are safe to be called concurrently.
169171

172+
## Ergonomic API
173+
174+
**Status**: [Development](../document-status.md)
175+
176+
Languages MAY additionally provide a more ergonomic and convenient logging API.
177+
178+
The ergonomic API SHOULD make it more convenient to emit event records following
179+
the [event semantics](https://opentelemetry.io/docs/specs/semconv/general/events/).
180+
181+
The design of the ergonomic API SHOULD be idiomatic for its language.
182+
170183
## References
171184

172185
- [OTEP0150 Logging Library SDK Prototype Specification](../../oteps/logs/0150-logging-library-sdk.md)

0 commit comments

Comments
 (0)