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

[exporter/datadog] Add telemetry metric for runtime metrics #23138

Merged
15 changes: 10 additions & 5 deletions exporter/datadogexporter/internal/metrics/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,33 @@ func (c *Consumer) toDataType(dt metrics.DataType) (out datadogV2.MetricIntakeTy
}

// runningMetrics gets the running metrics for the exporter.
func (c *Consumer) runningMetrics(timestamp uint64, buildInfo component.BuildInfo) (series []datadogV2.MetricSeries) {
func (c *Consumer) runningMetrics(timestamp uint64, buildInfo component.BuildInfo, metadata metrics.RuntimeMetricsTelemetry) (series []datadogV2.MetricSeries) {
for host := range c.seenHosts {
// Report the host as running
runningMetric := DefaultMetrics("metrics", host, timestamp, buildInfo)
runningMetric := DefaultMetrics("metrics", host, timestamp, buildInfo, "")
series = append(series, runningMetric...)
}

for tag := range c.seenTags {
runningMetrics := DefaultMetrics("metrics", "", timestamp, buildInfo)
runningMetrics := DefaultMetrics("metrics", "", timestamp, buildInfo, "")
liustanley marked this conversation as resolved.
Show resolved Hide resolved
for i := range runningMetrics {
runningMetrics[i].Tags = append(runningMetrics[i].Tags, tag)
}
series = append(series, runningMetrics...)
}

for _, lang := range metadata.LanguageTags {
runningMetric := DefaultMetrics("runtime_metrics", "", timestamp, buildInfo, lang)
series = append(series, runningMetric...)
}

return
}

// All gets all metrics (consumed metrics and running metrics).
func (c *Consumer) All(timestamp uint64, buildInfo component.BuildInfo, tags []string) ([]datadogV2.MetricSeries, sketches.SketchSeriesList, []pb.ClientStatsPayload) {
func (c *Consumer) All(timestamp uint64, buildInfo component.BuildInfo, tags []string, metadata metrics.RuntimeMetricsTelemetry) ([]datadogV2.MetricSeries, sketches.SketchSeriesList, []pb.ClientStatsPayload) {
series := c.ms
series = append(series, c.runningMetrics(timestamp, buildInfo)...)
series = append(series, c.runningMetrics(timestamp, buildInfo, metadata)...)
if len(tags) == 0 {
return series, c.sl, c.as
}
Expand Down
5 changes: 4 additions & 1 deletion exporter/datadogexporter/internal/metrics/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ func NewCount(name string, ts uint64, value float64, tags []string) datadogV2.Me
}

// DefaultMetrics creates built-in metrics to report that an exporter is running
func DefaultMetrics(exporterType string, hostname string, timestamp uint64, buildInfo component.BuildInfo) []datadogV2.MetricSeries {
func DefaultMetrics(exporterType string, hostname string, timestamp uint64, buildInfo component.BuildInfo, language string) []datadogV2.MetricSeries {
var tags []string
if buildInfo.Version != "" {
tags = append(tags, "version:"+buildInfo.Version)
}
if buildInfo.Command != "" {
tags = append(tags, "command:"+buildInfo.Command)
}
if language != "" {
tags = append(tags, "language:"+language)
}
metrics := []datadogV2.MetricSeries{
NewGauge(fmt.Sprintf("otel.datadog_exporter.%s.running", exporterType), timestamp, 1.0, tags),
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr
} else {
consumer = metrics.NewZorkianConsumer()
}
_, err := exp.tr.MapMetrics(ctx, md, consumer)
metadata, err := exp.tr.MapMetrics(ctx, md, consumer)
if err != nil {
return fmt.Errorf("failed to map metrics: %w", err)
}
Expand All @@ -203,7 +203,7 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr
var sp []pb.ClientStatsPayload
if isMetricExportV2Enabled() {
var ms []datadogV2.MetricSeries
ms, sl, sp = consumer.(*metrics.Consumer).All(exp.getPushTime(), exp.params.BuildInfo, tags)
ms, sl, sp = consumer.(*metrics.Consumer).All(exp.getPushTime(), exp.params.BuildInfo, tags, metadata)
ms = metrics.PrepareSystemMetrics(ms)
ms = metrics.PrepareContainerMetrics(ms)

Expand Down
4 changes: 2 additions & 2 deletions exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func (exp *traceExporter) exportUsageMetrics(ctx context.Context, hosts map[stri
if isMetricExportV2Enabled() {
series := make([]datadogV2.MetricSeries, 0, len(hosts)+len(tags))
for host := range hosts {
series = append(series, metrics.DefaultMetrics("traces", host, uint64(now), exp.params.BuildInfo)...)
series = append(series, metrics.DefaultMetrics("traces", host, uint64(now), exp.params.BuildInfo, "")...)
}
for tag := range tags {
ms := metrics.DefaultMetrics("traces", "", uint64(now), exp.params.BuildInfo)
ms := metrics.DefaultMetrics("traces", "", uint64(now), exp.params.BuildInfo, "")
for i := range ms {
ms[i].Tags = append(ms[i].Tags, tag)
}
Expand Down