Dynatrace OpenTelemetry Metrics Exporter for JavaScript
This exporter is currently in RC state and therefore
not intended for production use.
This exporter allows exporting metrics created using the OpenTelemetry SDK for JavaScript
directly to Dynatrace.
It was built against OpenTelemetry SDK version 1.8.0.
More information on exporting OpenTelemetry metrics to Dynatrace can be found in
the Dynatrace documentation.
Getting started
The general setup of OpenTelemetry JS is explained in the official
Getting Started Guide.
Using the Metrics API is explained in the
Monitor Your NodeJS Application section.
Install Dependencies
The Dynatrace OpenTelemetry exporter requires the following prerequisites:
- Node.js 14+
- NPM (8+ recommended, included with Node.js)
npm install --global npm
npm install @dynatrace/opentelemetry-exporter-metrics
If you are using a npm version < 7, please install the @opentelemetry/api
peer dependency manually.
npm install @opentelemetry/api
Initialize components
The Dynatrace exporter is added and set-up like this:
'use strict';
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
const { Resource } = require('@opentelemetry/resources');
const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const { configureDynatraceMetricExport } = require('@dynatrace/opentelemetry-exporter-metrics');
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL)
const provider = new MeterProvider({
resource: new Resource({
'service.name': 'opentelemetry-metrics-sample-dynatrace'
})
});
const reader = configureDynatraceMetricExport(
{
prefix: 'sample',
defaultDimensions: [
{ key: 'default-dim', value: 'default-dim-value' },
],
},
{
exportIntervalMillis: 5000
}
);
provider.addMetricReader(reader);
const meter = provider.getMeter('opentelemetry-metrics-sample-dynatrace');
const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter'
});
const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {
description: 'Example of a UpDownCounter'
});
const attributes = {
pid: process.pid.toString(),
environment: 'staging'
};
setInterval(() => {
requestCounter.add(Math.round(Math.random() * 1000), attributes);
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes);
}, 1000);
Metrics are exported periodically, depending on the value of
exportIntervalMillis set above.
A full setup is provided in our example project.
Configuration
The exporter allows for configuring the following settings by setting them in
the ExporterConfig in configureDynatraceMetricExport:
In addition, there are some settings that will be passed to the MetricReader.
These can be set in the ReaderConfig
exportIntervalMillis | number | The interval in which metrics are exported. | 60000 (60 seconds) |
exportTimeoutMillis | number | The maximum timeout to wait for an export to finish. | 30000 (30 seconds) |
Dynatrace API Endpoint
API Endpoint and Token are optional. By default, metrics will be exported to
the local OneAgent endpoint described below, if it is available.
The endpoint to which the metrics are sent is specified using the url
parameter.
Given an environment ID myenv123 on Dynatrace SaaS, the
metrics ingest endpoint
would be https://myenv123.live.dynatrace.com/api/v2/metrics/ingest.
If a OneAgent is installed on the host, it can provide a local endpoint for
providing metrics directly without the need for an API token.
Depending on your environment, this feature might have to be enabled as
described in the
OneAgent metric API documentation
first.
Using the local API endpoint, the host ID and host name context are
automatically added to each metric as dimensions.
The default metric API endpoint exposed by the OneAgent is
http://localhost:14499/metrics/ingest.
If no Dynatrace API endpoint is set, the exporter will default to the local
OneAgent endpoint.
Dynatrace API Token
Required only if an API endpoint is also provided.
The Dynatrace API token to be used by the exporter is specified using the
apiToken parameter and could, for example, be read from an environment
variable.
Creating an API token for your Dynatrace environment is described in the
Dynatrace API documentation.
The permission required for sending metrics is Ingest metrics
(metrics.ingest) and it is recommended to limit scope to only
this permission.
Metric Key Prefix
The prefix parameter specifies an optional prefix, which is prepended to each
metric key, separated by a dot (<prefix>.<namespace>.<name>).
Default Attributes/Dimensions
The defaultDimensions parameter can be used to optionally specify a list of key/value
pairs, which will be added as additional attributes/dimensions to all data points.
Retries on Connection Failure
The maxRetries parameter can be used to set the amount of times the exporter should
retry on connection failures. By default, the exporter will retry 3 times before
marking the batch as failed. This number must be greater than or equal to 0.
The retryDelay parameter can be used to set the time in milliseconds to wait until
re-trying an export after a connection failure, the default is 1000ms. This number
must be greater than or equal to 0.
Dynatrace Metadata Enrichment
If running on a host with a running OneAgent, the exporter will export metadata
collected by the OneAgent to the Dynatrace endpoint.
This typically consists of the Dynatrace host ID and process group ID.
More information on the underlying feature used by the exporter can be found in
the
Dynatrace documentation.
By default, this option is turned on.
Limitations
Histogram
OpenTelemetry Histograms are exported to Dynatrace as statistical summaries
consisting of a minimum and maximum value, the total sum of all values, and the
count of the values summarized. If the min and max values are not directly
available on the metric data point, estimations based on the boundaries of the
first and last buckets containing values are used.
Attribute type limitations
Currently, only string type attribute values are supported.
Attributes with values of any other type will be dropped and not exported.
If you need those values to be exported, please convert them to string
type before export.