opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

ObservableGauge StartTimeStamp could be None instead of zero

Open tammy-baylis-swi opened this issue 1 year ago • 1 comments

Describe your environment

I'm using the ObservableGauge (like the docs example) and have my setup exporting by OTLP to an otel collector instance that exports to logging. I noticed the StartTimestamp is zeroed out in every exported metrics message:

Metric #1
Descriptor:
     -> Name: my.gauged.value
     -> Description: 
     -> Unit: 
     -> DataType: Gauge
NumberDataPoints #0
Data point attributes:
     -> status: Bool(true)
StartTimestamp: 1970-01-01 00:00:00 +0000 UTC
Timestamp: 2024-01-26 19:33:04.70007188 +0000 UTC
Value: 1

I've seen this with both unreleased SDK installed on my local (1.23.0.dev) and older release (1.20.0), on Python 3.9 in a locally-running Linux docker container.

Steps to reproduce Describe exactly how to reproduce the error. Include a code sample if applicable.

  1. Set up a docker container to run an instrumented Python script/service like the docs example
  2. Set up a 2nd container to run image: otel/opentelemetry-collector:latest, configured with logging exporter.
  3. Point instrumented container to otelcol, e.g. OTEL_EXPORTER_OTLP_ENDPOINT="http://otel-collector:4318"
  4. Run so instrumented container exports to otelcol, which exports to logs.

What is the expected behavior? StartTimestamp of None.

Originally I thought it should be the time of startup of the instrumented app, but it's not so appropriate for the temporality and aggregation of the ObservableGauge type (proto).

What is the actual behavior? StartTimestamp: 1970-01-01 00:00:00 +0000 UTC, which is a little misleading

Additional context

  • We chatted about this during Feb 8 2024 sig meeting, and also previously on Slack (thanks Pablo).
  • Zero start time seems to be set here: https://github.com/open-telemetry/opentelemetry-python/blob/cc8fd8838aaf9cbd8b19d9617da4e3d4aaee384b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py#L369
  • Spec says start time is optional https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#gauge
  • ObservableGauge proto: https://github.com/open-telemetry/opentelemetry-proto/blob/c451441d7b73f702d1647574c730daf7786f188c/opentelemetry/proto/metrics/v1/metrics.proto#L212C12-L212C27

tammy-baylis-swi avatar Feb 08 '24 18:02 tammy-baylis-swi

cc @ocelotl

tammy-baylis-swi avatar Feb 08 '24 18:02 tammy-baylis-swi

Discussed in SIG. This is the expected behavior for protobuf regardless of if the field is set to zero or unset. See https://protobuf.dev/programming-guides/proto3/#default

There is something called field presence but I don't think this feature is being used here (start time is not marked optional to enable explicit presence)

aabmass avatar Jul 11 '24 16:07 aabmass