Package: opentelemetry-exporter-dynatrace-metrics
Dynatrace OpenTelemetry Metrics Exporter for PythonThis exporter allows exporting metrics created using theOpenTelemetry SDK for Pythondirectly toDynatrace.It was built against OpenTelemetry SDK version1.12.0and should work with any1.12+version.More information on exporting OpenTelemetry metrics to Dynatrace can be found in theDynatrace documentation.Getting startedInstallationTo install thelatest version from PyPIrun:pipinstallopentelemetry-exporter-dynatrace-metricsUsageThe general setup of OpenTelemetry Python is explained in the officialGetting Started Guide.# setup metrics export pipelinemetrics.set_meter_provider(MeterProvider(# configure Exporter/MetricReader combination with a 5000ms export# interval, endpoint url and API token.metric_readers=[configure_dynatrace_metrics_export(export_interval_millis=5000,endpoint_url=endpoint_url,api_token=api_token)]))# get a metermeter=metrics.get_meter(__name__)# create a counter instrument and provide the first data pointcounter=meter.create_counter(name="my_counter",description="Description of MyCounter",unit="1")counter.add(25,{"dimension-1":"value-1"})ExampleTo run theexample, clone this repository and change to theopentelemetry-metric-pythonfolder, then run:pipinstall.# install the Dynatrace exporterexportLOGLEVEL=DEBUG# (optional) Set the log level to debug to see more output (default is INFO)pythonexample/basic_example.pyA more complete setup routine can be foundhere, including installing inside a virtual environment and getting required packages.
If you just want to see it in action, it should be sufficient to runexample/install_and_run.shfrom the root folder.
This script will install Python, set up a virtual environment, pull in all the required packages and run theexample.The example also offers a simple CLI. Runpython example/basic_example.py -hto get more information.ConfigurationThe exporter allows for configuring the following settings by passing them to the constructor:Dynatrace API EndpointThe endpoint to which the metrics are sent is specified using theendpoint_urlparameter.Given an environment IDmyenv123on Dynatrace SaaS, themetrics ingest endpointwould behttps://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.
This feature is currently in an Early Adopter phase and has to be enabled as described in theOneAgent metric API documentation.
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 ishttp://localhost:14499/metrics/ingest.
If no endpoint is set and a OneAgent is running on the host, metrics will be exported to it automatically using the OneAgent with no endpoint or API token configuration required.Dynatrace API TokenThe Dynatrace API token to be used by the exporter is specified using theapi_tokenparameter and could, for example, be read from an environment variable.Creating an API token for your Dynatrace environment is described in theDynatrace API documentation.
The permission required for sending metrics isIngest metrics(metrics.ingest) and it is recommended to limit scope to only this permission.Metric Key PrefixTheprefixparameter specifies an optional prefix, which is prepended to each metric key, separated by a dot (<prefix>.<name>).Default DimensionsThedefault_dimensionsparameter can be used to optionally specify a list of key/value pairs, which will be added as additional dimensions to all data points.
Dimension keys are unique, and labels on instruments will overwrite the default dimensions if key collisions appear.Export Dynatrace MetadataIf running on a host with a running OneAgent, setting theexport_dynatrace_metadataoption toTruewill export metadata collected by the OneAgent to the Dynatrace endpoint.
If no Dynatrace API endpoint is set, the default exporter endpoint will be the OneAgent endpoint, and this option will be set automatically.
Therefore, if no endpoint is specified, a OneAgent is assumed to be running and used as the export endpoint for all metric lines, including metadata.
More information on the underlying Dynatrace metadata feature that is used by the exporter can be found in theDynatrace documentation.Dimensions precedenceWhen specifying default dimensions, attributes and Dynatrace metadata enrichment, the precedence of dimensions with the same key is as follows:
Default dimensions are overwritten by attributes passed to instruments, which in turn are overwritten by the Dynatrace metadata dimensions (even though the likeliness of a collision here is very low, since the Dynatrace metadata only containsDynatrace reserved dimensionsstarting withdt.*).DevelopmentRequirementsJusttox.Running tests and lintTest all supported python versions:toxTest all supported python versions in parallel:tox -pA particular python version:tox -e 38Current python version:tox -e pyLint:tox -e lintLimitationsTyped attributes supportThe OpenTelemetry Metrics API for Python supports the concept
ofAttributes.
These attributes consist of key-value pairs, where the keys are strings and the
values are either primitive types or arrays of uniform primitive types.At the moment, this exporteronly supports attributes with string key and
value type.
This means that if attributes of any other type are used, they will beignoredandonlythe string-valued attributes are going to be sent to
Dynatrace.HistogramOpenTelemetry 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.