diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1ab343db61..5dc6e3e68c58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ Main (unreleased) - Allow converting labels to structured metadata with Loki's structured_metadata stage. (@gonzalesraul) +- Added new config options to spanmetrics processor in static mode (@ptodev): + - `aggregation_temporality`: configures whether to reset the metrics after flushing. + - `metrics_flush_interval`: configures how often to flush generated metrics. + ### Other changes - Use Go 1.21.3 for builds. (@tpaschalis) diff --git a/docs/sources/static/configuration/traces-config.md b/docs/sources/static/configuration/traces-config.md index dbd27dc34245..6e8537a2c0a2 100644 --- a/docs/sources/static/configuration/traces-config.md +++ b/docs/sources/static/configuration/traces-config.md @@ -157,7 +157,7 @@ remote_write: automatic_logging: # Indicates where the stream of log lines should go. Either supports writing # to a logs instance defined in this same config or to stdout. - [ backend: | default = "stdout" | supported "stdout", "logs_instance" ] + [ backend: | default = "stdout" | supported = "stdout", "logs_instance" ] # Indicates the logs instance to write logs to. # Required if backend is set to logs_instance. [ logs_instance_name: ] @@ -264,8 +264,13 @@ spanmetrics: [ metrics_instance: ] # handler_endpoint defines the endpoint where the OTel prometheus exporter will be exposed. [ handler_endpoint: ] - # dimensions_cache_size defines the size of cache for storing Dimensions - [ dimensions_cache_size: ] + # dimensions_cache_size defines the size of cache for storing Dimensions. + [ dimensions_cache_size: | default = 1000 ] + # aggregation_temporality configures whether to reset the metrics after flushing. + # It can be either AGGREGATION_TEMPORALITY_CUMULATIVE or AGGREGATION_TEMPORALITY_DELTA. + [ aggregation_temporality: | default = "AGGREGATION_TEMPORALITY_CUMULATIVE" ] + # metrics_flush_interval configures how often to flush generated metrics. + [ metrics_flush_interval: | default = 15s ] # tail_sampling supports tail-based sampling of traces in the agent. # diff --git a/pkg/traces/config.go b/pkg/traces/config.go index dbd6e28a9a44..4bb6776b6f25 100644 --- a/pkg/traces/config.go +++ b/pkg/traces/config.go @@ -365,6 +365,15 @@ type SpanMetricsConfig struct { // DimensionsCacheSize defines the size of cache for storing Dimensions, which helps to avoid cache memory growing // indefinitely over the lifetime of the collector. DimensionsCacheSize int `yaml:"dimensions_cache_size"` + + // Defines the aggregation temporality of the generated metrics. Can be either of: + // * "AGGREGATION_TEMPORALITY_CUMULATIVE" + // * "AGGREGATION_TEMPORALITY_DELTA" + AggregationTemporality string `yaml:"aggregation_temporality"` + + // MetricsEmitInterval is the time period between when metrics are flushed + // or emitted to the configured MetricsExporter. + MetricsFlushInterval time.Duration `yaml:"metrics_flush_interval"` } // tailSamplingConfig is the configuration for tail-based sampling @@ -739,6 +748,12 @@ func (c *InstanceConfig) otelConfig() (*otelcol.Config, error) { "latency_histogram_buckets": c.SpanMetrics.LatencyHistogramBuckets, "dimensions": c.SpanMetrics.Dimensions, } + if c.SpanMetrics.AggregationTemporality != "" { + spanMetrics["aggregation_temporality"] = c.SpanMetrics.AggregationTemporality + } + if c.SpanMetrics.MetricsFlushInterval != 0 { + spanMetrics["metrics_flush_interval"] = c.SpanMetrics.MetricsFlushInterval + } if c.SpanMetrics.DimensionsCacheSize != 0 { spanMetrics["dimensions_cache_size"] = c.SpanMetrics.DimensionsCacheSize } diff --git a/pkg/traces/config_test.go b/pkg/traces/config_test.go index 89157f809ba7..80edb01b82f5 100644 --- a/pkg/traces/config_test.go +++ b/pkg/traces/config_test.go @@ -546,6 +546,8 @@ spanmetrics: - name: http.status_code metrics_instance: traces dimensions_cache_size: 10000 + aggregation_temporality: AGGREGATION_TEMPORALITY_DELTA + metrics_flush_interval: 20s `, expectedConfig: ` receivers: @@ -572,6 +574,8 @@ processors: default: GET - name: http.status_code dimensions_cache_size: 10000 + aggregation_temporality: AGGREGATION_TEMPORALITY_DELTA + metrics_flush_interval: 20s extensions: {} service: pipelines: @@ -617,6 +621,9 @@ processors: metrics_exporter: prometheus latency_histogram_buckets: {} dimensions: {} + aggregation_temporality: AGGREGATION_TEMPORALITY_CUMULATIVE + metrics_flush_interval: 15s + dimensions_cache_size: 1000 extensions: {} service: