diff --git a/cmd/telemetrygen/internal/metrics/metrics.go b/cmd/telemetrygen/internal/metrics/metrics.go index 6418f7228a95..e39ceaba6e7b 100644 --- a/cmd/telemetrygen/internal/metrics/metrics.go +++ b/cmd/telemetrygen/internal/metrics/metrics.go @@ -112,7 +112,7 @@ func Run(c *Config, exp sdkmetric.Exporter, logger *zap.Logger) error { index: i, } - go w.simulateMetrics(res, exp) + go w.simulateMetrics(res, exp, c.GetAttributes()) } if c.TotalDuration > 0 { time.Sleep(c.TotalDuration) diff --git a/cmd/telemetrygen/internal/metrics/worker.go b/cmd/telemetrygen/internal/metrics/worker.go index 6056cc5eb4ab..75c89f259e85 100644 --- a/cmd/telemetrygen/internal/metrics/worker.go +++ b/cmd/telemetrygen/internal/metrics/worker.go @@ -9,6 +9,7 @@ import ( "sync/atomic" "time" + "go.opentelemetry.io/otel/attribute" sdkmetric "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/resource" @@ -26,9 +27,12 @@ type worker struct { index int // worker index } -func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Exporter) { +func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Exporter, attributes []attribute.KeyValue) { limiter := rate.NewLimiter(w.limitPerSecond, 1) + var i int64 + value := 24.42 + attrs := attribute.NewSet(attributes...) for w.running.Load() { rm := metricdata.ResourceMetrics{ @@ -37,12 +41,43 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor { Metrics: []metricdata.Metrics{ { - Name: "gen", + Name: "gen.metric.gauge", Data: metricdata.Gauge[int64]{ DataPoints: []metricdata.DataPoint[int64]{ { - Time: time.Now(), - Value: i, + Attributes: attrs, + Time: time.Now(), + Value: i, + }, + }, + }, + }, + { + Name: "gen.metric.sum", + Data: metricdata.Sum[int64]{ + IsMonotonic: true, + Temporality: metricdata.DeltaTemporality, + DataPoints: []metricdata.DataPoint[int64]{ + { + Attributes: attrs, + StartTime: time.Now(), + Time: time.Now().Add(1 * time.Second), + Value: i, + }, + }, + }, + }, + { + Name: "gen.metric.histogram", + Data: metricdata.Histogram[float64]{ + Temporality: metricdata.CumulativeTemporality, + DataPoints: []metricdata.HistogramDataPoint[float64]{ + { + Attributes: attrs, + Sum: float64(float32(value)), + Max: metricdata.NewExtrema(float64(float32(value))), + Min: metricdata.NewExtrema(float64(float32(value))), + Count: 1, }, }, }, @@ -51,6 +86,7 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor }, }, } + if err := exporter.Export(context.Background(), &rm); err != nil { w.logger.Fatal("exporter failed", zap.Error(err)) }