Socket
Socket
Sign inDemoInstall

@ms-cloudpack/telemetry

Package Overview
Dependencies
0
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ms-cloudpack/telemetry

Helpers for logging tasks to the console.


Version published
Weekly downloads
316
increased by42.34%
Maintainers
3
Install size
0.978 MB
Created
Weekly downloads
 

Readme

Source

@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

FAQs

Last updated on 25 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc