@ms-cloudpack/telemetry
v0.11.65
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 telemetryClient = new TelemetryClient({
serviceNamespace: 'cloudpack',
serviceName: 'cli',
productVersion: '1.2.3',
instrumentationKey: '<Application insights Instrumentation Key>',
logLevel: 'verbose',
});- Add shared attributes
telemetryClient.setSharedSpanAttribute('sessionId', 'my-session-id');These attributes will get added to all spans.
- Get the tracer
const tracer = telemetryClient.getTracer();- Create a span / add events / end the span
const span = tracer.createSpan('my-unit-of-work');
// do work
span.addEvent('my-event', { myCustomAttribute: 'my-custom-value' });
try {
// do more work
} catch (err) {
span.recordException(err);
}
// end the span when the unit-of-work completed.
span.end();- Shutdown TelemetryClient before application exists
telemetryClient.shutdown();- 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
