Skip to content

Commit

Permalink
chore!: split metrics into its own api package (open-telemetry#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent 3104cf4 commit 442517b
Show file tree
Hide file tree
Showing 18 changed files with 5 additions and 908 deletions.
36 changes: 1 addition & 35 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This package provides everything needed to interact with the OpenTelemetry API,

## Quick Start

To get started you need to install the SDK and plugins, create a TracerProvider and/or MeterProvider, and register it with the API.
To get started you need to install the SDK and plugins, create a TracerProvider, and register it with the API.

### Install Dependencies

Expand All @@ -23,11 +23,6 @@ $ npm install \
@opentelemetry/tracing \
@opentelemetry/exporter-jaeger \ # add exporters as needed
@opentelemetry/plugin-http # add plugins as needed

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

> Note: this example is for node.js. See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/tracer-web) for a browser example.
Expand Down Expand Up @@ -74,27 +69,6 @@ tracerProvider.addSpanProcessor(
tracerProvider.register();
```

#### Metrics

```javascript
const api = require("@opentelemetry/api");
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.
Expand Down Expand Up @@ -122,7 +96,6 @@ tracerProvider.register({
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` 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.

- [Trace API Documentation][trace-api-docs]
- [Metrics API Documentation][metrics-api-docs]
- [Propagation API Documentation][propagation-api-docs]
- [Context API Documentation][context-api-docs]

Expand All @@ -136,13 +109,6 @@ api.trace.getTracerProvider();
/* returns a tracer from the registered global tracer provider (no-op if a working provider has not been initialized) */
api.trace.getTracer(name, version);

/* 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);

/* Initialize Propagator */
api.propagation.setGlobalPropagator(httpTraceContextPropagator);

Expand Down
1 change: 0 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"browser",
"tracing",
"profiling",
"metrics",
"stats",
"monitoring"
],
Expand Down
6 changes: 1 addition & 5 deletions api/src/api/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

import { ContextManager } from '@opentelemetry/context-base';
import { TextMapPropagator } from '../context/propagation/TextMapPropagator';
import { MeterProvider } from '../metrics/MeterProvider';
import { TracerProvider } from '../trace/tracer_provider';
import { _globalThis } from '../platform';

export const GLOBAL_CONTEXT_MANAGER_API_KEY = Symbol.for(
'io.opentelemetry.js.api.context'
);
export const GLOBAL_METRICS_API_KEY = Symbol.for(
'io.opentelemetry.js.api.metrics'
);

export const GLOBAL_PROPAGATION_API_KEY = Symbol.for(
'io.opentelemetry.js.api.propagation'
);
Expand All @@ -34,7 +31,6 @@ export const GLOBAL_TRACE_API_KEY = Symbol.for('io.opentelemetry.js.api.trace');
type Get<T> = (version: number) => T;
type OtelGlobal = Partial<{
[GLOBAL_CONTEXT_MANAGER_API_KEY]: Get<ContextManager>;
[GLOBAL_METRICS_API_KEY]: Get<MeterProvider>;
[GLOBAL_PROPAGATION_API_KEY]: Get<TextMapPropagator>;
[GLOBAL_TRACE_API_KEY]: Get<TracerProvider>;
}>;
Expand Down
84 changes: 0 additions & 84 deletions api/src/api/metrics.ts

This file was deleted.

14 changes: 0 additions & 14 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ export * from './context/propagation/TextMapPropagator';
export * from './context/propagation/NoopTextMapPropagator';
export * from './baggage/Baggage';
export * from './baggage/EntryValue';
export * from './metrics/BatchObserverResult';
export * from './metrics/BoundInstrument';
export * from './metrics/Meter';
export * from './metrics/MeterProvider';
export * from './metrics/Metric';
export * from './metrics/NoopMeter';
export * from './metrics/NoopMeterProvider';
export * from './metrics/Observation';
export * from './metrics/ObserverResult';
export * from './trace/attributes';
export * from './trace/Event';
export * from './trace/link_context';
Expand Down Expand Up @@ -78,17 +69,12 @@ import { TraceAPI } from './api/trace';
/** Entrypoint for trace API */
export const trace = TraceAPI.getInstance();

import { MetricsAPI } from './api/metrics';
/** Entrypoint for metrics API */
export const metrics = MetricsAPI.getInstance();

import { PropagationAPI } from './api/propagation';
/** Entrypoint for propagation API */
export const propagation = PropagationAPI.getInstance();

export default {
trace,
metrics,
context,
propagation,
};
31 changes: 0 additions & 31 deletions api/src/metrics/BatchObserverResult.ts

This file was deleted.

38 changes: 0 additions & 38 deletions api/src/metrics/BoundInstrument.ts

This file was deleted.

Loading

0 comments on commit 442517b

Please sign in to comment.