Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api separation #727

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
docs-deploy:
Expand All @@ -178,7 +178,7 @@ jobs:
steps:
- checkout
- attach_workspace:
at: packages/opentelemetry-types/docs
at: packages/opentelemetry-api/docs
- run:
name: Install and configure dependencies
command: |
Expand All @@ -190,7 +190,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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ Maintainers ([@open-telemetry/js-maintainers](https:/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

Expand Down Expand Up @@ -197,5 +197,5 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[otel-shim-opentracing]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-shim-opentracing
[otel-tracing]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing
[otel-web]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-web
[otel-types]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-types
[otel-api]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-api
[otel-core]: https:/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-core
24 changes: 24 additions & 0 deletions packages/opentelemetry-api/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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
}))
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "@opentelemetry/types",
"name": "@opentelemetry/api",
dyladan marked this conversation as resolved.
Show resolved Hide resolved
"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",
Expand Down Expand Up @@ -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"
}
}
}
dyladan marked this conversation as resolved.
Show resolved Hide resolved
59 changes: 59 additions & 0 deletions packages/opentelemetry-api/src/api/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*!
* 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;

private constructor() {}

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);
}
}
59 changes: 59 additions & 0 deletions packages/opentelemetry-api/src/api/trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*!
* 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';

/**
dyladan marked this conversation as resolved.
Show resolved Hide resolved
* 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;

private constructor() {}
dyladan marked this conversation as resolved.
Show resolved Hide resolved

public static getInstance(): TraceAPI {
dyladan marked this conversation as resolved.
Show resolved Hide resolved
if (!this._instance) {
this._instance = new TraceAPI();
}

return this._instance;
}

/**
* Set the current global tracer. Returns the initialized global tracer registry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this function only sets registry, it should have different name then init
Maybe add or set because it doesn't init anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was brought over from the old core package. A rename like this could be discussed though. cc @mayurkale22

*/
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* 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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* 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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ 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';
export const trace = TraceAPI.getInstance();

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

export default {
trace,
metrics,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Loading