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

Instrument identity, registration conflicts, multi-callback registration, unregister support #2317

Merged
merged 56 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
dc3d5ed
allow duplicate instrument reg
jmacd Jan 18, 2022
80c0e73
comment about single-writer rule and duplicate instruments
jmacd Jan 18, 2022
64c955f
comment about duplicate asynchronous observations
jmacd Jan 18, 2022
e70203c
refer to supp guidelines as well
jmacd Jan 18, 2022
55a1a88
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 1, 2022
fc0cfe9
first draft update
jmacd Feb 3, 2022
db71662
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 4, 2022
c94358f
pre-merge
jmacd Feb 4, 2022
72d484b
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 4, 2022
806317b
finish draft
jmacd Feb 4, 2022
e166181
two edits
jmacd Feb 4, 2022
73d3c03
SDK req
jmacd Feb 4, 2022
0ffc305
intrinsic properties
jmacd Feb 4, 2022
7d5163b
from 2270
jmacd Feb 4, 2022
0778baf
typos
jmacd Feb 4, 2022
bd3056a
add summary
jmacd Feb 4, 2022
65d6147
Require a shorter test for probability sampler
jmacd Feb 4, 2022
f3cbbcc
Update specification/metrics/sdk.md
jmacd Feb 7, 2022
ef78747
Update specification/metrics/datamodel.md
jmacd Feb 7, 2022
fc06d2e
add unit to identity for data points
jmacd Feb 7, 2022
3d27e97
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 10, 2022
e9384f0
clarify data model uniqueness
jmacd Feb 10, 2022
40f8ed8
clarify how to report semantic errors and when they can be remediated
jmacd Feb 10, 2022
faf19c1
lint
jmacd Feb 11, 2022
f80bc10
Merge branch 'main' into jmacd/less_prob_sample_test
jmacd Feb 11, 2022
dfc5009
spelling
jmacd Feb 11, 2022
521cb6a
Merge branch 'jmacd/less_prob_sample_test' of github.com:jmacd/opente…
jmacd Feb 11, 2022
841aa47
spelling
jmacd Feb 11, 2022
307e6c2
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 11, 2022
eb2430c
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 11, 2022
941e11a
Merge branch 'jmacd/less_prob_sample_test' of github.com:jmacd/opente…
jmacd Feb 11, 2022
58e4335
revert mistake unrelated
jmacd Feb 11, 2022
8e93d28
identical and distinct, respectively
jmacd Feb 11, 2022
be56745
refer to API/datamodel spec in SDK spec for conflict res
jmacd Feb 11, 2022
58d20d7
try to clarifyt async observation APIs
jmacd Feb 11, 2022
421ddbc
edits
jmacd Feb 12, 2022
8e56ae6
Update specification/metrics/api.md
jmacd Feb 14, 2022
cb2fa43
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 14, 2022
16b1be0
example unregister in python
jmacd Feb 14, 2022
733edcc
Merge branch 'jmacd/dup_instruments' of github.com:jmacd/opentelemetr…
jmacd Feb 14, 2022
5e77317
let multi-instrument be MAY
jmacd Feb 14, 2022
33d6c47
Update specification/metrics/api.md
jmacd Feb 15, 2022
3b13c12
Update specification/metrics/api.md
jmacd Feb 15, 2022
1f4243b
Update specification/metrics/sdk.md
jmacd Feb 15, 2022
84b9bd8
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 15, 2022
478b3cd
remove multi-instrument callbacks for now
jmacd Feb 15, 2022
519e854
update examples
jmacd Feb 15, 2022
dba0a00
example text
jmacd Feb 15, 2022
351eea6
remove use of 'context'
jmacd Feb 15, 2022
32c001b
move an SDK req
jmacd Feb 15, 2022
06cbf7d
lint
jmacd Feb 15, 2022
eca822e
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Feb 16, 2022
21d2852
Merge branch 'main' into jmacd/dup_instruments
bogdandrutu Feb 17, 2022
8a56608
Fix lint
Feb 17, 2022
6bf3b0a
Merge branch 'main' into jmacd/dup_instruments
Feb 17, 2022
9e1a2d6
Update specification/metrics/api.md
jmacd Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 84 additions & 20 deletions specification/metrics/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,24 @@ This API MUST accept the following parameters:
* [since 1.4.0] `schema_url` (optional): Specifies the Schema URL that should be
recorded in the emitted telemetry.

It is unspecified whether or under which conditions the same or different
`Meter` instances are returned from this functions.

Implementations MUST NOT require users to repeatedly obtain a `Meter` again with
the same name+version+schema_url to pick up configuration changes. This can be
Meters are identified by all of these fields. When more than one
Meter of the same `name`, `version`, and `schema_url` is created, it
is unspecified whether or under which conditions the same or different
jmacd marked this conversation as resolved.
Show resolved Hide resolved
`Meter` instances are returned. Meter identity, and the terms
_identical_ and _distinct_ applied to Meters in this specification
describes Meter instances that have identical and/or distinct values
jmacd marked this conversation as resolved.
Show resolved Hide resolved
for all three of their `name`, `version`, and `schema_url` attributes.

Implementations MUST NOT require users to repeatedly obtain a `Meter` with
the same identity 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 `Meter`s.
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -175,19 +180,50 @@ Instruments are used to report [Measurements](#measurement). Each Instrument
will have the following information:
jmacd marked this conversation as resolved.
Show resolved Hide resolved

* The `name` of the Instrument
* The `kind` of the Instrument - whether it is a [Counter](#counter) or other
instruments, whether it is synchronous or asynchronous
* The `kind` of the Instrument - whether it is a [Counter](#counter) or
one of the other kinds, whether it is synchronous or asynchronous
* An optional `unit` of measure
* An optional `description`

Instruments are associated with the Meter during creation, and are identified by
the name:
Instruments are associated with the Meter during creation. Instruments
are identified by all of these fields.

<a name="instrument-type-conflict-detection"></a>

When more than one Instrument of the same `name` is created for
identical Meters, denoted _duplicate instrument registration_, the
implementation MUST return a valid Instrument in every case.
jmacd marked this conversation as resolved.
Show resolved Hide resolved
jmacd marked this conversation as resolved.
Show resolved Hide resolved

It is unspecified whether or under which conditions the same or
different Instrument instance will be returned as a result of
duplicate instrument registration. Instrument identity, and the terms
_identical_ and _distinct_ applied to Instruments in this
specification describes Instrument instances that have identical
and/or distinct values for all four of their `name`, `kind`, `unit`,
and `description` attributes. Language-level features such the
distinction between integer and floating point numbers SHOULD be
jmacd marked this conversation as resolved.
Show resolved Hide resolved
considered as identifying, as well.

The implementation MUST aggregate data from identical Instruments
together in its export pipeline.
jmacd marked this conversation as resolved.
Show resolved Hide resolved

When through duplicate registration more than one distinct Instrument
jmacd marked this conversation as resolved.
Show resolved Hide resolved
is registered with the same `name` for identical Meters, the
implementation SHOULD emit a warning to the user informing them of
duplicate registration conflict(s).

__Note the warning about duplicate instrumentation registration
jmacd marked this conversation as resolved.
Show resolved Hide resolved
conflicts is meant to help avoid the semantic error state described in
the [OpenTelemetry Metrics data
model](datamodel.md#opentelemetry-data-model) when more than one kind
of point is written for a given instrument `name` and Meter identity
from the same process.
jmacd marked this conversation as resolved.
Show resolved Hide resolved

<a name="instrument-namespace"></a>

* Meter implementations MUST return an error when multiple Instruments are
registered under the same Meter instance using the same name.
* Different Meters MUST be treated as separate namespaces. The names of the
Instruments under one Meter SHOULD NOT interfere with Instruments under
another Meter.
Distinct Meters MUST be treated as separate namespaces for the
purposes of detecting [duplicate instrument registration
conflicts](#instrument-type-conflict-detection).

<a name="instrument-naming-rule"></a>

Expand All @@ -210,7 +246,7 @@ DIGIT = %x30-39 ; 0-9

<a name="instrument-unit"></a>

The `unit` is an optional string provided by the author of the instrument. It
The `unit` is an optional string provided by the author of the Instrument. It
SHOULD be treated as an opaque string from the API and SDK (e.g. the SDK is not
expected to validate the unit of measurement, or perform the unit conversion).

Expand Down Expand Up @@ -239,7 +275,7 @@ instrument. It MUST be treated as an opaque string from the API and SDK.
* It MUST support at least 1023 characters. [OpenTelemetry
API](../overview.md#api) authors MAY decide if they want to support more.

Instruments can be categorized based on whether they are synchronous or
Instruments are categorized based on whether they are synchronous or
jmacd marked this conversation as resolved.
Show resolved Hide resolved
asynchronous:

<a name="synchronous-instrument"></a>
Expand All @@ -264,6 +300,25 @@ Please note that the term _synchronous_ and _asynchronous_ have nothing to do
with the [asynchronous
pattern](https://en.wikipedia.org/wiki/Asynchronous_method_invocation).

Considering duplicate registration of asynchronous instruments, the
jmacd marked this conversation as resolved.
Show resolved Hide resolved
implementation MUST support multiple callbacks registered per
identical instrument.

The API MAY provide support for registration of a single callback
jmacd marked this conversation as resolved.
Show resolved Hide resolved
having multiple asynchronous instruments, where idiomatic. The
jmacd marked this conversation as resolved.
Show resolved Hide resolved
implementation is REQUIRED to maintain a mapping from every regsitered
jmacd marked this conversation as resolved.
Show resolved Hide resolved
callback to the associated instrument(s).

The implementation MUST provide a way to unregister callbacks
jmacd marked this conversation as resolved.
Show resolved Hide resolved
associated with asynchronous instruments.

The implementation SHOULD reject observations that are made outside of
jmacd marked this conversation as resolved.
Show resolved Hide resolved
a callback registered for the instrument.

Callers SHOULD avoid making duplicate observations from asynchronous
jmacd marked this conversation as resolved.
Show resolved Hide resolved
jmacd marked this conversation as resolved.
Show resolved Hide resolved
jmacd marked this conversation as resolved.
Show resolved Hide resolved
instrument callbacks, as the result of making duplicate observations
is not specified.
jmacd marked this conversation as resolved.
Show resolved Hide resolved

### Counter

`Counter` is a [synchronous Instrument](#synchronous-instrument) which supports
Expand Down Expand Up @@ -396,7 +451,10 @@ The API MUST accept the following parameters:
rule](#instrument-unit).
* An optional `description`, following the [instrument description
rule](#instrument-description).
* A `callback` function.

The API MUST support an idiomatic way to associate one or more
`callback` functions with each instrument, whether through the
jmacd marked this conversation as resolved.
Show resolved Hide resolved
instrument constructor or a separate registration method.

The `callback` function is responsible for reporting the
[Measurement](#measurement)s. It will only be called when the Meter is being
Expand Down Expand Up @@ -613,7 +671,10 @@ The API MUST accept the following parameters:
rule](#instrument-unit).
* An optional `description`, following the [instrument description
rule](#instrument-description).
* A `callback` function.

The API MUST support an idiomatic way to associate one or more
`callback` functions with each instrument, whether through the
jmacd marked this conversation as resolved.
Show resolved Hide resolved
instrument constructor or a separate registration method.

The `callback` function is responsible for reporting the
[Measurement](#measurement)s. It will only be called when the Meter is being
Expand Down Expand Up @@ -885,7 +946,10 @@ The API MUST accept the following parameters:
rule](#instrument-unit).
* An optional `description`, following the [instrument description
rule](#instrument-description).
* A `callback` function.

The API MUST support an idiomatic way to associate one or more
`callback` functions with each instrument, whether through the
jmacd marked this conversation as resolved.
Show resolved Hide resolved
instrument constructor or a separate registration method.

The `callback` function is responsible for reporting the
[Measurement](#measurement)s. It will only be called when the Meter is being
Expand Down
28 changes: 22 additions & 6 deletions specification/metrics/datamodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,33 @@ can be converted directly into Timeseries, and share the same identity
characteristics for a Timeseries. A metric stream is identified by:

- The originating `Resource`
- The metric's associated Meter details (`name`, `version`, and `schema_url`)
jmacd marked this conversation as resolved.
Show resolved Hide resolved
- The metric stream's `name`.
- The attached `Attribute`s
- The metric stream's point kind.
- The metric stream's point kind (`Sum`, `Gauge`, `Histogram` `ExponentialHistogram`)
jmacd marked this conversation as resolved.
Show resolved Hide resolved

It is possible (and likely) that more than one metric stream is created per
`Instrument` in the event model.

__Note: The same `Resource`, `name` and `Attribute`s but differing point kind
coming out of an OpenTelemetry SDK is considered an "error state" that SHOULD
be handled by an SDK.__

A metric stream can use one of these basic point kinds, all of
Points with identical `name`, `Resource`, and Meter details but
different point kind SHOULD be considered an "error state", due to
semantic disagreement, whether or not they use distinct `Attribute`
values.

Consumers of OpenTelemetry metrics data streams MAY reject data
containing the multiple point kinds for identical `name`, `Resource`,
and Meter details, even though the [Single-Writer](#single-writer)
rule is only broken when distinct `Attribute` values are involved.

__Note: The OpenTelemetry SDK specification is written to explicitly
permit duplicate instrumentation registration, which means the
potential to produce the error state. This is considered to be in the
user's best interest. Although the SDK has permission to pass-through
jmacd marked this conversation as resolved.
Show resolved Hide resolved
duplicate instrument registration conflicts, consumers of
OpenTelemetry metrics are given equal permission to reject the data
because of semantic disagreement.

A metric stream can use one of the basic point kinds, all of
which satisfy the requirements above, meaning they define a decomposable
aggregate function (also known as a “natural merge” function) for points of the
same kind. <sup>[1](#otlpdatapointfn)</sup>
Expand Down Expand Up @@ -749,6 +764,7 @@ All metric data streams within OTLP MUST have one logical writer. This means,
conceptually, that any Timeseries created from the Protocol MUST have one
originating source of truth. In practical terms, this implies the following:

@@@
- All metric data streams produced by OTel SDKs MUST be globally uniquely
produced and free from duplicates. All metric data streams can be uniquely
identified in some way.
Expand Down
23 changes: 23 additions & 0 deletions specification/metrics/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,26 @@ called concurrently.

**MetricExporter** - `ForceFlush` and `Shutdown` are safe to be called
concurrently.

## Data model requirements

The [OpenTelemetry Metrics data
model](datamodel.md#opentelemetry-protocol-data-model) has a [Single
Writer](datamodel.md#single-writer) rule which the SDK is required to
enforce, with one exception noted below. This rule is the origin of
the output-name uniqueness requirement for [Views](#view) and is the
reason the API specifies that implementations MUST aggregate data for
identical instruments in its pipeline.

The implementation has permission to pass-through violations of the
semantic "error state" described in the [OpenTelemetry Metrics data
model](datamodel.md#opentelemetry-protocol-data-model). This is to
address the exceptional case of duplicate instrument registration
conflicts, which are tolerated with warnings in the API.

Duplicate instrument registration conflicts can produce this semantic
error state, which may lead to violations of the single-writer rule.
SDKs are permitted to allow these conflicts to take place to avoid
jmacd marked this conversation as resolved.
Show resolved Hide resolved
user data loss. Since the semantic conflict may not be resolvable
downstream, Metrics data consumers MAY reject semantically conflicting
data and SHOULD notify the user of the error, somehow, in such cases.