@ms-cloudpack/telemetry
v0.12.4
Published
Helpers for reporting telemetry in Cloudpack.
Keywords
Readme
@ms-cloudpack/telemetry
A library for reporting Cloudpack telemetry to Application Insights using Open Telemetry standards.
Telemetry is only reported by the Cloudpack CLI if a connection string is configured (telemetry.connectionString in cloudpack.config.json, or CLOUDPACK_TELEMETRY_CONNECTION_STRING environment variable). It will only be sent to your own Application Insights instance referenced by the connection string, not to Microsoft.
Currently, this library only supports Tracing. Metrics and Logs can be added later when needed.
Example usage
Create a client:
const appPath = 'path to your app'; const telemetryApi = await startTelemetry({ serviceName: 'service', productVersion: '1.2.3', logLevel: 'VERBOSE', connectionStrings: { [appPath]: '<Application Insights instrumentation key>', }, }); const telemetryClient = telemetryApi.clients[appPath];Create a span / add events / end the span (learn more about spans)
await telemetryClient.tracer.startActiveSpan('my-unit-of-work', async (span) => { // do work span.addEvent('my-event', { myCustomAttribute: 'my-custom-value' }); // do more work }); // span ends automaticallyShut down TelemetryClient before application exists.
This will force flush all the remaining data to remote servers and prevent more data to be collected.
Make sure that all spans have been ended before shuting down the telemetry client
await telemetryApi.shutdown();
