Socket
Socket
Sign inDemoInstall

@opentelemetry/api-metrics

Package Overview
Dependencies
0
Maintainers
4
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @opentelemetry/api-metrics

Public metrics API for OpenTelemetry


Version published
Maintainers
4
Install size
162 kB
Created

Changelog

Source

1.0.1 / Experimental 0.27.0

:boom: Breaking Change

  • Other
    • #2566 feat!(metrics): remove batch observer (@dyladan)
    • #2485 feat!: Split metric and trace exporters into new experimental packages (@willarmiros)
    • #2540 fix(sdk-metrics-base): remove metric kind BATCH_OBSERVER (@legendecas)
    • #2496 feat(api-metrics): rename metric instruments to match feature-freeze API specification (@legendecas)
  • opentelemetry-core

:rocket: (Enhancement)

  • Other
    • #2523 feat: Rename Labels to Attributes (@pirgeo)
    • #2559 feat(api-metrics): remove bind/unbind and bound instruments (@legendecas)
    • #2563 feat(sdk-metrics-base): remove per-meter config on MeterProvider.getMeter (@legendecas)
  • opentelemetry-core
    • #2465 fix: prefer globalThis instead of window to support webworkers (@legendecas)
  • opentelemetry-semantic-conventions
    • #2532 feat(@opentelemetry/semantic-conventions): change enum to object literals (@echoontheway)
    • #2528 feat: upgrade semantic-conventions to latest v1.7.0 spec (@weyert)
  • opentelemetry-core, opentelemetry-sdk-trace-base

:bug: (Bug Fix)

  • Other
    • #2610 fix: preventing double enable for instrumentation that has been already enabled (@obecny)
    • #2581 feat: lazy initialization of the gzip stream (@fungiboletus)
    • #2584 fix: fixing compatibility versions for detectors (@obecny)
    • #2558 fix(@opentelemetry/exporter-prometheus): unref prometheus server to prevent process running indefinitely (@mothershipper)
    • #2495 fix(sdk-metrics-base): metrics name should be in the max length of 63 (@legendecas)
    • #2497 feat(@opentelemetry-instrumentation-fetch): support reading response body from the hook applyCustomAttributesOnSpan (@echoontheway)
  • opentelemetry-core
    • #2560 fix(core): support regex global flag in urlMatches (@moander)
  • opentelemetry-exporter-zipkin
    • #2519 fix(exporter-zipkin): correct status tags names (@t2t2)

:books: (Refine Doc)

:house: (Internal)

  • Other
  • opentelemetry-sdk-trace-base, opentelemetry-sdk-trace-node, opentelemetry-sdk-trace-web
  • opentelemetry-context-async-hooks, opentelemetry-context-zone-peer-dep, opentelemetry-core, opentelemetry-exporter-jaeger, opentelemetry-exporter-zipkin, opentelemetry-propagator-b3, opentelemetry-propagator-jaeger, opentelemetry-resources, opentelemetry-sdk-trace-base, opentelemetry-sdk-trace-node, opentelemetry-sdk-trace-web, opentelemetry-shim-opentracing
  • opentelemetry-core

Committers: 23

Readme

Source

OpenTelemetry API for JavaScript

NPM Published Version dependencies devDependencies Apache License

This package provides everything needed to interact with the unstable OpenTelemetry Metrics API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser.

Beta Software - Use at your own risk

The metrics API is considered alpha software and there is no guarantee of stability or long-term support. When the API is stabilized, it will be made available and supported long-term in the @opentelemetry/api package and this package will be deprecated.

Quick Start

To get started you need to install the SDK and instrumentations, create a MeterProvider, and register it with the API.

Install Dependencies

$ # Install metrics dependencies
$ npm install \
    @opentelemetry/api-metrics \
    @opentelemetry/sdk-metrics-base \
    @opentelemetry/exporter-prometheus # add exporters as needed

Note: this example is for node.js. See examples/tracer-web for a browser example.

Initialize the SDK

Before any other module in your application is loaded, you must initialize the global tracer and meter providers. If you fail to initialize a provider, no-op implementations will be provided to any library which acquires them from the API.

To collect traces and metrics, you will have to tell the SDK where to export telemetry data to. This example uses Jaeger and Prometheus, but exporters exist for other tracing backends. If you're not sure if there is an exporter for your tracing backend, contact your tracing provider.

Metrics
const api = require("@opentelemetry/api-metrics");
const { MeterProvider } = require("@opentelemetry/sdk-metrics-base");
const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus");

const meterProvider = new MeterProvider({
  // The Prometheus exporter runs an HTTP server which
  // the Prometheus backend scrapes to collect metrics.
  exporter: new PrometheusExporter({ startServer: true }),
  interval: 1000,
});

/**
 * Registering the provider with the API allows it to be discovered
 * and used by instrumentation libraries.
 */
api.metrics.setGlobalMeterProvider(meterProvider);

Version Compatibility

Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same node_modules structure, the OpenTelemetry API takes advantage of a variable on the global object to store the global API. When an API method in the API package is called, it checks if this global API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API.

Advanced Use

API Methods

If you are writing an instrumentation library, or prefer to call the API methods directly rather than using the register method on the Tracer/Meter Provider, OpenTelemetry provides direct access to the underlying API methods through the @opentelemetry/api-metrics package. API entry points are defined as global singleton objects trace, metrics, propagation, and context which contain methods used to initialize SDK implementations and acquire resources from the API.

const api = require("@opentelemetry/api-metrics");

/* Initialize MeterProvider */
api.metrics.setGlobalMeterProvider(meterProvider);
/* returns meterProvider (no-op if a working provider has not been initialized) */
api.metrics.getMeterProvider();
/* returns a meter from the registered global meter provider (no-op if a working provider has not been initialized) */
api.metrics.getMeter(name, version);

License

Apache 2.0 - See LICENSE for more information.

Keywords

FAQs

Last updated on 11 Nov 2021

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