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

otlpmetric: StartTimeUnixNano for Gauge metric points is always set to "11651379494838206464" #4268

Closed
pellared opened this issue Jun 29, 2023 Discussed in #4265 · 0 comments · Fixed by #4271
Closed

otlpmetric: StartTimeUnixNano for Gauge metric points is always set to "11651379494838206464" #4268

pellared opened this issue Jun 29, 2023 Discussed in #4265 · 0 comments · Fixed by #4271
Assignees
Labels
area:metrics Part of OpenTelemetry Metrics bug Something isn't working pkg:exporter:otlp Related to the OTLP exporter package

Comments

@pellared
Copy link
Member

pellared commented Jun 29, 2023

Repro steps

Code:

package main

import (
	"context"

	"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
	"go.opentelemetry.io/otel/metric"
	metricsdk "go.opentelemetry.io/otel/sdk/metric"
)

func main() {
	ctx := context.Background()
	exp, err := otlpmetrichttp.New(ctx, otlpmetrichttp.WithInsecure())
	if err != nil {
		panic(err)
	}

	meterProvider := metricsdk.NewMeterProvider(metricsdk.WithReader(metricsdk.NewPeriodicReader(exp)))
	defer func() {
		if err := meterProvider.Shutdown(ctx); err != nil {
			panic(err)
		}
	}()

	meter := meterProvider.Meter("go-playground")

	_, err = meter.Int64ObservableGauge("async-gauge", metric.WithInt64Callback(
		func(ctx context.Context, io metric.Int64Observer) error {
			io.Observe(123)
			return nil
		},
	))
	if err != nil {
		panic(err)
	}
}

Add a breakpoint here:

otlpRm, err := transform.ResourceMetrics(rm)
// Best effort upload of transformable metrics.
e.clientMu.Lock()
and run the debugger.

Actual

You will notice that the input (rm *metricdata.ResourceMetrics) contains z zero value of time.Time for StartTime and after serializing to proto the payload contains StartTimeUnixNano = 11651379494838206464 which is far from being correct: Tue 21 March 2339 22:18:14.838 UTC

Expected

  1. Fix the transform.ResourceMetrics(rm) to properly handle time.Time zero values. Take notice: https://pkg.go.dev/time#Time.UnixNano. Probably we could set StartTimeUnixNano = 0.
  2. (nice to have, this might be tracked as a separate issue) The initial StartTime could be set as suggested per specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#gauge. EDIT: I created sdk/metric: Set StartTime for gauge metric points #4269

Discussed in #4265

@anil181 thank you for reporting the issue.

@pellared pellared added bug Something isn't working area:metrics Part of OpenTelemetry Metrics pkg:exporter:otlp Related to the OTLP exporter package labels Jun 29, 2023
@pellared pellared changed the title otlpmetric: StartTimeUnixNano is always set to "11651379494838206464" otlpmetric: StartTimeUnixNano for Gauge metric points is always set to "11651379494838206464" Jun 29, 2023
@pellared pellared self-assigned this Jun 29, 2023
@pellared pellared moved this from Todo to In Progress in Go: Metric SDK (GA) Jun 29, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Go: Metric SDK (GA) Jun 30, 2023
@MrAlias MrAlias added this to the v1.17.0/v0.40.0 milestone Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics bug Something isn't working pkg:exporter:otlp Related to the OTLP exporter package
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants