Skip to main content

Application Telemetry

You can collect usage telemetry of your DeviceScript using trackEvent or trackMetric

When connected to the gateway, the device is modelled as a user and the connection as a session. The data is injected directly in Application Insights and can be analyzed through the Azure portal.

Exceptions

The trackException method uploads an exception to Application Insights. The stacktrace information is expanded in the gateway.

import { trackException } from "@devicescript/cloud"

try {
throw new Error("noes!")
} catch (e) {
await trackException(e as Error)
}

Events

The trackEvent method creates custom events in application insights. The event may be buffered or sampled to reduce the network load.

import { trackEvent } from "@devicescript/cloud"

await trackEvent("started")

Metrics

The metric aggregates a numerical value and upload the aggregate when requested.

import { Temperature } from "@devicescript/core"
import { createMetric } from "@devicescript/cloud"

const thermo = new Temperature()
const temp = createMetric("temp")
thermo.reading.subscribe(async t => temp.add(t))
setInterval(async () => {
await temp.upload()
}, 30000)