Skip to content

Commit 50699ee

Browse files
authored
temporality preference from env (#990)
Implement OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, which controls the temporality of meters when creating from environment vars. Add OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION to variables, although we do not yet have anything that uses it.
1 parent a489865 commit 50699ee

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

Common/Configuration/Defaults.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ interface Defaults
104104
public const OTEL_METRICS_EXEMPLAR_FILTER = 'with_sampled_trace';
105105
public const OTEL_METRIC_EXPORT_INTERVAL = 60000;
106106
public const OTEL_METRIC_EXPORT_TIMEOUT = 30000;
107+
public const OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = 'cumulative';
108+
public const OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION = 'explicit_bucket_histogram';
107109
/**
108110
* Language Specific Environment Variables
109111
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#language-specific-environment-variables

Common/Configuration/KnownValues.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ interface KnownValues
5454
public const VALUE_LOG_NOTICE = LogLevel::NOTICE;
5555
public const VALUE_LOG_INFO = LogLevel::INFO;
5656
public const VALUE_LOG_DEBUG = LogLevel::DEBUG;
57+
public const VALUE_TEMPORALITY_CUMULATIVE = 'cumulative';
58+
public const VALUE_TEMPORALITY_DELTA = 'delta';
59+
public const VALUE_TEMPORALITY_LOW_MEMORY = 'lowmemory';
60+
public const VALUE_HISTOGRAM_AGGREGATION_EXPLICIT = 'explicit_bucket_histogram';
61+
public const VALUE_HISTOGRAM_AGGREGATION_BASE2_EXPONENTIAL = 'base2_exponential_bucket_histogram';
5762

5863
public const VALUES_BOOLEAN = [
5964
self::VALUE_TRUE,
@@ -71,6 +76,17 @@ interface KnownValues
7176
self::VALUE_HTTP_JSON,
7277
];
7378

79+
public const VALUES_TEMPORALITY_PREFERENCE = [
80+
self::VALUE_TEMPORALITY_CUMULATIVE,
81+
self::VALUE_TEMPORALITY_DELTA,
82+
self::VALUE_TEMPORALITY_LOW_MEMORY,
83+
];
84+
85+
public const VALUES_HISTOGRAM_AGGREGATION = [
86+
self::VALUE_HISTOGRAM_AGGREGATION_EXPLICIT,
87+
self::VALUE_HISTOGRAM_AGGREGATION_BASE2_EXPONENTIAL,
88+
];
89+
7490
/**
7591
* General SDK Configuration
7692
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#general-sdk-configuration

Common/Configuration/ValueTypes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ interface ValueTypes
110110
public const OTEL_METRICS_EXEMPLAR_FILTER = VariableTypes::ENUM;
111111
public const OTEL_METRIC_EXPORT_INTERVAL = VariableTypes::INTEGER;
112112
public const OTEL_METRIC_EXPORT_TIMEOUT = VariableTypes::INTEGER;
113+
public const OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = VariableTypes::ENUM;
114+
public const OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION = VariableTypes::ENUM;
113115
/**
114116
* Language Specific Environment Variables
115117
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#language-specific-environment-variables

Common/Configuration/Variables.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ interface Variables
125125
public const OTEL_METRICS_EXEMPLAR_FILTER = 'OTEL_METRICS_EXEMPLAR_FILTER';
126126
public const OTEL_METRIC_EXPORT_INTERVAL = 'OTEL_METRIC_EXPORT_INTERVAL';
127127
public const OTEL_METRIC_EXPORT_TIMEOUT = 'OTEL_METRIC_EXPORT_TIMEOUT';
128+
public const OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = 'OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE';
129+
public const OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION = 'OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION';
128130
/**
129131
* Language Specific Environment Variables
130132
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#language-specific-environment-variables

Metrics/MeterProviderFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class MeterProviderFactory
2323
{
2424
use LogsMessagesTrait;
2525

26+
/**
27+
* @todo https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md#general
28+
* - "The exporter MUST configure the default aggregation on the basis of instrument kind using the
29+
* OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION variable as described below if it is implemented."
30+
*/
2631
public function create(): MeterProviderInterface
2732
{
2833
if (Sdk::isDisabled()) {
@@ -43,6 +48,7 @@ public function create(): MeterProviderInterface
4348
$exporter = new NoopMetricExporter();
4449
}
4550

51+
// @todo "The exporter MUST be paired with a periodic exporting MetricReader"
4652
$reader = new ExportingReader($exporter);
4753
$resource = ResourceInfoFactory::defaultResource();
4854
$exemplarFilter = $this->createExemplarFilter(Configuration::getEnum(Variables::OTEL_METRICS_EXEMPLAR_FILTER));

0 commit comments

Comments
 (0)