Skip to content

stdoutmetric should output some bucket information #2345

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

Closed
david-gang opened this issue Nov 4, 2021 · 2 comments
Closed

stdoutmetric should output some bucket information #2345

david-gang opened this issue Nov 4, 2021 · 2 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Milestone

Comments

@david-gang
Copy link

Problem Statement

A clear and concise description of what the problem is.

I configured the globalmetricsprovider with stdoutmetric and histogram with 101 buckets

exporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint())
	if err != nil {
		log.Fatalln("failed to initialize metric stdout exporter:", err)
	}
	var boundaries []float64
	for i := 0.0; i <= 1000.0; i += 10 {
		boundaries = append(boundaries, i)
	}
	cont := controller.New(
		processor.NewFactory(
			simple.NewWithHistogramDistribution(histogram.WithExplicitBoundaries(boundaries)),
			exporter,
		),
		controller.WithExporter(exporter),
		controller.WithResource(newResource()),
	)
	if err := cont.Start(context.Background()); err != nil {
		log.Fatalln("failed to start the metric controller:", err)
	}
	global.SetMeterProvider(cont)

then i added afterwards a middleware of gin which measures latency:

func Logger() gin.HandlerFunc {
	provider := global.GetMeterProvider()
	meter := provider.Meter("gin-middleware")
	requestTimeStat, err := meter.NewInt64Histogram("request-latency")
	if err != nil {
		log.Fatalln("failed to create histogram", err)
	}

	ctx := context.Background()
	return func(c *gin.Context) {
		t := time.Now()
		c.Next()
		latency := time.Since(t).Milliseconds()
		requestTimeStat.Record(ctx, latency)
	}
}

The output was lacking all the bucket data and has just

	{
		"Name": "request-latency{environment=demo,service.name=coolResource,service.version=v0.1.0,telemetry.sdk.language=go,telemetry.sdk.name=opentelemetry,telemetry.sdk.version=1.1.0,instrumentation.name=gin-middleware}",
		"Sum": 2737
	}

I debugged the issue and found out https://github.com/open-telemetry/opentelemetry-go/blob/main/exporters/stdout/stdoutmetric/metric.go#L38

type line struct {
	Name      string      `json:"Name"`
	Min       interface{} `json:"Min,omitempty"`
	Max       interface{} `json:"Max,omitempty"`
	Sum       interface{} `json:"Sum,omitempty"`
	Count     interface{} `json:"Count,omitempty"`
	LastValue interface{} `json:"Last,omitempty"`

	// Note: this is a pointer because omitempty doesn't work when time.IsZero()
	Timestamp *time.Time `json:"Timestamp,omitempty"`
}

the output was missing all bucket info

Proposed Solution

A clear and concise description of what you want to happen.
Could the bucket info be added so all non empty buckets would be printed or if we fear that it would be too much than maybe the first 10 with dots ?

Alternatives

A clear and concise description of any alternative solutions or features you've considered.

Maybe it should be warned somewhere in a log that bucket info is missing

Prior Art

A clear and concise list of any similar and existing solutions from other projects that provide context to possible solutions.

Additional Context

Add any other context or screenshots about the feature request here.

@david-gang david-gang added the enhancement New feature or request label Nov 4, 2021
@MrAlias
Copy link
Contributor

MrAlias commented Nov 11, 2021

Likely duplicate of #954

@MrAlias MrAlias added the duplicate This issue or pull request already exists label Nov 11, 2021
@MrAlias
Copy link
Contributor

MrAlias commented May 3, 2022

Duplicate of #954

@MrAlias MrAlias marked this as a duplicate of #954 May 3, 2022
@MrAlias MrAlias closed this as completed May 3, 2022
@pellared pellared added this to the untracked milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants