From 71e2e5e8e47ea2b3504ac9039dc835e001778675 Mon Sep 17 00:00:00 2001
From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
Date: Tue, 6 Feb 2024 13:05:44 +0900
Subject: [PATCH] Document newly supported OTLP env vars
See gh-4500 that added support for more environment variables. Documents that support in our reference documentation.
Resolves gh-4566
---
.../ROOT/pages/implementations/otlp.adoc | 8 ++++--
.../micrometer/registry/otlp/OtlpConfig.java | 28 ++++++++++++++++---
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/docs/modules/ROOT/pages/implementations/otlp.adoc b/docs/modules/ROOT/pages/implementations/otlp.adoc
index cf71caa430..90a967e2f9 100644
--- a/docs/modules/ROOT/pages/implementations/otlp.adoc
+++ b/docs/modules/ROOT/pages/implementations/otlp.adoc
@@ -35,15 +35,17 @@ management:
aggregationTemporality: "cumulative"
headers:
header1: value1
+ step: 30s
resourceAttributes:
key1: value1
----
-1. `url` - The URL to which data is reported. Defaults to `http://localhost:4318/v1/metrics`
-2. `aggregationTemporality` - https://opentelemetry.io/docs/specs/otel/metrics/data-model/#temporality[Aggregation temporality, window=_blank] determines how the additive quantities are expressed, in relation to time. The supported values are `cumulative` or `delta`. Defaults to `cumulative`. +
+1. `url` - The URL to which data is reported. Environment variables `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` and `OTEL_EXPORTER_OTLP_ENDPOINT` are also supported in the default implementation. If a value is not provided, it defaults to `http://localhost:4318/v1/metrics`
+2. `aggregationTemporality` - https://opentelemetry.io/docs/specs/otel/metrics/data-model/#temporality[Aggregation temporality, window=_blank] determines how the additive quantities are expressed, in relation to time. The environment variable `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` is supported by the default implementation. The supported values are `cumulative` or `delta`. Defaults to `cumulative`. +
*Note*: This config was introduced in version 1.11.0.
3. `headers` - Additional headers to send with exported metrics. This can be used for authorization headers. By default, headers are loaded from the config. If that is not set, they can be taken from the environment variables `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_METRICS_HEADERS`. If a header is set in both the environmental variables, the header in the latter overrides the former.
-4. `resourceAttributes` - https://opentelemetry.io/docs/specs/otel/resource/semantic_conventions/#service[Resource attributes, window=_blank] are used for all metrics published. By default, Micrometer adds the following resource attributes:
+4. `step` - the interval at which metrics will be published. The environment variable `OTEL_METRIC_EXPORT_INTERVAL` is supported by the default implementation. If a value is not provided, defaults to 1 minute.
+5. `resourceAttributes` - https://opentelemetry.io/docs/specs/otel/resource/semantic_conventions/#service[Resource attributes, window=_blank] are used for all metrics published. By default, Micrometer adds the following resource attributes:
[%autowidth]
|===
diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java
index 58a2fed6f4..3183a6add6 100644
--- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java
+++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java
@@ -50,8 +50,15 @@ default String prefix() {
}
/**
- * Defaults to http://localhost:4318/v1/metrics
- * @return address to where metrics will be published.
+ * If no value is returned by {@link #get(String)}, environment variables
+ * {@code OTEL_EXPORTER_OTLP_METRICS_ENDPOINT} and {@code OTEL_EXPORTER_OTLP_ENDPOINT}
+ * environment variables will be checked, in that order, by the default
+ * implementation.
+ * @return address to where metrics will be published. Default is
+ * {@code http://localhost:4318/v1/metrics}
+ * @see OTLP
+ * Exporter Configuration
*/
default String url() {
return getUrlString(this, "url").orElseGet(() -> {
@@ -70,6 +77,14 @@ else if (!endpoint.endsWith("/v1/metrics")) {
});
}
+ /**
+ * Default implementation supports the environment variable
+ * {@code OTEL_METRIC_EXPORT_INTERVAL} when the step value is not provided by the
+ * {@link #get(String)} implementation.
+ * @return step size (reporting frequency) to use. The default is 1 minute.
+ * @see OTEL_METRIC_EXPORT_INTERVAL
+ */
@Override
default Duration step() {
Validated step = getDuration(this, "step");
@@ -120,11 +135,16 @@ default Map resourceAttributes() {
/**
* {@link AggregationTemporality} of the OtlpMeterRegistry. This determines whether
* the meters should be cumulative(AGGREGATION_TEMPORALITY_CUMULATIVE) or
- * step/delta(AGGREGATION_TEMPORALITY_DELTA).
- * @return the aggregationTemporality for OtlpMeterRegistry
+ * step/delta(AGGREGATION_TEMPORALITY_DELTA). Default implementation supports the
+ * environment variable {@code OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE} when
+ * a value is not provided by {@link #get(String)}.
+ * @return the aggregationTemporality; default is Cumulative
* @see OTLP
* Temporality
+ * @see OpenTelemetry
+ * Metrics Exporter - OTLP
* @since 1.11.0
*/
default AggregationTemporality aggregationTemporality() {