@ms-cloudpack/telemetry
TypeScript icon, indicating that this package has built-in type declarations

0.5.2 • Public • Published

@ms-cloudpack/telemetry

A library for telemetry that gets reported to Application Insights by using Open Telemetry standards.

Currently, this library only supports Tracing. Metrics and Logs can be added later when needed.

Example usage

  1. Create a client:
const telemetryClient = new TelemetryClient({
  serviceNamespace: 'cloudpack',
  serviceName: 'cli',
  productVersion: '1.2.3',
  instrumentationKey: '<Application insights Instrumentation Key>',
  logLevel: 'verbose',
});
  1. Add shared attributes
telemetryClient.setSharedSpanAttribute('sessionId', 'my-session-id');

These attributes will get added to all spans.

  1. Get the tracer
const tracer = telemetryClient.getTracer();
  1. 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();

Lear more about spans

  1. 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

/@ms-cloudpack/telemetry/

    Package Sidebar

    Install

    npm i @ms-cloudpack/telemetry

    Weekly Downloads

    264

    Version

    0.5.2

    License

    MIT

    Unpacked Size

    1.08 MB

    Total Files

    26

    Last publish

    Collaborators

    • ecraig12345_msft
    • uifabricteam
    • dzearing