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

Introduce Scope Attributes #201

Merged
Show file tree
Hide file tree
Changes from 2 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
148 changes: 148 additions & 0 deletions text/0201-scope-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Introduce Scope Attributes

This OTEP adds attributes to the Scope.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved

## Motivation

There are a few reasons why adding Scope attributes is a good idea:

- There are 2 known use cases where Scope attributes can solve specific problems:
- Add support for [Meter "short_name"](https://github.com/open-telemetry/opentelemetry-specification/pull/2422),
represented as an attribute of Meter's Scope.
- Add support for differentiating the type of data emitted from the scopes that belong
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
to different data domains, e.g. profiling data emitted as log records or client-side
data emitted as log records needs to be differentiated so that it can be easily
routed and processed differently in the backends. We don't have a good way to handle
this today. The type of the data can be recorded as an attribute Logger's Scope.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
- It makes Scope consistent with the other primary data types: Resource, Span, Metric,
LogRecord.

See additional [discussion here](https://github.com/open-telemetry/opentelemetry-specification/issues/2450).

## Summary

The following is the summary of proposed changes:

- We will extend OpenTelemetry API to allow specifying Scope attributes when obtaining a
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
Tracer, Meter or LogEmitter. Scope attributes will be optional.
- We will add `attributes` field to the [InstrumentationScope](https://github.com/open-telemetry/opentelemetry-proto/blob/88faab1197a2a105c7da659951e94bc951d37ab9/opentelemetry/proto/common/v1/common.proto#L83)
message of OTLP.
- We will specify that Telemetry emitted via a Scope-ed Tracer, Meter or LogEmitter will
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
be associated with the Scope's attributes.
- We will specify that OTLP Exporter will record the attributes in the
InstrumentationScope message.
- We will create a section for Scope attributes' semantic conventions in
the specification.

## Internal details

### API Changes

`Get a Tracer` API will be extended to add the following parameter:

```
- `attributes` (optional): Specifies the instrumentation scope attributes to associate
with emitted telemetry.
```

`Get a Metter` API will be extended to add the following parameter:
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved

```
- `attributes` (optional): Specifies the instrumentation scope attributes to associate
with emitted telemetry.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
```

`Get LogEmitter` SDK call will be altered to the following:

```
Accepts the instrumentation scope name and optional version and attributes and
returns a LogEmitter associated with the instrumentation scope.
```

Since the attributes are optional this is a backwards compatible change.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved

### OTLP Changes

The InstrumentationScope message in OTLP will be modified to add 2 new fields:
attributes and dropped_attributes_count:

```protobuf
message InstrumentationScope {
string name = 1;
string version = 2;
repeated KeyValue attributes = 3;
uint32 dropped_attributes_count = 4;
}
```

This change is backwards compatible from OTLP's interoperability perspective. Recipients
of old OTLP versions will not see the Scope attributes and will ignore them, which we
consider acceptable from interoperability perspective. This is aligned with our general
stance on what happens when telemetry sources _add_ new data which old recipients
don't understand: we expect the new data to be safely ignored.

## Attribute Value Precedence

If the same attribute is specified both at the Span/Metric/LogRecord and at the Scope
then the attribute value at Span/Metric/LogRecord takes precedence.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved

This rule applies to non-OTLP exporters in SDKs, to conversions from OTLP to non-OTLP
formats in the Collector and to OTLP recipients of data that need to interpret the
attributes in the received data.

## Exporting to non-OTLP

tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
SDK's non-OTLP Exporters and Collector's exporter to formats that don't have a concept
that is equivalent to the Scope will record the attributes at the most suitable place
in their corresponding format, typically at the Span, Metric or LogRecord equivalent.

## Prior art and alternatives

The [Meter "short_name" PR](https://github.com/open-telemetry/opentelemetry-specification/pull/2422)
had an alternate approach where the "short_name" was added as the only attribute to the
InstrumentationScope. This OTEP's proposal generalizes this and allows arbitrary
attributes which allows them to be used for use cases.

Differentiating the type of data emitted from the scopes that belong to different data
domains can be alternatively done by recording attributes on the Span, Metric or LogRecord.
However, this will be less efficient since it will require the same attributes to be
specified repeatedly on the wire. It will be also cumbersome to require the callers
to always specify such attributes when creating a Span, Metric or a LogRecord as
opposed to specifying them once when obtaining the Trace, Meter or LogEmitter.

## Examples

### Usage in Code

The following is an example usage where LogEmitter is used to emit client-side
log records (pseudocode follows):

```
// obtain a logger once, at startup.
logger = LogEmitterProvider.GetLogEmitter("mylibrary", "1.0.0", KeyValue("otel.clientside", true))

// somewhere later in the code
logger.emit(LogRecord{Body:"click", Attributes:...})
```

### LogRecord Multiplexing

Here is an example usage where LogRecords are used to represent profiling data,
client-side events and regular logs. The Scope attribute is used for multiplexing
and routing the LogRecords:

![LogRecord Multiplexing](img/0201-scope-multiplexing.png)

## Open questions

- Should we allow/encourage recording Span/Metric/LogRecord attributes at the Scope level?
The alternate is to disallow this and have completely separate set of semantic
conventions that are allowed for Scope attributes only.
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
- Can all existing APIs in all languages be safely modified to ensure the addition
of the optional attributes is not a breaking change? (It should be safe, since we did
a very similar change when we [introduced the Scope](https://github.com/open-telemetry/opentelemetry-specification/pull/2276))

## Future possibilities

If this OTEP is accepted we need to then introduce the relevant semantic conventions
that will make the 2 use cases [described earlier](#motivation) possible.
Binary file added text/img/0201-scope-multiplexing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.