Skip to content

Commit 8bf3488

Browse files
committed
Update Documentation to reflect Spring Boot config changes
1 parent 27690cf commit 8bf3488

File tree

1 file changed

+111
-47
lines changed

1 file changed

+111
-47
lines changed

src/docs/implementations/dynatrace.adoc

Lines changed: 111 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include::install.adoc[]
1010

1111
== Configuring
1212

13-
For setting up new integrations with Dynatrace, it is recommended to use the latest version of the https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/[Dynatrace Metrics API] (`api-version: v2`).
13+
For setting up new integrations with Dynatrace, it is recommended to use the latest version of the https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/[Dynatrace Metrics API] (v2).
1414
Dynatrace provides different ways of setting up integrations:
1515

1616
=== Using a Dynatrace OneAgent installed on the host (preferred) [[bookmark-oneagent-example]]
@@ -39,13 +39,9 @@ MeterRegistry registry = new DynatraceMeterRegistry(dynatraceConfig, Clock.SYSTE
3939
`DynatraceConfig` is an interface with a set of default methods.
4040
Micrometer's Spring Boot support binds properties prefixed with `management.metrics.export.dynatrace` directly to the `DynatraceConfig`.
4141
This allows configuring the Dynatrace exporter by using the <<bookmark-available-properties, the available properties>>.
42-
To enable the export to the local OneAgent, use:
4342

44-
[source,yml]
45-
----
46-
management.metrics.export.dynatrace:
47-
api-version: v2
48-
----
43+
To use the Dynatrace metrics exporter for Micrometer in your Spring Boot project, it is enough to include the `runtimeOnly 'io.micrometer:micrometer-registry-dynatrace'` dependency.
44+
In this default configuration, metrics will be exported to the v2 endpoint.
4945

5046
=== Using a custom endpoint
5147

@@ -67,13 +63,15 @@ DynatraceConfig dynatraceConfig = new DynatraceConfig() {
6763
// The endpoint of the Dynatrace Metrics API v2 including path, e.g.:
6864
// "https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest".
6965
// Should be read from a secure source and not hard-coded.
70-
return MY_DYNATRACE_URI;
66+
String endpoint = System.getenv("DT_METRICS_INGEST_URL");
67+
return endpoint != null ? endpoint : DynatraceConfig.super.uri();
7168
}
7269
7370
@Override
7471
public String apiToken() {
7572
// It is *not* recommended to place secrets in config files but to read them from a secure source.
76-
return MY_TOKEN;
73+
String token = System.getenv("DT_METRICS_INGEST_API_TOKEN");
74+
return token != null ? token : "";
7775
}
7876
7977
@Override
@@ -84,19 +82,23 @@ DynatraceConfig dynatraceConfig = new DynatraceConfig() {
8482
}
8583
};
8684
MeterRegistry registry = new DynatraceMeterRegistry(dynatraceConfig, Clock.SYSTEM);
85+
// Register the Dynatrace registry with the global MeterRegistry.
86+
Metrics.addRegistry(registry);
8787
----
8888

8989
These properties can also be set via the Spring Boot properties file.
9090
It is possible to reference environment variables using the Spring property placeholder notation here (`${VAR_NAME}`).
91+
When running the Micrometer exporter for Spring Boot, `v2` is used as the default API version.
9192

9293
[source,yml]
9394
----
9495
management.metrics.export.dynatrace:
95-
api-version: v2
96+
# for SaaS: https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest
97+
# for managed deployments: https://{your-domain}/e/{your-environment-id}/api/v2/metrics/ingest
98+
uri: ${DT_METRICS_INGEST_URL}
9699
97-
# e.g.: https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest
98-
uri: ${ENV_VAR_DT_INGEST_URI}
99-
api-token: ${ENV_VAR_DT_INGEST_TOKEN}
100+
# should not be hardcoded but rather read from a secure source, like environment variables.
101+
api-token: ${DT_METRICS_INGEST_API_TOKEN}
100102
----
101103

102104
== API Versions
@@ -105,8 +107,10 @@ management.metrics.export.dynatrace:
105107

106108
When the API version is configured to "v2", the registry will send data using the https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/[Metrics API v2].
107109
The v2 exporter does not require any properties to be set except for the version.
108-
In this case, metrics will be exported to the local OneAgent endpoint.
109-
If no OneAgent is running on the target host, it is possible to specify an endpoint and an API token in order to export metrics to that specific endpoint.
110+
When running Micrometer without Spring Boot, the default version is `v1` in order to maintain backwards compatibility.
111+
The version is assumed to be `v2` automatically when using Spring Boot, and does not have to be set explicitly in that case.
112+
With no endpoint URL and token set, metrics will be exported to the local OneAgent endpoint.
113+
If no OneAgent is running on the target host, it is possible to specify endpoint and token explicitly, in order to export metrics to that specific endpoint.
110114

111115
*Minimal configuration with a local Dynatrace OneAgent*
112116

@@ -129,45 +133,101 @@ When using the https://www.dynatrace.com/support/help/dynatrace-api/environment-
129133
[source,yml]
130134
----
131135
management.metrics.export.dynatrace:
132-
# required to use the properties below
133-
api-version: v2
134-
135-
# required if not using a local OneAgent endpoint.
136-
uri: https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest
137-
# or https://{your-domain}/e/{your-environment-id}/api/v2/metrics/ingest on Managed
136+
# Required only if not using the OneAgent endpoint
137+
# For SaaS: https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest
138+
# For managed deployments: https://{your-domain}/e/{your-environment-id}/api/v2/metrics/ingest
139+
uri: ${DT_METRICS_INGEST_URL}
138140
139141
# It is *not* recommended to put the token into the YAML or properties file directly.
140-
# It should be read from a secure source instead.
141-
# E.g. using `api-token: ${ENV_VAR_DT_INGEST_TOKEN}` to read from the environment.
142-
api-token: MY_TOKEN
143-
144-
# Sets a prefix that is prepended to each exported metric key.
145-
metric-key-prefix: my.metric.key.prefix
146-
147-
# If set to true and a local OneAgent or operator is running, retrieves metadata
148-
# and adds it as additional dimensions to all data points (default: true)
149-
enrich-with-dynatrace-metadata: true
150-
151-
# Sets an arbitrary number of key-value pairs as default dimensions.
152-
# Micrometer tags will overwrite these dimensions, if the same key appears twice.
153-
# Each exported metric will contain these dimensions.
154-
default-dimensions:
155-
key1: "value1"
156-
key2: "value2"
142+
# It should be read from a secure source instead, e.g. from environment variables.
143+
# E.g. using `api-token: ${DT_METRICS_INGEST_API_TOKEN}` to read from the environment.
144+
api-token: ${DT_METRICS_INGEST_API_TOKEN}
145+
146+
# These properties can only be used with the v2 exporter.
147+
v2:
148+
# Sets a prefix that is prepended to each exported metric key.
149+
metric-key-prefix: my.metric.key.prefix
150+
151+
# If set to true and a local OneAgent or operator is running, retrieves metadata
152+
# and adds it as additional dimensions to all data points (default: true)
153+
enrich-with-dynatrace-metadata: true
154+
155+
# Sets an arbitrary number of key-value pairs as default dimensions.
156+
# Micrometer tags will overwrite these dimensions, if they have the same key.
157+
# Each exported metric will contain these dimensions.
158+
default-dimensions:
159+
key1: "value1"
160+
key2: "value2"
157161
158162
# The export interval in which metrics are sent to Dynatrace (default: 60s).
159163
step: 60s
160164
----
161165

162-
These properties can also be set in code by overwriting the respective methods of the `DynatraceConfig` class.
166+
These properties can also be set in code by overwriting the respective methods of the `DynatraceConfig` class:
167+
168+
[source,java]
169+
----
170+
DynatraceConfig dynatraceConfig = new DynatraceConfig() {
171+
@Override
172+
public DynatraceApiVersion apiVersion() {
173+
return DynatraceApiVersion.V2;
174+
}
175+
176+
@Override
177+
public String uri() {
178+
// The endpoint of the Dynatrace Metrics API v2 including path, e.g.:
179+
// "https://{your-environment-id}.live.dynatrace.com/api/v2/metrics/ingest".
180+
// Should be read from a secure source and not hard-coded.
181+
String endpoint = System.getenv("DT_METRICS_INGEST_URL");
182+
return endpoint != null ? endpoint : DynatraceConfig.super.uri();
183+
}
184+
185+
@Override
186+
public String apiToken() {
187+
// It is *not* recommended to place secrets in config files but to read them from a secure source.
188+
String token = System.getenv("DT_METRICS_INGEST_API_TOKEN");
189+
return token != null ? token : "";
190+
}
163191
164-
For more information about the metadata picked up by the enrichment, see https://www.dynatrace.com/support/help/how-to-use-dynatrace/metrics/metric-ingestion/ingestion-methods/enrich-metrics/[the Dynatrace documentation].
192+
@Override
193+
public String metricKeyPrefix() {
194+
// will be prepended to all metric keys
195+
return "your.desired.prefix";
196+
}
197+
198+
@Override
199+
public boolean enrichWithDynatraceMetadata() {
200+
return true;
201+
}
202+
203+
@Override
204+
public Map<String, String> defaultDimensions() {
205+
// create and return a map containing the desired key-value pairs.
206+
Map<String, String> dims = new HashMap<String,String>();
207+
dims.put("dimensionKey", "dimensionValue");
208+
return dims;
209+
}
210+
211+
@Override
212+
@Nullable
213+
public String get(String k) {
214+
// This method for retrieving arbitrary config items introduced by the interface is currently not used in DynatraceConfig.
215+
return null;
216+
}
217+
};
218+
----
219+
220+
For more information about the metadata picked up by the Dynatrace metadata enrichment feature, see https://www.dynatrace.com/support/help/how-to-use-dynatrace/metrics/metric-ingestion/ingestion-methods/enrich-metrics/[the Dynatrace documentation].
165221

166222
=== API v1 (Legacy)
167223

168-
When the apiVersion is configured to "v1", the registry will send data using the https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v1/custom-metrics/[Dynatrace Timeseries API v1 for custom metrics].
224+
When the apiVersion is configured to `v1`, the registry will send data using the https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v1/custom-metrics/[Dynatrace Timeseries API v1 for custom metrics].
225+
If no `apiVersion` is specified, it will default to `v1` for backwards compatibility with earlier setups.
226+
When using Spring Boot, `v1` can be turned on by specifying the `device-id` property, which is required for `v1` and not used in `v2`.
227+
Therefore, when running Spring Boot with the `v1` exporter and a configuration with the required `device-id` property, metrics will be exported to the v1 API.
228+
Existing setups will continue to work when updating to newer versions of Micrometer.
169229
The reported metrics will be assigned to https://www.dynatrace.com/support/help/dynatrace-api/environment-api/topology-and-smartscape/custom-device-api/report-custom-device-metric-via-rest-api/[custom devices] in Dynatrace.
170-
If no apiVersion is specified, it will default to "v1" for backwards-compatibility with earlier setups.
230+
171231

172232
For the v1 API, do not specify the ingest path, but only the base URL of your environment, e.g.: `uri: https://{your-environment-id}.live.dynatrace.com`
173233

@@ -204,14 +264,18 @@ MeterRegistry registry = new DynatraceMeterRegistry(dynatraceConfig, Clock.SYSTE
204264
[source,yml]
205265
----
206266
management.metrics.export.dynatrace:
207-
# This is required
208-
uri: https://your-environment-id.live.dynatrace.com
267+
# For v1 export, do not append a path to the endpoint URL, e.g.:
268+
# For SaaS: https://{your-environment-id}.live.dynatrace.com
269+
# For managed deployments: https://{your-domain}/e/{your-environment-id}
270+
uri: https://{your-environment-id}.live.dynatrace.com
209271
210-
# This is required
272+
# This should not be hardcoded but rather read from a secure source.
211273
api-token: MY_TOKEN
212274
213-
# This is required
214-
device-id: sample
275+
# When setting the device id, metrics will be exported to the v1 timeseries endpoint
276+
# Using just device-id (without the v1 prefix) is deprecated, but will work to maintain backwards compatibility.
277+
v1:
278+
device-id: sample
215279
216280
# To disable Dynatrace publishing, e.g. in a local development profile, use:
217281
# enabled: false

0 commit comments

Comments
 (0)