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

sdk/metric does not respect metric.WithInstrumentationAttributes #4687

Closed
pellared opened this issue Nov 2, 2023 · 2 comments
Closed

sdk/metric does not respect metric.WithInstrumentationAttributes #4687

pellared opened this issue Nov 2, 2023 · 2 comments
Labels
area:metrics Part of OpenTelemetry Metrics bug Something isn't working pkg:SDK Related to an SDK package

Comments

@pellared
Copy link
Member

pellared commented Nov 2, 2023

Description

The metrics SDK does not add attributes added using metric.WithInstrumentationAttributes

Reported via Gophers Slack: https://gophers.slack.com/archives/CK623313R/p1698843326696549

Environment

  • OS: any
  • Architecture: any
  • Go Version: 1.21
  • opentelemetry-go version: v1.19.0

Steps To Reproduce

https://go.dev/play/p/eoD76GfYWnz

package main

import (
	"context"
	"log"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
	metricapi "go.opentelemetry.io/otel/metric"
	"go.opentelemetry.io/otel/sdk/metric"
	"go.opentelemetry.io/otel/sdk/resource"
)

func main() {
	metricExporter, err := stdoutmetric.New()
	if err != nil {
		log.Fatalln(err)
	}
	reader := metric.NewPeriodicReader(metricExporter)

	meterProvider := metric.NewMeterProvider(
		metric.WithResource(resource.Empty()),
		metric.WithReader(reader),
	)

	m := meterProvider.Meter("my-package", metricapi.WithInstrumentationAttributes(attribute.Key("foo").Int(42)))
	cnt, _ := m.Int64Counter("count")
	cnt.Add(context.Background(), 1)

	err = meterProvider.Shutdown(context.Background())
	if err != nil {
		log.Fatalln(err)
	}
}

Output:

{"Resource":null,"ScopeMetrics":[{"Scope":{"Name":"my-package","Version":"","SchemaURL":""},"Metrics":[{"Name":"count","Description":"","Unit":"","Data":{"DataPoints":[{"Attributes":[],"StartTime":"2009-11-10T23:00:00Z","Time":"2009-11-10T23:00:00Z","Value":1}],"Temporality":"CumulativeTemporality","IsMonotonic":true}}]}]}

Expected behavior

The data points for count has foo attribute with value 42 .

@pellared pellared added bug Something isn't working pkg:SDK Related to an SDK package area:metrics Part of OpenTelemetry Metrics labels Nov 2, 2023
@MrAlias
Copy link
Contributor

MrAlias commented Nov 2, 2023

The data points for count has foo attribute with value 42 .

Instrumentation attributes would be added to the scope, not the instrument.

They are currently dropped because we do not have a resolution to #3368. Namely, have the specification define a way to export these.

@pellared
Copy link
Member Author

pellared commented Nov 2, 2023

Duplicate of #3368

@pellared pellared marked this as a duplicate of #3368 Nov 2, 2023
@pellared pellared closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 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:SDK Related to an SDK package
Projects
None yet
Development

No branches or pull requests

2 participants