Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@opentelemetry/api-metrics

Package Overview
Dependencies
1
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
Weekly downloads
820K
decreased by-26.51%
Maintainers
4
Created
Weekly downloads
 

Changelog

Source

0.20.0

:boom: Breaking Change

  • opentelemetry-sdk-node, opentelemetry-tracing
    • #2190 feat: apply spec changes for TraceParams (@weyert)
  • opentelemetry-node, opentelemetry-propagator-jaeger, opentelemetry-shim-opentracing
    • #2148 chore: renaming jaeger http trace propagator to jaeger propagator (@obecny)
  • opentelemetry-core, opentelemetry-instrumentation-grpc, opentelemetry-shim-opentracing, opentelemetry-tracing
    • #2149 chore: adding sufix propagator to http baggage and http trace context (@obecny)

:rocket: (Enhancement)

  • opentelemetry-shim-opentracing
  • opentelemetry-tracing
  • opentelemetry-core, opentelemetry-exporter-collector-grpc, opentelemetry-exporter-collector-proto, opentelemetry-exporter-collector, opentelemetry-exporter-jaeger, opentelemetry-exporter-zipkin, opentelemetry-metrics, opentelemetry-resources, opentelemetry-sdk-node, opentelemetry-tracing
  • opentelemetry-api-metrics, opentelemetry-context-async-hooks, opentelemetry-context-zone-peer-dep, opentelemetry-context-zone, opentelemetry-core, opentelemetry-exporter-collector-grpc, opentelemetry-exporter-collector-proto, opentelemetry-exporter-collector, opentelemetry-exporter-jaeger, opentelemetry-exporter-prometheus, opentelemetry-exporter-zipkin, opentelemetry-instrumentation-fetch, opentelemetry-instrumentation-grpc, opentelemetry-instrumentation-http, opentelemetry-instrumentation-xml-http-request, opentelemetry-instrumentation, opentelemetry-metrics, opentelemetry-node, opentelemetry-propagator-b3, opentelemetry-propagator-jaeger, opentelemetry-resource-detector-aws, opentelemetry-resource-detector-gcp, opentelemetry-resources, opentelemetry-sdk-node, opentelemetry-shim-opentracing, opentelemetry-tracing, opentelemetry-web
  • opentelemetry-instrumentation
    • #2224 feat(opentelemetry-instrumentation): getConfig and setConfig (@mottibec)
  • opentelemetry-core, opentelemetry-instrumentation-http, opentelemetry-propagator-b3, opentelemetry-propagator-jaeger, opentelemetry-tracing
  • opentelemetry-core, opentelemetry-tracing
    • #2100 feat(tracing): allow to configure exporter by environment #1676 (@vmarchaud)
  • opentelemetry-core, opentelemetry-exporter-collector-grpc, opentelemetry-exporter-collector-proto, opentelemetry-exporter-collector
  • opentelemetry-exporter-collector, opentelemetry-exporter-zipkin, opentelemetry-tracing
    • #2183 chore: removing usage of timed event from api (@obecny)
  • Other
    • #2195 fix: remove redundant try-catch from http/https server examples (@legendecas)
  • opentelemetry-exporter-collector-grpc
  • opentelemetry-semantic-conventions
    • #2167 semantic-conventions: include built esm files in package (@t2t2)
  • opentelemetry-instrumentation-xml-http-request
    • #2134 feat(instrumentation-xhr): add applyCustomAttributesOnSpan hook (@mhennoch)
  • opentelemetry-exporter-prometheus
    • #2122 feat: add diag warning when metric name is invalid (@weyert)
  • opentelemetry-api-metrics, opentelemetry-exporter-collector-grpc, opentelemetry-exporter-collector-proto, opentelemetry-exporter-collector, opentelemetry-metrics

:bug: (Bug Fix)

  • opentelemetry-exporter-collector-grpc
  • opentelemetry-tracing
    • #2185 fix: use invalid parent for sampler when options.root (@dyladan)
    • #2171 fix: move initialization of const above first use #2170 (@dyladan)
  • opentelemetry-instrumentation-grpc
  • opentelemetry-core
    • #2165 [sampler] treat invalid SpanContext as no SpanContext (@thisthat)

:books: (Refine Doc)

  • opentelemetry-node
  • Other
  • opentelemetry-instrumentation-fetch, opentelemetry-instrumentation-grpc, opentelemetry-instrumentation-http, opentelemetry-instrumentation-xml-http-request, opentelemetry-instrumentation, opentelemetry-node, opentelemetry-sdk-node, opentelemetry-web
    • #2127 chore: prefer use of global TracerProvider/MeterProvider (@Flarna)

:house: (Internal)

  • opentelemetry-api-metrics, opentelemetry-context-async-hooks, opentelemetry-context-zone-peer-dep, opentelemetry-context-zone, opentelemetry-core, opentelemetry-exporter-collector-grpc, opentelemetry-exporter-collector-proto, opentelemetry-exporter-collector, opentelemetry-exporter-jaeger, opentelemetry-exporter-prometheus, opentelemetry-exporter-zipkin, opentelemetry-instrumentation-fetch, opentelemetry-instrumentation-grpc, opentelemetry-instrumentation-http, opentelemetry-instrumentation-xml-http-request, opentelemetry-instrumentation, opentelemetry-metrics, opentelemetry-node, opentelemetry-propagator-b3, opentelemetry-propagator-jaeger, opentelemetry-resource-detector-aws, opentelemetry-resource-detector-gcp, opentelemetry-resources, opentelemetry-sdk-node, opentelemetry-semantic-conventions, opentelemetry-shim-opentracing, opentelemetry-tracing, opentelemetry-web, template
  • opentelemetry-instrumentation-http, opentelemetry-instrumentation, opentelemetry-tracing
  • opentelemetry-node, opentelemetry-sdk-node, opentelemetry-web
    • #2230 chore: remove references to Noop classes from API (@dyladan)
  • opentelemetry-api-metrics, opentelemetry-context-zone-peer-dep, opentelemetry-context-zone, opentelemetry-core, opentelemetry-exporter-collector, opentelemetry-exporter-zipkin, opentelemetry-instrumentation-fetch, opentelemetry-instrumentation-xml-http-request, opentelemetry-instrumentation, opentelemetry-propagator-jaeger, opentelemetry-tracing, opentelemetry-web
  • opentelemetry-sdk-node
    • #2219 fix(opentelemetry-sdk-node): move nock to dev dependencies (@nflaig)
  • opentelemetry-core
  • opentelemetry-api-metrics, opentelemetry-context-zone-peer-dep, opentelemetry-context-zone, opentelemetry-core, opentelemetry-exporter-collector, opentelemetry-exporter-zipkin, opentelemetry-instrumentation-fetch, opentelemetry-instrumentation-xml-http-request, opentelemetry-instrumentation, opentelemetry-metrics, opentelemetry-propagator-b3, opentelemetry-propagator-jaeger, opentelemetry-resources, opentelemetry-semantic-conventions, opentelemetry-tracing, opentelemetry-web, template
    • #2112 feat: add ESM builds for packages used in browser (@t2t2)

Committers: 18

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/metrics \
    @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/metrics");
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 03 Jun 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