Skip to main content

Ingest data

Enrich data on the Dynatrace platform by ingesting metrics, logs, and events within your app. You can do this by using the ingest endpoints of the Dynatrace API. Alternatively, you can use Extensions to collect observability data from different data sources not covered by OneAgent.

Dynatrace provides various SDK packages to make your life easier. Here are some examples of what you can do:

Metrics

To ingest metrics, you can use the ingest method of the metricsClient namespace, which is provided by the @dynatrace-sdk/client-classic-environment-v2 package. You have to pass the metric values in the form of a string based on the Metrics ingestion protocol. Further ways of ingesting metrics can be found here.

import { metricsClient } from '@dynatrace-sdk/client-classic-environment-v2';

metricsClient
.ingest({ body: 'cpu.temperature,hostname=host 55' })
.then((response) => {
console.log(response);
})
.catch((e) => {
console.error(e);
});

The ingested metrics can be queried with the following DQL statement:

timeseries avg(cpu.temperature)

Tip

This operation requires the scope storage:metrics:write. Read more about scopes in this guide.

Logs

To ingest logs, you can use the storeLog method of the logsClient namespace, which is provided by the @dynatrace-sdk/client-classic-environment-v2 package. The method accepts a single log line as a JSON object or multiple log lines as an array.

An example of this could look like the following:

import { logsClient } from '@dynatrace-sdk/client-classic-environment-v2';

const logs = [
{
'content': 'example log content 1',
'log.source': '/var/log/syslog',
'log.tag': ['tag1', 'tag2'],
},
{ content: 'example log content 2' },
];

logsClient
.storeLog({
body: logs,
type: 'application/json; charset=utf-8',
})
.then((response) => console.log(response))
.catch((e) => console.error(e));

In case of a successful ingest, the API returns an empty response body (see API docs). So the response object of the storeLog method is undefined.

You can query the ingested logs with the following DQL statement:

fetch logs
| filter contains(content, "example")

Tip

This operation requires the scope storage:logs:write. Read more about scopes in this guide.

Business events

To ingest business events, you can use the ingest function from the businessEventsClient namespace provided by the @dynatrace-sdk/client-classic-environment-v2 package. In the following example, you're ingesting a CloudEvent.

import { businessEventsClient } from '@dynatrace-sdk/client-classic-environment-v2';

const bizevent = {
specversion: '1.0',
source: 'booking.app.tutorial',
id: crypto.randomUUID().toString(),
type: 'booking.process.started',
data: {
amount: 869,
startdate: '2020-04-06',
arrivaldate: '2022-04-16',
currency: 'USD',
numbertravelers: 2,
product: 'Vienna - New York',
},
};

businessEventsClient
.ingest({
body: bizevent,
type: 'application/cloudevent+json',
})
.then(() => console.log('Event ingested'))
.catch((e) => console.error('Failed to ingest event: ' + e));

Key things to remember

  • It's important that you specify the correct content type as highlighted in the previous code.
  • Dynatrace support both CloudEvent and pure JSON data. For cloud events, the content type is application/cloudevent+json and for pure JSON data it is application/json; charset=utf-8.

You can query this event with the following DQL statement:

fetch bizevents
| filter event.type == "booking.process.started"

Tip

This operation requires the scope storage:events:write. Read more about scopes in this guide.

Events (Davis events)

To ingest events, you need to use the createEvent method of the eventsClient namespace within the @dynatrace-sdk/client-classic-environment-v2 package:

import { EventIngest, EventIngestEventType, eventsClient } from '@dynatrace-sdk/client-classic-environment-v2';

const terminationEvent: EventIngest = {
eventType: EventIngestEventType.MarkedForTermination,
title: 'Planned host downscale',
entitySelector: 'type(HOST),entityId(HOST-7DB082B3599E3EA9)',
properties: { 'job.number': '21234346' },
};

eventsClient.createEvent({ body: terminationEvent });

The example above shows how to ingest an event that should mark a host with a specific host id for termination.

The ingested event can be queried with the following DQL statement:

fetch events
| filter event.kind == "DAVIS_EVENT"
| filter event.type == "MARKED_FOR_TERMINATION"

Tip

This operation requires the scope storage:events:write. Read more about scopes in this guide.

Extensions 2.0

Dynatrace provides capabilities for monitoring and analyzing the performance of all aspects of your application environment. With OneAgent, you can monitor everything that runs on a host. However, you often need to look deeper into other technologies that don't accept agents, for example, network devices. Extensions can cover these cases.

You can install extensions on both OneAgent and ActiveGates. They connect to the monitored technologies in the best way that fits that technology. Dynatrace develops the extension data acquisition layer (data source), which allows you to easily manage your extensions declaratively by creating a YAML file specifying what data you want and from where.

To learn more, visit Extensions 2.0

Still have questions?
Find answers in the Dynatrace Community