mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-12 02:28:07 +02:00
Deprecate metric/unit
and use a string
for units in the metric API/SDK (#3776)
* Replace Unit from metric/unit with string Deprecate the units package. This package will not be included in the metric GA. * Add changes to changelog
This commit is contained in:
parent
17e5d0f549
commit
fe6856e804
@ -41,6 +41,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
- [bridge/ot] Fall-back to TextMap carrier when it's not ot.HttpHeaders. (#3679)
|
||||
- The `Collect` method of the `"go.opentelemetry.io/otel/sdk/metric".Reader` interface is updated to accept the `metricdata.ResourceMetrics` value the collection will be made into. This change is made to enable memory reuse by SDK users. (#3732)
|
||||
- The `WithUnit` option in `go.opentelemetry.io/otel/sdk/metric/instrument` is updated to accept a `string` for the unit value. (#3776)
|
||||
|
||||
### Fixed
|
||||
|
||||
@ -51,6 +52,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Data race issue in OTLP exporter retry mechanism. (#3756)
|
||||
- Fixes wrapping a nil error in some cases (#????)
|
||||
|
||||
### Deprecated
|
||||
|
||||
- The `go.opentelemetry.io/otel/metric/unit` package is deprecated.
|
||||
Use the equivalent unit string instead. (#3776)
|
||||
- Use `"1"` instead of `unit.Dimensionless`
|
||||
- Use `"By"` instead of `unit.Bytes`
|
||||
- Use `"ms"` instead of `unit.Milliseconds`
|
||||
|
||||
## [1.13.0/0.36.0] 2023-02-07
|
||||
|
||||
### Added
|
||||
|
@ -6,7 +6,6 @@ require (
|
||||
github.com/stretchr/testify v1.8.2
|
||||
go.opencensus.io v0.24.0
|
||||
go.opentelemetry.io/otel v1.13.0
|
||||
go.opentelemetry.io/otel/metric v0.36.0
|
||||
go.opentelemetry.io/otel/sdk v1.13.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.36.0
|
||||
go.opentelemetry.io/otel/trace v1.13.0
|
||||
@ -19,6 +18,7 @@ require (
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.36.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
ocmetricdata "go.opencensus.io/metric/metricdata"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
)
|
||||
|
||||
@ -52,7 +51,7 @@ func ConvertMetrics(ocmetrics []*ocmetricdata.Metric) ([]metricdata.Metrics, err
|
||||
otelMetrics = append(otelMetrics, metricdata.Metrics{
|
||||
Name: ocm.Descriptor.Name,
|
||||
Description: ocm.Descriptor.Description,
|
||||
Unit: convertUnit(ocm.Descriptor.Unit),
|
||||
Unit: string(ocm.Descriptor.Unit),
|
||||
Data: agg,
|
||||
})
|
||||
}
|
||||
@ -201,16 +200,3 @@ func convertAttrs(keys []ocmetricdata.LabelKey, values []ocmetricdata.LabelValue
|
||||
}
|
||||
return attribute.NewSet(attrs...), nil
|
||||
}
|
||||
|
||||
// convertUnit converts from the OpenCensus unit to OpenTelemetry unit.
|
||||
func convertUnit(u ocmetricdata.Unit) unit.Unit {
|
||||
switch u {
|
||||
case ocmetricdata.UnitDimensionless:
|
||||
return unit.Dimensionless
|
||||
case ocmetricdata.UnitBytes:
|
||||
return unit.Bytes
|
||||
case ocmetricdata.UnitMilliseconds:
|
||||
return unit.Milliseconds
|
||||
}
|
||||
return unit.Unit(string(u))
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
ocmetricdata "go.opencensus.io/metric/metricdata"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
|
||||
)
|
||||
@ -214,7 +213,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
{
|
||||
Name: "foo.com/histogram-a",
|
||||
Description: "a testing histogram",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Histogram{
|
||||
DataPoints: []metricdata.HistogramDataPoint{
|
||||
{
|
||||
@ -252,7 +251,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
}, {
|
||||
Name: "foo.com/gauge-a",
|
||||
Description: "an int testing gauge",
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Data: metricdata.Gauge[int64]{
|
||||
DataPoints: []metricdata.DataPoint[int64]{
|
||||
{
|
||||
@ -281,7 +280,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
}, {
|
||||
Name: "foo.com/gauge-b",
|
||||
Description: "a float testing gauge",
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Data: metricdata.Gauge[float64]{
|
||||
DataPoints: []metricdata.DataPoint[float64]{
|
||||
{
|
||||
@ -310,7 +309,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
}, {
|
||||
Name: "foo.com/sum-a",
|
||||
Description: "an int testing sum",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
Data: metricdata.Sum[int64]{
|
||||
IsMonotonic: true,
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
@ -341,7 +340,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
}, {
|
||||
Name: "foo.com/sum-b",
|
||||
Description: "a float testing sum",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
Data: metricdata.Sum[float64]{
|
||||
IsMonotonic: true,
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
@ -387,7 +386,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
{
|
||||
Name: "foo.com/histogram-a",
|
||||
Description: "a testing histogram",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Histogram{
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
DataPoints: []metricdata.HistogramDataPoint{},
|
||||
@ -410,7 +409,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
{
|
||||
Name: "foo.com/sum-a",
|
||||
Description: "a testing sum",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Sum[float64]{
|
||||
IsMonotonic: true,
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
@ -434,7 +433,7 @@ func TestConvertMetrics(t *testing.T) {
|
||||
{
|
||||
Name: "foo.com/gauge-a",
|
||||
Description: "a testing gauge",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Gauge[int64]{
|
||||
DataPoints: []metricdata.DataPoint[int64]{},
|
||||
},
|
||||
@ -580,38 +579,6 @@ func TestConvertMetrics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertUnits(t *testing.T) {
|
||||
var noUnit unit.Unit
|
||||
for _, tc := range []struct {
|
||||
desc string
|
||||
input ocmetricdata.Unit
|
||||
expected unit.Unit
|
||||
}{{
|
||||
desc: "unspecified unit",
|
||||
expected: noUnit,
|
||||
}, {
|
||||
desc: "dimensionless",
|
||||
input: ocmetricdata.UnitDimensionless,
|
||||
expected: unit.Dimensionless,
|
||||
}, {
|
||||
desc: "milliseconds",
|
||||
input: ocmetricdata.UnitMilliseconds,
|
||||
expected: unit.Milliseconds,
|
||||
}, {
|
||||
desc: "bytes",
|
||||
input: ocmetricdata.UnitBytes,
|
||||
expected: unit.Bytes,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
output := convertUnit(tc.input)
|
||||
if output != tc.expected {
|
||||
t.Errorf("convertUnit(%v) = %q, want %q", tc.input, output, tc.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertAttributes(t *testing.T) {
|
||||
setWithMultipleKeys := attribute.NewSet(
|
||||
attribute.KeyValue{Key: attribute.Key("first"), Value: attribute.StringValue("1")},
|
||||
|
@ -7,7 +7,6 @@ require (
|
||||
github.com/stretchr/testify v1.8.2
|
||||
go.opentelemetry.io/otel v1.13.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.13.0
|
||||
go.opentelemetry.io/otel/metric v0.36.0
|
||||
go.opentelemetry.io/otel/sdk v1.13.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.36.0
|
||||
go.opentelemetry.io/proto/otlp v0.19.0
|
||||
@ -23,6 +22,7 @@ require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.36.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.13.0 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
||||
collpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
cpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
@ -118,31 +117,31 @@ var (
|
||||
{
|
||||
Name: "int64-gauge",
|
||||
Description: "Gauge with int64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Gauge{Gauge: gaugeInt64},
|
||||
},
|
||||
{
|
||||
Name: "float64-gauge",
|
||||
Description: "Gauge with float64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Gauge{Gauge: gaugeFloat64},
|
||||
},
|
||||
{
|
||||
Name: "int64-sum",
|
||||
Description: "Sum with int64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Sum{Sum: sumInt64},
|
||||
},
|
||||
{
|
||||
Name: "float64-sum",
|
||||
Description: "Sum with float64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Sum{Sum: sumFloat64},
|
||||
},
|
||||
{
|
||||
Name: "histogram",
|
||||
Description: "Histogram",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Histogram{Histogram: hist},
|
||||
},
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -188,49 +187,49 @@ var (
|
||||
{
|
||||
Name: "int64-gauge",
|
||||
Description: "Gauge with int64 values",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelGaugeInt64,
|
||||
},
|
||||
{
|
||||
Name: "float64-gauge",
|
||||
Description: "Gauge with float64 values",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelGaugeFloat64,
|
||||
},
|
||||
{
|
||||
Name: "int64-sum",
|
||||
Description: "Sum with int64 values",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelSumInt64,
|
||||
},
|
||||
{
|
||||
Name: "float64-sum",
|
||||
Description: "Sum with float64 values",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelSumFloat64,
|
||||
},
|
||||
{
|
||||
Name: "invalid-sum",
|
||||
Description: "Sum with invalid temporality",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelSumInvalid,
|
||||
},
|
||||
{
|
||||
Name: "histogram",
|
||||
Description: "Histogram",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelHist,
|
||||
},
|
||||
{
|
||||
Name: "invalid-histogram",
|
||||
Description: "Invalid histogram",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: otelHistInvalid,
|
||||
},
|
||||
{
|
||||
Name: "unknown",
|
||||
Description: "Unknown aggregation",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: unknownAgg,
|
||||
},
|
||||
}
|
||||
@ -239,31 +238,31 @@ var (
|
||||
{
|
||||
Name: "int64-gauge",
|
||||
Description: "Gauge with int64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Gauge{Gauge: pbGaugeInt64},
|
||||
},
|
||||
{
|
||||
Name: "float64-gauge",
|
||||
Description: "Gauge with float64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Gauge{Gauge: pbGaugeFloat64},
|
||||
},
|
||||
{
|
||||
Name: "int64-sum",
|
||||
Description: "Sum with int64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Sum{Sum: pbSumInt64},
|
||||
},
|
||||
{
|
||||
Name: "float64-sum",
|
||||
Description: "Sum with float64 values",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Sum{Sum: pbSumFloat64},
|
||||
},
|
||||
{
|
||||
Name: "histogram",
|
||||
Description: "Histogram",
|
||||
Unit: string(unit.Dimensionless),
|
||||
Unit: "1",
|
||||
Data: &mpb.Metric_Histogram{Histogram: pbHist},
|
||||
},
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
@ -309,10 +308,10 @@ func sanitizeRune(r rune) rune {
|
||||
return '_'
|
||||
}
|
||||
|
||||
var unitSuffixes = map[unit.Unit]string{
|
||||
unit.Dimensionless: "_ratio",
|
||||
unit.Bytes: "_bytes",
|
||||
unit.Milliseconds: "_milliseconds",
|
||||
var unitSuffixes = map[string]string{
|
||||
"1": "_ratio",
|
||||
"By": "_bytes",
|
||||
"ms": "_milliseconds",
|
||||
}
|
||||
|
||||
// getName returns the sanitized name, including unit suffix.
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
otelmetric "go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -56,7 +55,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
counter, err := meter.Float64Counter(
|
||||
"foo",
|
||||
instrument.WithDescription("a simple counter"),
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
counter.Add(ctx, 5, attrs...)
|
||||
@ -83,7 +82,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
gauge, err := meter.Float64UpDownCounter(
|
||||
"bar",
|
||||
instrument.WithDescription("a fun little gauge"),
|
||||
instrument.WithUnit(unit.Dimensionless),
|
||||
instrument.WithUnit("1"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
gauge.Add(ctx, 1.0, attrs...)
|
||||
@ -101,7 +100,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
histogram, err := meter.Float64Histogram(
|
||||
"histogram_baz",
|
||||
instrument.WithDescription("a very nice histogram"),
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
histogram.Record(ctx, 23, attrs...)
|
||||
@ -128,7 +127,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
"foo",
|
||||
instrument.WithDescription("a sanitary counter"),
|
||||
// This unit is not added to
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
counter.Add(ctx, 5, attrs...)
|
||||
@ -233,7 +232,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
gauge, err := meter.Int64UpDownCounter(
|
||||
"bar",
|
||||
instrument.WithDescription("a fun little gauge"),
|
||||
instrument.WithUnit(unit.Dimensionless),
|
||||
instrument.WithUnit("1"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
gauge.Add(ctx, 2, attrs...)
|
||||
@ -252,7 +251,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
counter, err := meter.Int64Counter(
|
||||
"bar",
|
||||
instrument.WithDescription("a fun little counter"),
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
counter.Add(ctx, 2, attrs...)
|
||||
@ -366,7 +365,7 @@ func TestMultiScopes(t *testing.T) {
|
||||
fooCounter, err := provider.Meter("meterfoo", otelmetric.WithInstrumentationVersion("v0.1.0")).
|
||||
Int64Counter(
|
||||
"foo",
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
instrument.WithDescription("meter foo counter"))
|
||||
assert.NoError(t, err)
|
||||
fooCounter.Add(ctx, 100, attribute.String("type", "foo"))
|
||||
@ -374,7 +373,7 @@ func TestMultiScopes(t *testing.T) {
|
||||
barCounter, err := provider.Meter("meterbar", otelmetric.WithInstrumentationVersion("v0.1.0")).
|
||||
Int64Counter(
|
||||
"bar",
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
instrument.WithDescription("meter bar counter"))
|
||||
assert.NoError(t, err)
|
||||
barCounter.Add(ctx, 200, attribute.String("type", "bar"))
|
||||
@ -399,13 +398,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "no_conflict_two_counters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
fooA, err := meterA.Int64Counter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter counter foo"))
|
||||
assert.NoError(t, err)
|
||||
fooA.Add(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
fooB, err := meterB.Int64Counter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter counter foo"))
|
||||
assert.NoError(t, err)
|
||||
fooB.Add(ctx, 100, attribute.String("A", "B"))
|
||||
@ -416,13 +415,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "no_conflict_two_updowncounters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
fooA, err := meterA.Int64UpDownCounter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter gauge foo"))
|
||||
assert.NoError(t, err)
|
||||
fooA.Add(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
fooB, err := meterB.Int64UpDownCounter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter gauge foo"))
|
||||
assert.NoError(t, err)
|
||||
fooB.Add(ctx, 100, attribute.String("A", "B"))
|
||||
@ -433,13 +432,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "no_conflict_two_histograms",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
fooA, err := meterA.Int64Histogram("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter histogram foo"))
|
||||
assert.NoError(t, err)
|
||||
fooA.Record(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
fooB, err := meterB.Int64Histogram("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter histogram foo"))
|
||||
assert.NoError(t, err)
|
||||
fooB.Record(ctx, 100, attribute.String("A", "B"))
|
||||
@ -450,13 +449,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_help_two_counters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
barA, err := meterA.Int64Counter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter a bar"))
|
||||
assert.NoError(t, err)
|
||||
barA.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
|
||||
barB, err := meterB.Int64Counter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter b bar"))
|
||||
assert.NoError(t, err)
|
||||
barB.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
@ -470,13 +469,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_help_two_updowncounters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
barA, err := meterA.Int64UpDownCounter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter a bar"))
|
||||
assert.NoError(t, err)
|
||||
barA.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
|
||||
barB, err := meterB.Int64UpDownCounter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter b bar"))
|
||||
assert.NoError(t, err)
|
||||
barB.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
@ -490,13 +489,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_help_two_histograms",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
barA, err := meterA.Int64Histogram("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter a bar"))
|
||||
assert.NoError(t, err)
|
||||
barA.Record(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
barB, err := meterB.Int64Histogram("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter b bar"))
|
||||
assert.NoError(t, err)
|
||||
barB.Record(ctx, 100, attribute.String("A", "B"))
|
||||
@ -510,13 +509,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_unit_two_counters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
bazA, err := meterA.Int64Counter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter bar"))
|
||||
assert.NoError(t, err)
|
||||
bazA.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
|
||||
bazB, err := meterB.Int64Counter("bar",
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
instrument.WithDescription("meter bar"))
|
||||
assert.NoError(t, err)
|
||||
bazB.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
@ -528,13 +527,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_unit_two_updowncounters",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
barA, err := meterA.Int64UpDownCounter("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter gauge bar"))
|
||||
assert.NoError(t, err)
|
||||
barA.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
|
||||
barB, err := meterB.Int64UpDownCounter("bar",
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
instrument.WithDescription("meter gauge bar"))
|
||||
assert.NoError(t, err)
|
||||
barB.Add(ctx, 100, attribute.String("type", "bar"))
|
||||
@ -546,13 +545,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_unit_two_histograms",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
barA, err := meterA.Int64Histogram("bar",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter histogram bar"))
|
||||
assert.NoError(t, err)
|
||||
barA.Record(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
barB, err := meterB.Int64Histogram("bar",
|
||||
instrument.WithUnit(unit.Milliseconds),
|
||||
instrument.WithUnit("ms"),
|
||||
instrument.WithDescription("meter histogram bar"))
|
||||
assert.NoError(t, err)
|
||||
barB.Record(ctx, 100, attribute.String("A", "B"))
|
||||
@ -564,13 +563,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_type_counter_and_updowncounter",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
counter, err := meterA.Int64Counter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter foo"))
|
||||
assert.NoError(t, err)
|
||||
counter.Add(ctx, 100, attribute.String("type", "foo"))
|
||||
|
||||
gauge, err := meterA.Int64UpDownCounter("foo_total",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter foo"))
|
||||
assert.NoError(t, err)
|
||||
gauge.Add(ctx, 200, attribute.String("type", "foo"))
|
||||
@ -585,13 +584,13 @@ func TestDuplicateMetrics(t *testing.T) {
|
||||
name: "conflict_type_histogram_and_updowncounter",
|
||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
||||
fooA, err := meterA.Int64UpDownCounter("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter gauge foo"))
|
||||
assert.NoError(t, err)
|
||||
fooA.Add(ctx, 100, attribute.String("A", "B"))
|
||||
|
||||
fooHistogramA, err := meterA.Int64Histogram("foo",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithDescription("meter histogram foo"))
|
||||
assert.NoError(t, err)
|
||||
fooHistogramA.Record(ctx, 100, attribute.String("A", "B"))
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
@ -47,7 +46,7 @@ var (
|
||||
{
|
||||
Name: "requests",
|
||||
Description: "Number of requests received",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Sum[int64]{
|
||||
IsMonotonic: true,
|
||||
Temporality: metricdata.DeltaTemporality,
|
||||
@ -64,7 +63,7 @@ var (
|
||||
{
|
||||
Name: "latency",
|
||||
Description: "Time spend processing received requests",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
Data: metricdata.Histogram{
|
||||
Temporality: metricdata.DeltaTemporality,
|
||||
DataPoints: []metricdata.HistogramDataPoint{
|
||||
@ -83,7 +82,7 @@ var (
|
||||
{
|
||||
Name: "temperature",
|
||||
Description: "CPU global temperature",
|
||||
Unit: unit.Unit("cel(1 K)"),
|
||||
Unit: "cel(1 K)",
|
||||
Data: metricdata.Gauge[float64]{
|
||||
DataPoints: []metricdata.DataPoint[float64]{
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ go 1.18
|
||||
require (
|
||||
github.com/stretchr/testify v1.8.2
|
||||
go.opentelemetry.io/otel v1.13.0
|
||||
go.opentelemetry.io/otel/metric v0.36.0
|
||||
go.opentelemetry.io/otel/sdk v1.13.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.36.0
|
||||
)
|
||||
@ -15,6 +14,7 @@ require (
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.36.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.13.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
//nolint:govet // Meter doesn't register for go vet
|
||||
@ -33,7 +32,7 @@ func ExampleMeter_synchronous() {
|
||||
|
||||
workDuration, err := meterProvider.Meter("go.opentelemetry.io/otel/metric#SyncExample").Int64Histogram(
|
||||
"workDuration",
|
||||
instrument.WithUnit(unit.Milliseconds))
|
||||
instrument.WithUnit("ms"))
|
||||
if err != nil {
|
||||
fmt.Println("Failed to register instrument")
|
||||
panic(err)
|
||||
@ -54,7 +53,7 @@ func ExampleMeter_asynchronous_single() {
|
||||
|
||||
_, err := meter.Int64ObservableGauge(
|
||||
"DiskUsage",
|
||||
instrument.WithUnit(unit.Bytes),
|
||||
instrument.WithUnit("By"),
|
||||
instrument.WithInt64Callback(func(_ context.Context, obsrv instrument.Int64Observer) error {
|
||||
// Do the real work here to get the real disk usage. For example,
|
||||
//
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
// Float64Observable describes a set of instruments used asynchronously to
|
||||
@ -82,7 +81,7 @@ type Float64Callback func(context.Context, Float64Observer) error
|
||||
// observe float64 values.
|
||||
type Float64ObserverConfig struct {
|
||||
description string
|
||||
unit unit.Unit
|
||||
unit string
|
||||
callbacks []Float64Callback
|
||||
}
|
||||
|
||||
@ -102,7 +101,7 @@ func (c Float64ObserverConfig) Description() string {
|
||||
}
|
||||
|
||||
// Unit returns the Config unit.
|
||||
func (c Float64ObserverConfig) Unit() unit.Unit {
|
||||
func (c Float64ObserverConfig) Unit() string {
|
||||
return c.unit
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,13 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
func TestFloat64ObserverOptions(t *testing.T) {
|
||||
const (
|
||||
token float64 = 43
|
||||
desc = "Instrument description."
|
||||
uBytes = unit.Bytes
|
||||
uBytes = "By"
|
||||
)
|
||||
|
||||
got := NewFloat64ObserverConfig(
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
// Int64Observable describes a set of instruments used asynchronously to record
|
||||
@ -82,7 +81,7 @@ type Int64Callback func(context.Context, Int64Observer) error
|
||||
// observe int64 values.
|
||||
type Int64ObserverConfig struct {
|
||||
description string
|
||||
unit unit.Unit
|
||||
unit string
|
||||
callbacks []Int64Callback
|
||||
}
|
||||
|
||||
@ -102,7 +101,7 @@ func (c Int64ObserverConfig) Description() string {
|
||||
}
|
||||
|
||||
// Unit returns the Config unit.
|
||||
func (c Int64ObserverConfig) Unit() unit.Unit {
|
||||
func (c Int64ObserverConfig) Unit() string {
|
||||
return c.unit
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,13 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
func TestInt64ObserverOptions(t *testing.T) {
|
||||
const (
|
||||
token int64 = 43
|
||||
desc = "Instrument description."
|
||||
uBytes = unit.Bytes
|
||||
uBytes = "By"
|
||||
)
|
||||
|
||||
got := NewInt64ObserverConfig(
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
package instrument // import "go.opentelemetry.io/otel/metric/instrument"
|
||||
|
||||
import "go.opentelemetry.io/otel/metric/unit"
|
||||
|
||||
// Asynchronous instruments are instruments that are updated within a Callback.
|
||||
// If an instrument is observed outside of it's callback it should be an error.
|
||||
//
|
||||
@ -64,27 +62,27 @@ func (o descOpt) applyInt64Observer(c Int64ObserverConfig) Int64ObserverConfig {
|
||||
// WithDescription sets the instrument description.
|
||||
func WithDescription(desc string) Option { return descOpt(desc) }
|
||||
|
||||
type unitOpt unit.Unit
|
||||
type unitOpt string
|
||||
|
||||
func (o unitOpt) applyFloat64(c Float64Config) Float64Config {
|
||||
c.unit = unit.Unit(o)
|
||||
c.unit = string(o)
|
||||
return c
|
||||
}
|
||||
|
||||
func (o unitOpt) applyInt64(c Int64Config) Int64Config {
|
||||
c.unit = unit.Unit(o)
|
||||
c.unit = string(o)
|
||||
return c
|
||||
}
|
||||
|
||||
func (o unitOpt) applyFloat64Observer(c Float64ObserverConfig) Float64ObserverConfig {
|
||||
c.unit = unit.Unit(o)
|
||||
c.unit = string(o)
|
||||
return c
|
||||
}
|
||||
|
||||
func (o unitOpt) applyInt64Observer(c Int64ObserverConfig) Int64ObserverConfig {
|
||||
c.unit = unit.Unit(o)
|
||||
c.unit = string(o)
|
||||
return c
|
||||
}
|
||||
|
||||
// WithUnit sets the instrument unit.
|
||||
func WithUnit(u unit.Unit) Option { return unitOpt(u) }
|
||||
func WithUnit(u string) Option { return unitOpt(u) }
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
// Float64Counter is an instrument that records increasing float64 values.
|
||||
@ -57,7 +56,7 @@ type Float64Histogram interface {
|
||||
// observe float64 values.
|
||||
type Float64Config struct {
|
||||
description string
|
||||
unit unit.Unit
|
||||
unit string
|
||||
}
|
||||
|
||||
// Float64Config contains options for Synchronous instruments that record
|
||||
@ -76,7 +75,7 @@ func (c Float64Config) Description() string {
|
||||
}
|
||||
|
||||
// Unit returns the Config unit.
|
||||
func (c Float64Config) Unit() unit.Unit {
|
||||
func (c Float64Config) Unit() string {
|
||||
return c.unit
|
||||
}
|
||||
|
||||
|
@ -18,15 +18,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
func TestFloat64Options(t *testing.T) {
|
||||
const (
|
||||
token float64 = 43
|
||||
desc = "Instrument description."
|
||||
uBytes = unit.Bytes
|
||||
uBytes = "By"
|
||||
)
|
||||
|
||||
got := NewFloat64Config(WithDescription(desc), WithUnit(uBytes))
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
// Int64Counter is an instrument that records increasing int64 values.
|
||||
@ -57,7 +56,7 @@ type Int64Histogram interface {
|
||||
// values.
|
||||
type Int64Config struct {
|
||||
description string
|
||||
unit unit.Unit
|
||||
unit string
|
||||
}
|
||||
|
||||
// NewInt64Config returns a new Int64Config with all opts
|
||||
@ -76,7 +75,7 @@ func (c Int64Config) Description() string {
|
||||
}
|
||||
|
||||
// Unit returns the Config unit.
|
||||
func (c Int64Config) Unit() unit.Unit {
|
||||
func (c Int64Config) Unit() string {
|
||||
return c.unit
|
||||
}
|
||||
|
||||
|
@ -18,15 +18,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
)
|
||||
|
||||
func TestInt64Options(t *testing.T) {
|
||||
const (
|
||||
token int64 = 43
|
||||
desc = "Instrument description."
|
||||
uBytes = unit.Bytes
|
||||
uBytes = "By"
|
||||
)
|
||||
|
||||
got := NewInt64Config(WithDescription(desc), WithUnit(uBytes))
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
// Package unit provides units.
|
||||
//
|
||||
// This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
// may be introduced in subsequent minor version releases as we work to track
|
||||
// the evolving OpenTelemetry specification and user feedback.
|
||||
// Deprecated: This package will be removed in the next release. Use the
|
||||
// equivalent unit string instead.
|
||||
package unit // import "go.opentelemetry.io/otel/metric/unit"
|
||||
|
@ -15,6 +15,8 @@
|
||||
package unit // import "go.opentelemetry.io/otel/metric/unit"
|
||||
|
||||
// Unit is a determinate standard quantity of measurement.
|
||||
//
|
||||
// Deprecated: This will be removed in the next release.
|
||||
type Unit string
|
||||
|
||||
// Units defined by OpenTelemetry.
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/internal"
|
||||
@ -29,7 +28,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
zeroUnit unit.Unit
|
||||
zeroInstrumentKind InstrumentKind
|
||||
zeroScope instrumentation.Scope
|
||||
)
|
||||
@ -76,7 +74,7 @@ type Instrument struct {
|
||||
// Kind defines the functional group of the instrument.
|
||||
Kind InstrumentKind
|
||||
// Unit is the unit of measurement recorded by the instrument.
|
||||
Unit unit.Unit
|
||||
Unit string
|
||||
// Scope identifies the instrumentation that created the instrument.
|
||||
Scope instrumentation.Scope
|
||||
|
||||
@ -89,7 +87,7 @@ func (i Instrument) empty() bool {
|
||||
return i.Name == "" &&
|
||||
i.Description == "" &&
|
||||
i.Kind == zeroInstrumentKind &&
|
||||
i.Unit == zeroUnit &&
|
||||
i.Unit == "" &&
|
||||
i.Scope == zeroScope
|
||||
}
|
||||
|
||||
@ -125,7 +123,7 @@ func (i Instrument) matchesKind(other Instrument) bool {
|
||||
// matchesUnit returns true if the Unit of i is its zero-value or it equals the
|
||||
// Unit of other, otherwise false.
|
||||
func (i Instrument) matchesUnit(other Instrument) bool {
|
||||
return i.Unit == zeroUnit || i.Unit == other.Unit
|
||||
return i.Unit == "" || i.Unit == other.Unit
|
||||
}
|
||||
|
||||
// matchesScope returns true if the Scope of i is its zero-value or it equals
|
||||
@ -143,7 +141,7 @@ type Stream struct {
|
||||
// Description describes the purpose of the data.
|
||||
Description string
|
||||
// Unit is the unit of measurement recorded.
|
||||
Unit unit.Unit
|
||||
Unit string
|
||||
// Aggregation the stream uses for an instrument.
|
||||
Aggregation aggregation.Aggregation
|
||||
// AttributeFilter applied to all attributes recorded for an instrument.
|
||||
@ -157,7 +155,7 @@ type streamID struct {
|
||||
// Description is the description of the stream.
|
||||
Description string
|
||||
// Unit is the unit of the stream.
|
||||
Unit unit.Unit
|
||||
Unit string
|
||||
// Aggregation is the aggregation data type of the stream.
|
||||
Aggregation string
|
||||
// Monotonic is the monotonicity of an instruments data type. This field is
|
||||
@ -206,7 +204,7 @@ type observablID[N int64 | float64] struct {
|
||||
name string
|
||||
description string
|
||||
kind InstrumentKind
|
||||
unit unit.Unit
|
||||
unit string
|
||||
scope instrumentation.Scope
|
||||
}
|
||||
|
||||
@ -219,7 +217,7 @@ var _ instrument.Float64ObservableCounter = float64Observable{}
|
||||
var _ instrument.Float64ObservableUpDownCounter = float64Observable{}
|
||||
var _ instrument.Float64ObservableGauge = float64Observable{}
|
||||
|
||||
func newFloat64Observable(scope instrumentation.Scope, kind InstrumentKind, name, desc string, u unit.Unit, agg []internal.Aggregator[float64]) float64Observable {
|
||||
func newFloat64Observable(scope instrumentation.Scope, kind InstrumentKind, name, desc, u string, agg []internal.Aggregator[float64]) float64Observable {
|
||||
return float64Observable{
|
||||
observable: newObservable[float64](scope, kind, name, desc, u, agg),
|
||||
}
|
||||
@ -234,7 +232,7 @@ var _ instrument.Int64ObservableCounter = int64Observable{}
|
||||
var _ instrument.Int64ObservableUpDownCounter = int64Observable{}
|
||||
var _ instrument.Int64ObservableGauge = int64Observable{}
|
||||
|
||||
func newInt64Observable(scope instrumentation.Scope, kind InstrumentKind, name, desc string, u unit.Unit, agg []internal.Aggregator[int64]) int64Observable {
|
||||
func newInt64Observable(scope instrumentation.Scope, kind InstrumentKind, name, desc, u string, agg []internal.Aggregator[int64]) int64Observable {
|
||||
return int64Observable{
|
||||
observable: newObservable[int64](scope, kind, name, desc, u, agg),
|
||||
}
|
||||
@ -247,7 +245,7 @@ type observable[N int64 | float64] struct {
|
||||
aggregators []internal.Aggregator[N]
|
||||
}
|
||||
|
||||
func newObservable[N int64 | float64](scope instrumentation.Scope, kind InstrumentKind, name, desc string, u unit.Unit, agg []internal.Aggregator[N]) *observable[N] {
|
||||
func newObservable[N int64 | float64](scope instrumentation.Scope, kind InstrumentKind, name, desc, u string, agg []internal.Aggregator[N]) *observable[N] {
|
||||
return &observable[N]{
|
||||
observablID: observablID[N]{
|
||||
name: name,
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/internal"
|
||||
)
|
||||
@ -374,7 +373,7 @@ func newInstProvider[N int64 | float64](s instrumentation.Scope, p pipelines, c
|
||||
return &instProvider[N]{scope: s, pipes: p, resolve: newResolver[N](p, c)}
|
||||
}
|
||||
|
||||
func (p *instProvider[N]) aggs(kind InstrumentKind, name, desc string, u unit.Unit) ([]internal.Aggregator[N], error) {
|
||||
func (p *instProvider[N]) aggs(kind InstrumentKind, name, desc, u string) ([]internal.Aggregator[N], error) {
|
||||
inst := Instrument{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
@ -386,14 +385,14 @@ func (p *instProvider[N]) aggs(kind InstrumentKind, name, desc string, u unit.Un
|
||||
}
|
||||
|
||||
// lookup returns the resolved instrumentImpl.
|
||||
func (p *instProvider[N]) lookup(kind InstrumentKind, name, desc string, u unit.Unit) (*instrumentImpl[N], error) {
|
||||
func (p *instProvider[N]) lookup(kind InstrumentKind, name, desc, u string) (*instrumentImpl[N], error) {
|
||||
aggs, err := p.aggs(kind, name, desc, u)
|
||||
return &instrumentImpl[N]{aggregators: aggs}, err
|
||||
}
|
||||
|
||||
type int64ObservProvider struct{ *instProvider[int64] }
|
||||
|
||||
func (p int64ObservProvider) lookup(kind InstrumentKind, name, desc string, u unit.Unit) (int64Observable, error) {
|
||||
func (p int64ObservProvider) lookup(kind InstrumentKind, name, desc, u string) (int64Observable, error) {
|
||||
aggs, err := p.aggs(kind, name, desc, u)
|
||||
return newInt64Observable(p.scope, kind, name, desc, u, aggs), err
|
||||
}
|
||||
@ -424,7 +423,7 @@ func (o int64Observer) Observe(val int64, attrs ...attribute.KeyValue) {
|
||||
|
||||
type float64ObservProvider struct{ *instProvider[float64] }
|
||||
|
||||
func (p float64ObservProvider) lookup(kind InstrumentKind, name, desc string, u unit.Unit) (float64Observable, error) {
|
||||
func (p float64ObservProvider) lookup(kind InstrumentKind, name, desc, u string) (float64Observable, error) {
|
||||
aggs, err := p.aggs(kind, name, desc, u)
|
||||
return newFloat64Observable(p.scope, kind, name, desc, u, aggs), err
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
@ -47,7 +46,7 @@ type Metrics struct {
|
||||
// Description is the description of the Instrument, which can be used in documentation.
|
||||
Description string
|
||||
// Unit is the unit in which the Instrument reports.
|
||||
Unit unit.Unit
|
||||
Unit string
|
||||
// Data is the aggregated data from an Instrument.
|
||||
Data Aggregation
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -175,19 +174,19 @@ var (
|
||||
metricsA = metricdata.Metrics{
|
||||
Name: "A",
|
||||
Description: "A desc",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: sumInt64A,
|
||||
}
|
||||
metricsB = metricdata.Metrics{
|
||||
Name: "B",
|
||||
Description: "B desc",
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Data: gaugeFloat64B,
|
||||
}
|
||||
metricsC = metricdata.Metrics{
|
||||
Name: "A",
|
||||
Description: "A desc",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: sumInt64C,
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/internal"
|
||||
@ -48,7 +47,7 @@ type aggregator interface {
|
||||
type instrumentSync struct {
|
||||
name string
|
||||
description string
|
||||
unit unit.Unit
|
||||
unit string
|
||||
aggregator aggregator
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
|
||||
@ -48,7 +47,7 @@ func TestEmptyPipeline(t *testing.T) {
|
||||
assert.Nil(t, output.Resource)
|
||||
assert.Len(t, output.ScopeMetrics, 0)
|
||||
|
||||
iSync := instrumentSync{"name", "desc", unit.Dimensionless, testSumAggregator{}}
|
||||
iSync := instrumentSync{"name", "desc", "1", testSumAggregator{}}
|
||||
assert.NotPanics(t, func() {
|
||||
pipe.addSync(instrumentation.Scope{}, iSync)
|
||||
})
|
||||
@ -72,7 +71,7 @@ func TestNewPipeline(t *testing.T) {
|
||||
assert.Equal(t, resource.Empty(), output.Resource)
|
||||
assert.Len(t, output.ScopeMetrics, 0)
|
||||
|
||||
iSync := instrumentSync{"name", "desc", unit.Dimensionless, testSumAggregator{}}
|
||||
iSync := instrumentSync{"name", "desc", "1", testSumAggregator{}}
|
||||
assert.NotPanics(t, func() {
|
||||
pipe.addSync(instrumentation.Scope{}, iSync)
|
||||
})
|
||||
@ -114,7 +113,7 @@ func TestPipelineConcurrency(t *testing.T) {
|
||||
go func(n int) {
|
||||
defer wg.Done()
|
||||
name := fmt.Sprintf("name %d", n)
|
||||
sync := instrumentSync{name, "desc", unit.Dimensionless, testSumAggregator{}}
|
||||
sync := instrumentSync{name, "desc", "1", testSumAggregator{}}
|
||||
pipe.addSync(instrumentation.Scope{}, sync)
|
||||
}(i)
|
||||
|
||||
@ -137,7 +136,7 @@ func testDefaultViewImplicit[N int64 | float64]() func(t *testing.T) {
|
||||
Name: "requests",
|
||||
Description: "count of requests received",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
}
|
||||
return func(t *testing.T) {
|
||||
reader := NewManualReader()
|
||||
@ -176,7 +175,7 @@ func testDefaultViewImplicit[N int64 | float64]() func(t *testing.T) {
|
||||
metricdatatest.AssertEqual(t, metricdata.Metrics{
|
||||
Name: inst.Name,
|
||||
Description: inst.Description,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Sum[N]{
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
IsMonotonic: true,
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -211,7 +210,7 @@ var testScopeMetricsA = metricdata.ScopeMetrics{
|
||||
Metrics: []metricdata.Metrics{{
|
||||
Name: "fake data",
|
||||
Description: "Data used to test a reader",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Data: metricdata.Sum[int64]{
|
||||
Temporality: metricdata.CumulativeTemporality,
|
||||
IsMonotonic: true,
|
||||
@ -230,7 +229,7 @@ var testScopeMetricsB = metricdata.ScopeMetrics{
|
||||
Metrics: []metricdata.Metrics{{
|
||||
Name: "fake scope data",
|
||||
Description: "Data used to test a Producer reader",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
Data: metricdata.Gauge[int64]{
|
||||
DataPoints: []metricdata.DataPoint[int64]{{
|
||||
Attributes: attribute.NewSet(attribute.String("user", "ben")),
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/unit"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
)
|
||||
@ -37,7 +36,7 @@ var (
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: instrumentation.Scope{
|
||||
Name: "TestNewViewMatch",
|
||||
Version: "v0.1.0",
|
||||
@ -206,12 +205,12 @@ func TestNewViewMatch(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Unit",
|
||||
criteria: Instrument{Unit: unit.Bytes},
|
||||
matches: []Instrument{{Unit: unit.Bytes}, completeIP},
|
||||
criteria: Instrument{Unit: "By"},
|
||||
matches: []Instrument{{Unit: "By"}, completeIP},
|
||||
notMatches: []Instrument{
|
||||
{},
|
||||
{Unit: unit.Dimensionless},
|
||||
{Unit: unit.Unit("K")},
|
||||
{Unit: "1"},
|
||||
{Unit: "K"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -278,49 +277,49 @@ func TestNewViewMatch(t *testing.T) {
|
||||
Name: "Wrong Name",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("TestNewViewMatch", "v0.1.0", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "Wrong Description",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("TestNewViewMatch", "v0.1.0", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindObservableUpDownCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("TestNewViewMatch", "v0.1.0", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Scope: scope("TestNewViewMatch", "v0.1.0", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("Wrong Scope Name", "v0.1.0", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("TestNewViewMatch", "v1.4.3", schemaURL),
|
||||
},
|
||||
{
|
||||
Name: "foo",
|
||||
Description: "foo desc",
|
||||
Kind: InstrumentKindCounter,
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
Scope: scope("TestNewViewMatch", "v0.1.0", "https://go.dev"),
|
||||
},
|
||||
},
|
||||
@ -384,12 +383,12 @@ func TestNewViewReplace(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Unit",
|
||||
mask: Stream{Unit: unit.Dimensionless},
|
||||
mask: Stream{Unit: "1"},
|
||||
want: func(i Instrument) Stream {
|
||||
return Stream{
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -410,14 +409,14 @@ func TestNewViewReplace(t *testing.T) {
|
||||
mask: Stream{
|
||||
Name: alt,
|
||||
Description: alt,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Aggregation: aggregation.LastValue{},
|
||||
},
|
||||
want: func(i Instrument) Stream {
|
||||
return Stream{
|
||||
Name: alt,
|
||||
Description: alt,
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
Aggregation: aggregation.LastValue{},
|
||||
}
|
||||
},
|
||||
@ -490,7 +489,7 @@ func ExampleNewView() {
|
||||
stream, _ := view(Instrument{
|
||||
Name: "latency",
|
||||
Description: "request latency",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
Kind: InstrumentKindCounter,
|
||||
Scope: instrumentation.Scope{
|
||||
Name: "http",
|
||||
@ -537,7 +536,7 @@ func ExampleNewView_wildcard() {
|
||||
// name suffix of ".ms".
|
||||
view := NewView(
|
||||
Instrument{Name: "*.ms"},
|
||||
Stream{Unit: unit.Milliseconds},
|
||||
Stream{Unit: "ms"},
|
||||
)
|
||||
|
||||
// The created view can then be registered with the OpenTelemetry metric
|
||||
@ -546,7 +545,7 @@ func ExampleNewView_wildcard() {
|
||||
|
||||
stream, _ := view(Instrument{
|
||||
Name: "computation.time.ms",
|
||||
Unit: unit.Dimensionless,
|
||||
Unit: "1",
|
||||
})
|
||||
fmt.Println("name:", stream.Name)
|
||||
fmt.Println("unit:", stream.Unit)
|
||||
@ -573,9 +572,9 @@ func ExampleView() {
|
||||
return s, false
|
||||
}
|
||||
switch i.Unit {
|
||||
case unit.Milliseconds:
|
||||
case "ms":
|
||||
s.Name += ".ms"
|
||||
case unit.Bytes:
|
||||
case "By":
|
||||
s.Name += ".byte"
|
||||
default:
|
||||
return s, false
|
||||
@ -589,13 +588,13 @@ func ExampleView() {
|
||||
|
||||
stream, _ := view(Instrument{
|
||||
Name: "computation.time.ms",
|
||||
Unit: unit.Milliseconds,
|
||||
Unit: "ms",
|
||||
})
|
||||
fmt.Println("name:", stream.Name)
|
||||
|
||||
stream, _ = view(Instrument{
|
||||
Name: "heap.size",
|
||||
Unit: unit.Bytes,
|
||||
Unit: "By",
|
||||
})
|
||||
fmt.Println("name:", stream.Name)
|
||||
// Output:
|
||||
|
Loading…
Reference in New Issue
Block a user