Api separation (#727)

* feat: create an api package

* chore: update circle for new api package

* chore: bring back getTracer

* chore: add wrongly removed dev dependency

* chore: review comments

* chore: review comments

* chore: lint

* chore: export all noop implementations

* chore: update API README

* chore: ignore known working links that are not yet published

* chore: add jsdoc for getInstance calls

* chore: add jsdoc for private constructors

* chore: review comments

* chore: fix readme npm url

* chore: fix old readmes without registry

* chore: update api calling convention
This commit is contained in:
Daniel Dyla 2020-01-29 16:30:49 -05:00 committed by GitHub
parent 4a83613c5b
commit 5d6c99d126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
200 changed files with 599 additions and 371 deletions

View File

@ -45,7 +45,7 @@ cache_1: &cache_1
- ./yarn.lock
- packages/opentelemetry-base/node_modules
- packages/opentelemetry-scope-base/node_modules
- packages/opentelemetry-types/node_modules
- packages/opentelemetry-api/node_modules
- packages/opentelemetry-scope-async-hooks/node_modules
- packages/opentelemetry-core/node_modules
- packages/opentelemetry-exporter-prometheus/node_modules
@ -169,7 +169,7 @@ jobs:
name: Docs tests
command: yarn docs-test
- persist_to_workspace:
root: packages/opentelemetry-types/docs
root: packages/opentelemetry-api/docs
paths:
- out
- run:
@ -184,7 +184,7 @@ jobs:
steps:
- checkout
- attach_workspace:
at: packages/opentelemetry-types/docs
at: packages/opentelemetry-api/docs
- run:
name: Install and configure dependencies
command: |
@ -196,7 +196,7 @@ jobs:
- "1d:a3:60:b5:b4:8d:e7:8a:96:ce:6a:0a:e9:58:4c:54"
- run:
name: Deploy docs to gh-pages branch
command: gh-pages --dist packages/opentelemetry-types/docs/out
command: gh-pages --dist packages/opentelemetry-api/docs/out
node8:
docker:
- image: node:8

View File

@ -65,7 +65,7 @@ The `opentelemetry-js` project is written in TypeScript.
### Generating API documentation
- `yarn docs` or `npm run docs` to generate API documentation. Generates the documentation in `packages/opentelemetry-types/docs/out`
- `yarn docs` or `npm run docs` to generate API documentation. Generates the documentation in `packages/opentelemetry-api/docs/out`
### Generating CHANGELOG documentation
- `yarn changelog` or `npm run changelog` to generate CHANGELOG documentation in your terminal (see [RELEASING.md](RELEASING.md) for more details).

View File

@ -96,8 +96,8 @@ Maintainers ([@open-telemetry/js-maintainers](https://github.com/orgs/open-telem
| Package | Description |
| ----------------------- | -----------------|
| [@opentelemetry/types][otel-types] | This package provides TypeScript interfaces and enums for the OpenTelemetry core trace and metrics model. It is intended for use both on the server and in the browser. |
| [@opentelemetry/core][otel-core] | This package provides default and no-op implementations of the OpenTelemetry types for trace and metrics. It's intended for use both on the server and in the browser. |
| [@opentelemetry/api][otel-api] | This package provides TypeScript interfaces and enums for the OpenTelemetry core trace and metrics model. It is intended for use both on the server and in the browser. |
| [@opentelemetry/core][otel-core] | This package provides default and no-op implementations of the OpenTelemetry api for trace and metrics. It's intended for use both on the server and in the browser. |
### Implementation / SDKs
@ -195,5 +195,5 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[otel-shim-opentracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-shim-opentracing
[otel-tracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing
[otel-web]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-web
[otel-types]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-types
[otel-api]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-api
[otel-core]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-core

View File

@ -77,4 +77,4 @@ To generate the docs, use:
$ yarn docs
```
The document will be available under `packages/opentelemetry-types/docs/out` path.
The document will be available under `packages/opentelemetry-api/docs/out` path.

View File

@ -23,7 +23,7 @@
"predocs-test": "yarn docs",
"docs-test": "lerna run docs-test",
"docs": "lerna run docs",
"docs-deploy": "gh-pages --dist packages/opentelemetry-types/docs/out",
"docs-deploy": "gh-pages --dist packages/opentelemetry-api/docs/out",
"lint-examples": "eslint ./examples/**/*.js",
"fix-examples": "eslint ./examples/**/*.js --fix"
},

View File

@ -0,0 +1,123 @@
# OpenTelemetry API for JavaScript
[![Gitter chat][gitter-image]][gitter-url]
[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]
This package provides everything needed to interact with the OpenTelemetry API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser.
## Basic Use
### API Entry Point
API entry points are defined as global singleton objects `trace` and `metrics` 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]
```javascript
const api = require("@opentelemetry/api")
/* Initialize TraceRegistry */
api.trace.initGlobalTracerRegistry(traceRegistry);
/* returns traceRegistry (no-op if a working registry has not been initialized) */
api.trace.getTracerRegistry();
/* returns a tracer from the registered global tracer registry (no-op if a working registry has not been initialized); */
api.trace.getTracer(name, version);
/* Initialize MeterRegistry */
api.metrics.initGlobalMeterRegistry(meterRegistry);
/* returns meterRegistry (no-op if a working registry has not been initialized) */
api.metrics.getMeterRegistry();
/* returns a meter from the registered global meter registry (no-op if a working registry has not been initialized); */
api.metrics.getMeter(name, version);
```
### Application Owners
Application owners will also need a working OpenTelemetry SDK implementation. OpenTelemetry provides working SDK implementations for [web] and [node] for both [tracing] and [metrics].
#### Simple NodeJS Example
Before any other module in your application is loaded, you must initialize the global tracer and meter registries. If you fail to initialize a registry, no-op implementations will be provided to any library which acquires them from the API.
```javascript
const api = require("@opentelemetry/api");
const sdk = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
// Initialize an exporter
const exporter = new JaegerExporter({
serviceName: 'basic-service'
});
// Create a registry which we will configure as the global tracer registry
const registry = new sdk.NodeTracerRegistry();
// Configure span processor to send spans to the exporter
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
// Initialize the OpenTelemetry APIs to use the NodeTracerRegistry bindings
api.trace.initGlobalTracerRegistry(registry);
// your application code below this line
```
### Library Authors
Library authors need only to depend on the `@opentelemetry/api` package and trust that the application owners which use their library will initialize an appropriate SDK.
```javascript
const api = require("@opentelemetry/api");
const tracer = api.trace.getTracer("my-library-name", "0.2.3");
async function doSomething() {
const span = tracer.startSpan("doSomething", { parent: tracer.getCurrentSpan() });
try {
const result = await doSomethingElse();
span.end();
return result;
} catch (err) {
span.setStatus({
// use an appropriate status code here
code: api.CanonicalCode.INTERNAL,
message: err.message,
});
span.end();
return null;
}
}
```
## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us on [gitter][gitter-url]
## License
Apache 2.0 - See [LICENSE][license-url] for more information.
[gitter-image]: https://badges.gitter.im/open-telemetry/opentelemetry-js.svg
[gitter-url]: https://gitter.im/open-telemetry/opentelemetry-node?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/master/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/status.svg?path=packages/opentelemetry-api
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-api
[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-api
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-api&type=dev
[npm-url]: https://www.npmjs.com/package/@opentelemetry/api
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Ftypes.svg
[trace-api-docs]: https://open-telemetry.github.io/opentelemetry-js/classes/traceapi.html
[metrics-api-docs]: https://open-telemetry.github.io/opentelemetry-js/classes/metricsapi.html
[web]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-web
[tracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing
[node]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node
[metrics]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics

View File

@ -0,0 +1,24 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');
module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig
}))
};

View File

@ -1,18 +1,22 @@
{
"name": "@opentelemetry/types",
"name": "@opentelemetry/api",
"version": "0.3.3",
"description": "TypeScript types for OpenTelemetry",
"description": "Public API for OpenTelemetry",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json test/**/*.ts",
"test:browser": "nyc karma start --single-run",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"build": "npm run compile",
"check": "gts check",
"precompile": "tsc --version",
"version:update": "node ../../scripts/version-update.js",
"compile": "npm run version:update && tsc -p .",
"fix": "gts fix",
"docs-test": "linkinator docs/out --skip david-dm.org",
"docs-test": "linkinator docs/out --silent --skip david-dm.org --skip https://open-telemetry.github.io/opentelemetry-js/classes/.+api.html",
"docs": "typedoc --tsconfig tsconfig.json",
"prepare": "npm run compile"
},
@ -42,11 +46,27 @@
"access": "public"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.8",
"@types/webpack-env": "1.13.9",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"karma": "^4.4.1",
"linkinator": "^1.5.0",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"ts-loader": "^6.0.4",
"ts-mocha": "^6.0.0",
"tslint-consistent-codestyle": "^1.15.1",
"tslint-microsoft-contrib": "^6.2.0",
"typedoc": "^0.15.0",
"typescript": "3.7.2"
"typescript": "3.7.2",
"webpack": "^4.35.2"
}
}

View File

@ -0,0 +1,61 @@
/*!
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Meter } from '../metrics/Meter';
import { MeterRegistry } from '../metrics/MeterRegistry';
import { NOOP_METER_REGISTRY } from '../metrics/NoopMeterRegistry';
/**
* Singleton object which represents the entry point to the OpenTelemetry Metrics API
*/
export class MetricsAPI {
private static _instance?: MetricsAPI;
private _meterRegistry: MeterRegistry = NOOP_METER_REGISTRY;
/** Empty private constructor prevents end users from constructing a new instance of the API */
private constructor() {}
/** Get the singleton instance of the Metrics API */
public static getInstance(): MetricsAPI {
if (!this._instance) {
this._instance = new MetricsAPI();
}
return this._instance;
}
/**
* Set the current global meter. Returns the initialized global meter registry.
*/
public initGlobalMeterRegistry(registry: MeterRegistry): MeterRegistry {
this._meterRegistry = registry;
return registry;
}
/**
* Returns the global meter registry.
*/
public getMeterRegistry(): MeterRegistry {
return this._meterRegistry;
}
/**
* Returns a meter from the global meter registry.
*/
public getMeter(name: string, version?: string): Meter {
return this.getMeterRegistry().getMeter(name, version);
}
}

View File

@ -0,0 +1,61 @@
/*!
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NOOP_TRACER_REGISTRY } from '../trace/NoopTracerRegistry';
import { TracerRegistry } from '../trace/tracer_registry';
import { Tracer } from '../trace/tracer';
/**
* Singleton object which represents the entry point to the OpenTelemetry Tracing API
*/
export class TraceAPI {
private static _instance?: TraceAPI;
private _tracerRegistry: TracerRegistry = NOOP_TRACER_REGISTRY;
/** Empty private constructor prevents end users from constructing a new instance of the API */
private constructor() {}
/** Get the singleton instance of the Trace API */
public static getInstance(): TraceAPI {
if (!this._instance) {
this._instance = new TraceAPI();
}
return this._instance;
}
/**
* Set the current global tracer. Returns the initialized global tracer registry
*/
public initGlobalTracerRegistry(registry: TracerRegistry): TracerRegistry {
this._tracerRegistry = registry;
return registry;
}
/**
* Returns the global tracer registry.
*/
public getTracerRegistry(): TracerRegistry {
return this._tracerRegistry;
}
/**
* Returns a tracer from the global tracer registry.
*/
public getTracer(name: string, version?: string): Tracer {
return this.getTracerRegistry().getTracer(name, version);
}
}

View File

@ -14,12 +14,13 @@
* limitations under the License.
*/
import { SpanContext, BinaryFormat } from '@opentelemetry/types';
import { SpanContext } from '../../trace/span_context';
import { BinaryFormat } from './BinaryFormat';
/**
* No-op implementations of {@link BinaryFormat}.
*/
class NoopBinaryFormat implements BinaryFormat {
export class NoopBinaryFormat implements BinaryFormat {
private readonly _buff = new ArrayBuffer(0);
// By default does nothing
toBytes(spanContext: SpanContext): ArrayBuffer {

View File

@ -14,12 +14,13 @@
* limitations under the License.
*/
import { HttpTextFormat, SpanContext } from '@opentelemetry/types';
import { SpanContext } from '../../trace/span_context';
import { HttpTextFormat } from './HttpTextFormat';
/**
* No-op implementations of {@link HttpTextFormat}.
*/
class NoopHttpTextFormat implements HttpTextFormat {
export class NoopHttpTextFormat implements HttpTextFormat {
// By default does nothing
inject(spanContext: SpanContext, format: string, carrier: unknown): void {}
// By default does nothing

View File

@ -39,3 +39,21 @@ export * from './trace/tracer';
export * from './trace/tracer_registry';
export * from './trace/trace_flags';
export * from './trace/trace_state';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
export * from './trace/NoopTracerRegistry';
export * from './metrics/NoopMeterRegistry';
export * from './metrics/NoopMeter';
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();
export default {
trace,
metrics,
};

View File

@ -14,19 +14,11 @@
* limitations under the License.
*/
import {
BoundCounter,
DistributedContext,
BoundGauge,
Meter,
Metric,
MetricOptions,
MetricUtils,
BoundMeasure,
SpanContext,
LabelSet,
Labels,
} from '@opentelemetry/types';
import { Meter } from './Meter';
import { MetricOptions, Metric, Labels, LabelSet, MetricUtils } from './Metric';
import { BoundMeasure, BoundCounter, BoundGauge } from './BoundInstrument';
import { DistributedContext } from '../distributed_context/DistributedContext';
import { SpanContext } from '../trace/span_context';
/**
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses constant
@ -165,7 +157,7 @@ export class NoopBoundMeasure implements BoundMeasure {
}
}
export const noopMeter = new NoopMeter();
export const NOOP_METER = new NoopMeter();
export const NOOP_BOUND_GAUGE = new NoopBoundGauge();
export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_BOUND_GAUGE);

View File

@ -14,15 +14,18 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import { noopMeter } from './NoopMeter';
import { Meter } from './Meter';
import { MeterRegistry } from './MeterRegistry';
import { NOOP_METER } from './NoopMeter';
/**
* An implementation of the {@link MeterRegistry} which returns an impotent Meter
* for all calls to `getMeter`
*/
export class NoopMeterRegistry implements types.MeterRegistry {
getMeter(_name?: string, _version?: string): types.Meter {
return noopMeter;
export class NoopMeterRegistry implements MeterRegistry {
getMeter(_name?: string, _version?: string): Meter {
return NOOP_METER;
}
}
export const NOOP_METER_REGISTRY = new NoopMeterRegistry();

View File

@ -14,21 +14,33 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils';
import { TimeInput } from '../common/Time';
import { Attributes } from './attributes';
import { Span } from './span';
import { SpanContext } from './span_context';
import { Status } from './status';
import { TraceFlags } from './trace_flags';
export const INVALID_TRACE_ID = '0';
export const INVALID_SPAN_ID = '0';
const INVALID_SPAN_CONTEXT: SpanContext = {
traceId: INVALID_TRACE_ID,
spanId: INVALID_SPAN_ID,
traceFlags: TraceFlags.UNSAMPLED,
};
/**
* The NoopSpan is the default {@link Span} that is used when no Span
* implementation is available. All operations are no-op including context
* propagation.
*/
export class NoopSpan implements types.Span {
export class NoopSpan implements Span {
constructor(
private readonly _spanContext: types.SpanContext = INVALID_SPAN_CONTEXT
private readonly _spanContext: SpanContext = INVALID_SPAN_CONTEXT
) {}
// Returns a SpanContext.
context(): types.SpanContext {
context(): SpanContext {
return this._spanContext;
}
@ -38,22 +50,22 @@ export class NoopSpan implements types.Span {
}
// By default does nothing
setAttributes(attributes: types.Attributes): this {
setAttributes(attributes: Attributes): this {
return this;
}
// By default does nothing
addEvent(name: string, attributes?: types.Attributes): this {
addEvent(name: string, attributes?: Attributes): this {
return this;
}
// By default does nothing
addLink(spanContext: types.SpanContext, attributes?: types.Attributes): this {
addLink(spanContext: SpanContext, attributes?: Attributes): this {
return this;
}
// By default does nothing
setStatus(status: types.Status): this {
setStatus(status: Status): this {
return this;
}
@ -63,7 +75,7 @@ export class NoopSpan implements types.Span {
}
// By default does nothing
end(endTime?: types.TimeInput): void {}
end(endTime?: TimeInput): void {}
// isRecording always returns false for noopSpan.
isRecording(): boolean {

View File

@ -1,5 +1,5 @@
/*!
* Copyright 2019, OpenTelemetry Authors
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,15 +14,9 @@
* limitations under the License.
*/
import {
Tracer,
SpanOptions,
Span,
HttpTextFormat,
BinaryFormat,
} from '@opentelemetry/types';
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
import { BinaryFormat, HttpTextFormat, Span, SpanOptions, Tracer } from '..';
import { NOOP_BINARY_FORMAT } from '../context/propagation/NoopBinaryFormat';
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
import { NOOP_SPAN } from './NoopSpan';
/**
@ -60,4 +54,4 @@ export class NoopTracer implements Tracer {
}
}
export const noopTracer = new NoopTracer();
export const NOOP_TRACER = new NoopTracer();

View File

@ -14,15 +14,18 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import { noopTracer } from './NoopTracer';
import { NOOP_TRACER } from './NoopTracer';
import { Tracer } from './tracer';
import { TracerRegistry } from './tracer_registry';
/**
* An implementation of the {@link TracerRegistry} which returns an impotent Tracer
* for all calls to `getTracer`
*/
export class NoopTracerRegistry implements types.TracerRegistry {
getTracer(_name?: string, _version?: string): types.Tracer {
return noopTracer;
export class NoopTracerRegistry implements TracerRegistry {
getTracer(_name?: string, _version?: string): Tracer {
return NOOP_TRACER;
}
}
export const NOOP_TRACER_REGISTRY = new NoopTracerRegistry();

View File

@ -15,15 +15,9 @@
*/
import * as assert from 'assert';
import * as types from '@opentelemetry/types';
import {
getTracerRegistry,
initGlobalTracerRegistry,
} from '../../src/trace/globaltracer-utils';
import { NoopTracer, NoopSpan } from '../../src';
import { NoopTracerRegistry } from '../../src/trace/NoopTracerRegistry';
import api, { TraceFlags, NoopSpan, NoopTracerRegistry, NoopTracer, SpanOptions, Span } from '../../src';
describe('globaltracer-utils', () => {
describe('API', () => {
const functions = [
'getCurrentSpan',
'startSpan',
@ -33,7 +27,7 @@ describe('globaltracer-utils', () => {
];
it('should expose a tracer registry via getTracerRegistry', () => {
const tracer = getTracerRegistry();
const tracer = api.trace.getTracerRegistry();
assert.ok(tracer);
assert.strictEqual(typeof tracer, 'object');
});
@ -42,17 +36,17 @@ describe('globaltracer-utils', () => {
const spanContext = {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: '6e0c63257de34c92',
traceFlags: types.TraceFlags.UNSAMPLED,
traceFlags: TraceFlags.UNSAMPLED,
};
const dummySpan = new NoopSpan(spanContext);
afterEach(() => {
initGlobalTracerRegistry(new NoopTracerRegistry());
api.trace.initGlobalTracerRegistry(new NoopTracerRegistry());
});
it('should not crash', () => {
functions.forEach(fn => {
const tracer = getTracerRegistry();
const tracer = api.trace.getTracerRegistry();
try {
((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function
assert.ok(true, fn);
@ -65,8 +59,8 @@ describe('globaltracer-utils', () => {
});
it('should use the global tracer registry', () => {
initGlobalTracerRegistry(new TestTracerRegistry());
const tracer = getTracerRegistry().getTracer('name');
api.trace.initGlobalTracerRegistry(new TestTracerRegistry());
const tracer = api.trace.getTracerRegistry().getTracer('name');
const span = tracer.startSpan('test');
assert.deepStrictEqual(span, dummySpan);
});
@ -74,8 +68,8 @@ describe('globaltracer-utils', () => {
class TestTracer extends NoopTracer {
startSpan(
name: string,
options?: types.SpanOptions | undefined
): types.Span {
options?: SpanOptions | undefined
): Span {
return dummySpan;
}
}

View File

@ -0,0 +1,23 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file is the webpack entry point for the browser Karma tests. It requires
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);
const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);

View File

@ -16,15 +16,16 @@
import * as assert from 'assert';
import {
NOOP_BOUND_GAUGE,
NOOP_GAUGE_METRIC,
Labels,
NoopMeterRegistry,
NOOP_BOUND_COUNTER,
NOOP_COUNTER_METRIC,
NOOP_BOUND_GAUGE,
NOOP_BOUND_MEASURE,
NOOP_MEASURE_METRIC,
} from '../../src/metrics/NoopMeter';
import { Labels } from '@opentelemetry/types';
import { NoopMeterRegistry } from '../../src/metrics/NoopMeterRegistry';
NOOP_COUNTER_METRIC,
NOOP_GAUGE_METRIC,
NOOP_MEASURE_METRIC
} from '../../src';
describe('NoopMeter', () => {
it('should not crash', () => {

View File

@ -15,9 +15,7 @@
*/
import * as assert from 'assert';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { CanonicalCode, TraceFlags } from '@opentelemetry/types';
import { INVALID_TRACEID, INVALID_SPANID } from '../../src';
import { CanonicalCode, INVALID_SPAN_ID, INVALID_TRACE_ID, NoopSpan, TraceFlags } from '../../src';
describe('NoopSpan', () => {
it('do not crash', () => {
@ -53,8 +51,8 @@ describe('NoopSpan', () => {
assert.ok(!span.isRecording());
assert.deepStrictEqual(span.context(), {
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceId: INVALID_TRACE_ID,
spanId: INVALID_SPAN_ID,
traceFlags: TraceFlags.UNSAMPLED,
});
span.end();

View File

@ -15,9 +15,7 @@
*/
import * as assert from 'assert';
import { NoopTracer } from '../../src/trace/NoopTracer';
import { NOOP_SPAN } from '../../src/trace/NoopSpan';
import { SpanKind } from '@opentelemetry/types';
import { NoopTracer, NOOP_SPAN, SpanKind } from '../../src';
describe('NoopTracer', () => {
it('should not crash', () => {

View File

@ -78,7 +78,7 @@
"webpack": "^4.35.2"
},
"dependencies": {
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"semver": "^6.3.0"
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Logger } from '@opentelemetry/types';
import { Logger } from '@opentelemetry/api';
import { LogLevel } from './types';
export class ConsoleLogger implements Logger {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Logger } from '@opentelemetry/types';
import { Logger } from '@opentelemetry/api';
/** No-op implementation of Logger */
export class NoopLogger implements Logger {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { otperformance as performance } from '../platform';
import { TimeOriginLegacy } from './types';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { SpanContext, HttpTextFormat, TraceFlags } from '@opentelemetry/types';
import { SpanContext, HttpTextFormat, TraceFlags } from '@opentelemetry/api';
export const X_B3_TRACE_ID = 'x-b3-traceid';
export const X_B3_SPAN_ID = 'x-b3-spanid';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { BinaryFormat, SpanContext, TraceFlags } from '@opentelemetry/types';
import { BinaryFormat, SpanContext, TraceFlags } from '@opentelemetry/api';
const VERSION_ID = 0;
const TRACE_ID_FIELD_ID = 0;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { HttpTextFormat, SpanContext, TraceFlags } from '@opentelemetry/types';
import { HttpTextFormat, SpanContext, TraceFlags } from '@opentelemetry/api';
import { TraceState } from '../../trace/TraceState';
export const TRACE_PARENT_HEADER = 'traceparent';

View File

@ -23,15 +23,10 @@ export * from './context/propagation/B3Format';
export * from './context/propagation/BinaryTraceContext';
export * from './context/propagation/HttpTraceContext';
export * from './platform';
export * from './trace/globaltracer-utils';
export * from './trace/instrumentation/BasePlugin';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
export * from './trace/NoopTracerRegistry';
export * from './trace/NoRecordingSpan';
export * from './trace/sampler/ProbabilitySampler';
export * from './trace/spancontext-utils';
export * from './trace/TraceState';
export * from './metrics/NoopMeter';
export * from './utils/url';
export * from './utils/wrap';

View File

@ -14,8 +14,7 @@
* limitations under the License.
*/
import { NoopSpan } from './NoopSpan';
import { SpanContext } from '@opentelemetry/types';
import { SpanContext, NoopSpan } from '@opentelemetry/api';
import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils';
/**

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { validateKey, validateValue } from '../internal/validators';
const MAX_TRACE_STATE_ITEMS = 32;

View File

@ -1,45 +0,0 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import { NoopTracerRegistry } from './NoopTracerRegistry';
let globalTracerRegistry: types.TracerRegistry = new NoopTracerRegistry();
/**
* Set the current global tracer. Returns the initialized global tracer
*/
export function initGlobalTracerRegistry(
tracerRegistry: types.TracerRegistry
): types.TracerRegistry {
return (globalTracerRegistry = tracerRegistry);
}
/**
* Returns the global tracer registry.
*/
export function getTracerRegistry(): types.TracerRegistry {
// Return the global tracer registry
return globalTracerRegistry;
}
/**
* Returns a tracer from the global tracer registry.
*/
export function getTracer(name: string, version?: string): types.Tracer {
// Return the global tracer registry
return globalTracerRegistry.getTracer(name, version);
}

View File

@ -22,7 +22,7 @@ import {
PluginInternalFiles,
PluginInternalFilesVersion,
TracerRegistry,
} from '@opentelemetry/types';
} from '@opentelemetry/api';
import * as semver from 'semver';
import * as path from 'path';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Sampler, SpanContext } from '@opentelemetry/types';
import { Sampler, SpanContext } from '@opentelemetry/api';
/** Sampler that samples a given fraction of traces. */
export class ProbabilitySampler implements Sampler {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { SpanContext, TraceFlags } from '@opentelemetry/types';
import { SpanContext, TraceFlags } from '@opentelemetry/api';
export const INVALID_SPANID = '0';
export const INVALID_TRACEID = '0';

View File

@ -17,7 +17,7 @@
import * as assert from 'assert';
import { otperformance as performance } from '../../src/platform';
import * as sinon from 'sinon';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import {
hrTime,
timeInputToHrTime,

View File

@ -21,7 +21,7 @@ import {
X_B3_SPAN_ID,
X_B3_SAMPLED,
} from '../../src/context/propagation/B3Format';
import { SpanContext, TraceFlags } from '@opentelemetry/types';
import { SpanContext, TraceFlags } from '@opentelemetry/api';
import { TraceState } from '../../src/trace/TraceState';
describe('B3Format', () => {

View File

@ -16,7 +16,7 @@
import * as assert from 'assert';
import { BinaryTraceContext } from '../../src/context/propagation/BinaryTraceContext';
import { SpanContext, TraceFlags } from '@opentelemetry/types';
import { SpanContext, TraceFlags } from '@opentelemetry/api';
describe('BinaryTraceContext', () => {
const binaryTraceContext = new BinaryTraceContext();

View File

@ -20,7 +20,7 @@ import {
TRACE_PARENT_HEADER,
TRACE_STATE_HEADER,
} from '../../src/context/propagation/HttpTraceContext';
import { SpanContext, TraceFlags } from '@opentelemetry/types';
import { SpanContext, TraceFlags } from '@opentelemetry/api';
import { TraceState } from '../../src/trace/TraceState';
describe('HttpTraceContext', () => {

View File

@ -14,10 +14,10 @@
* limitations under the License.
*/
import { NoopTracerRegistry } from '@opentelemetry/api';
import * as assert from 'assert';
import * as path from 'path';
import { BasePlugin, NoopLogger } from '../../src';
import { NoopTracerRegistry } from '../../src/trace/NoopTracerRegistry';
import * as types from './fixtures/test-package/foo/bar/internal';
const registry = new NoopTracerRegistry();

View File

@ -16,7 +16,7 @@
import * as assert from 'assert';
import { NoRecordingSpan } from '../../src/trace/NoRecordingSpan';
import { TraceFlags } from '@opentelemetry/types';
import { TraceFlags } from '@opentelemetry/api';
describe('NoRecordingSpan', () => {
it('propagates span contexts', () => {

View File

@ -15,26 +15,26 @@ npm install --save @opentelemetry/exporter-collector
## Usage in Web
```js
import * as opentelemetry from '@opentelemetry/core';
import * as opentelemetry from '@opentelemetry/api';
import { SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { CollectorExporter } from '@opentelemetry/exporter-collector'
const collectorOptions = {
url: '<opentelemetry-collector-url>' // url is optional and can be omitted - default is http://localhost:55678/v1/trace
};
const tracer = new WebTracer();
const registry = new WebTracerRegistry();
const exporter = new CollectorExporter(collectorOptions);
tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
opentelemetry.initGlobalTracer(tracer);
opentelemetry.trace.initGlobalTracerRegistry(registry);
```
## Usage in Node
```js
const opentelemetry = require('@opentelemetry/core');
const opentelemetry = require('@opentelemetry/api');
const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');
@ -46,7 +46,7 @@ const registry = new BasicTracerRegistry();
const exporter = new CollectorExporter(collectorOptions);
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
opentelemetry.initGlobalTracerRegistry(registry);
opentelemetry.trace.initGlobalTracerRegistry(registry);
```

View File

@ -82,6 +82,6 @@
"@opentelemetry/base": "^0.3.3",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3"
"@opentelemetry/api": "^0.3.3"
}
}

View File

@ -17,7 +17,7 @@
import { ExportResult } from '@opentelemetry/base';
import { NoopLogger } from '@opentelemetry/core';
import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import { Attributes, Logger } from '@opentelemetry/types';
import { Attributes, Logger } from '@opentelemetry/api';
import * as collectorTypes from './types';
import { toCollectorSpan } from './transform';
import { onInit, onShutdown, sendSpans } from './platform/index';

View File

@ -15,7 +15,7 @@
*/
import * as core from '@opentelemetry/core';
import { Logger } from '@opentelemetry/types';
import { Logger } from '@opentelemetry/api';
import { CollectorExporter } from '../../CollectorExporter';
import * as collectorTypes from '../../types';
import { VERSION } from '../../version';

View File

@ -16,7 +16,7 @@
import { hexToBase64, hrTimeToTimeStamp } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Attributes, Link, TimedEvent, TraceState } from '@opentelemetry/types';
import { Attributes, Link, TimedEvent, TraceState } from '@opentelemetry/api';
import * as collectorTypes from './types';
const OT_MAX_STRING_LENGTH = 128;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { SpanKind, Status } from '@opentelemetry/types';
import { SpanKind, Status } from '@opentelemetry/api';
// header to prevent instrumentation on request
export const OT_REQUEST_HEADER = 'x-opentelemetry-outgoing-request';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Attributes, TimedEvent } from '@opentelemetry/types';
import { Attributes, TimedEvent } from '@opentelemetry/api';
import * as assert from 'assert';
import * as transform from '../../src/transform';
import { ensureSpanIsCorrect, mockedReadableSpan } from '../helper';

View File

@ -57,7 +57,7 @@
"@opentelemetry/base": "^0.3.3",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"jaeger-client": "^3.15.0"
}
}

View File

@ -14,10 +14,10 @@
* limitations under the License.
*/
import * as api from '@opentelemetry/api';
import { ExportResult } from '@opentelemetry/base';
import { NoopLogger } from '@opentelemetry/core';
import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import * as types from '@opentelemetry/types';
import { Socket } from 'dgram';
import { spanToThrift } from './transform';
import * as jaegerTypes from './types';
@ -26,7 +26,7 @@ import * as jaegerTypes from './types';
* Format and sends span information to Jaeger Exporter.
*/
export class JaegerExporter implements SpanExporter {
private readonly _logger: types.Logger;
private readonly _logger: api.Logger;
private readonly _process: jaegerTypes.ThriftProcess;
private readonly _sender: typeof jaegerTypes.UDPSender;
private readonly _forceFlushOnShutdown: boolean = true;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Link, CanonicalCode, SpanKind } from '@opentelemetry/types';
import { Link, CanonicalCode, SpanKind } from '@opentelemetry/api';
import { ReadableSpan } from '@opentelemetry/tracing';
import {
hrTimeToMilliseconds,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
/**
* Options for Jaeger configuration

View File

@ -17,7 +17,7 @@
import * as assert from 'assert';
import { JaegerExporter } from '../src';
import { NoopLogger } from '@opentelemetry/core';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { ThriftProcess } from '../src/types';
import { ReadableSpan } from '@opentelemetry/tracing';
import { ExportResult } from '@opentelemetry/base';

View File

@ -17,7 +17,7 @@
import * as assert from 'assert';
import { spanToThrift } from '../src/transform';
import { ReadableSpan } from '@opentelemetry/tracing';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
import { hrTimeToMicroseconds } from '@opentelemetry/core';

View File

@ -56,7 +56,7 @@
"@opentelemetry/base": "^0.3.3",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/metrics": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"prom-client": "^11.5.3"
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
/**
* Configuration interface for prometheus exporter

View File

@ -23,7 +23,7 @@ import {
MetricExporter,
ReadableMetric,
} from '@opentelemetry/metrics';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { createServer, IncomingMessage, Server, ServerResponse } from 'http';
import { Counter, Gauge, labelValues, Metric, Registry } from 'prom-client';
import * as url from 'url';

View File

@ -62,7 +62,7 @@
"@opentelemetry/base": "^0.3.3",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"google-auth-library": "^5.7.0",
"googleapis": "^46.0.0"
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Logger } from '@opentelemetry/types';
import { Logger } from '@opentelemetry/api';
export interface StackdriverExporterOptions {
/**

View File

@ -17,7 +17,7 @@
import { ExportResult } from '@opentelemetry/base';
import { NoopLogger } from '@opentelemetry/core';
import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import { Logger } from '@opentelemetry/types';
import { Logger } from '@opentelemetry/api';
import { GoogleAuth } from 'google-auth-library';
import { google } from 'googleapis';
import { StackdriverExporterOptions } from './external-types';

View File

@ -19,7 +19,7 @@ import {
VERSION as CORE_VERSION,
} from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import * as ot from '@opentelemetry/types';
import * as ot from '@opentelemetry/api';
import {
AttributeMap,
Attributes,

View File

@ -17,7 +17,7 @@
import { ExportResult } from '@opentelemetry/base';
import { ConsoleLogger, LogLevel } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import * as assert from 'assert';
import * as nock from 'nock';
import * as sinon from 'sinon';

View File

@ -16,7 +16,7 @@
import { VERSION as CORE_VERSION } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import * as assert from 'assert';
import { getReadableSpanTransformer } from '../src/transform';
import { LinkType, Span } from '../src/types';

View File

@ -58,6 +58,6 @@
"@opentelemetry/base": "^0.3.3",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3"
"@opentelemetry/api": "^0.3.3"
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { ReadableSpan } from '@opentelemetry/tracing';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
import * as zipkinTypes from './types';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
/**
* Exporter config

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';

View File

@ -15,7 +15,7 @@
*/
import * as assert from 'assert';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { Span, BasicTracerRegistry } from '@opentelemetry/tracing';
import {
NoopLogger,

View File

@ -19,7 +19,7 @@ import * as nock from 'nock';
import { ReadableSpan } from '@opentelemetry/tracing';
import { ExportResult } from '@opentelemetry/base';
import { NoopLogger, hrTimeToMicroseconds } from '@opentelemetry/core';
import * as types from '@opentelemetry/types';
import * as types from '@opentelemetry/api';
import { ZipkinExporter } from '../src';
import * as zipkinTypes from '../src/types';
import { OT_REQUEST_HEADER } from '../src/utils';

Some files were not shown because too many files have changed in this diff Show More