Skip to content

Commit

Permalink
SDK Resource (#846)
Browse files Browse the repository at this point in the history
* feat: add Resource.empty() method

* feat: add resource to BasicTracerProvider and assign to Spans

* feat: add Resource.createLibraryResource method

* refactor: rename LIBARY_RESOURCE -> TELEMETRY_SDK_RESOURCE

* feat: add resource to ReadableSpan interface

* feat: add Resource to NodeTracerProvider

* feat: add Resource to WebTracerProvider

* refactor: move resource-assertions

* feat: add Resource to instruments

* refactor: add SDK_INFO to core; simplify SDK resource creation

* chore: docs and cleanup

* docs: no need to update the copyright

* chore: move resources to devDependencies where applicable

* refactor: add resource to TraceConfig

* refactor: add resource to MeterConfig

* refactor: change resource visibility on Meter

* refactor: move resource-assertions to test/util
  • Loading branch information
mwear committed Mar 11, 2020
1 parent 69d738c commit abd191b
Show file tree
Hide file tree
Showing 40 changed files with 329 additions and 36 deletions.
4 changes: 4 additions & 0 deletions packages/opentelemetry-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.4.0",
"description": "OpenTelemetry base provides base code for the SDK packages",
"main": "build/src/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

export * from './ExportResult';
export * from './platform';
25 changes: 25 additions & 0 deletions packages/opentelemetry-base/src/platform/browser/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 { VERSION } from '../../version';

/** Constants describing the SDK in use */
export const SDK_INFO = {
NAME: 'opentelemetry',
RUNTIME: 'browser',
LANGUAGE: 'webjs',
VERSION: VERSION,
};
17 changes: 17 additions & 0 deletions packages/opentelemetry-base/src/platform/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* 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.
*/

export * from './constants';
20 changes: 20 additions & 0 deletions packages/opentelemetry-base/src/platform/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* 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.
*/

// Use the node platform by default. The "browser" field of package.json is used
// to override this file to use `./browser/index.ts` when packaged with
// webpack, Rollup, etc.
export * from './node';
25 changes: 25 additions & 0 deletions packages/opentelemetry-base/src/platform/node/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 { VERSION } from '../../version';

/** Constants describing the SDK in use */
export const SDK_INFO = {
NAME: 'opentelemetry',
RUNTIME: 'node',
LANGUAGE: 'nodejs',
VERSION: VERSION,
};
17 changes: 17 additions & 0 deletions packages/opentelemetry-base/src/platform/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* 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.
*/

export * from './constants';
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@opentelemetry/resources": "^0.4.0",
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
"@types/sinon": "^7.0.13",
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-exporter-collector/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { TraceFlags } from '@opentelemetry/api';
import * as core from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import * as transform from '../src/transform';
import * as collectorTypes from '../src/types';
Expand Down Expand Up @@ -68,6 +69,7 @@ export const mockedReadableSpan: ReadableSpan = {
},
],
duration: [0, 8885000],
resource: Resource.empty(),
};

export function ensureSpanIsCorrect(span: collectorTypes.Span) {
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/resources": "^0.4.0",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"codecov": "^3.6.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ThriftProcess } from '../src/types';
import { ReadableSpan } from '@opentelemetry/tracing';
import { ExportResult } from '@opentelemetry/base';
import { TraceFlags } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';

describe('JaegerExporter', () => {
describe('constructor', () => {
Expand Down Expand Up @@ -127,6 +128,7 @@ describe('JaegerExporter', () => {
links: [],
events: [],
duration: [32, 800000000],
resource: Resource.empty(),
};

exporter.export([readableSpan], (result: ExportResult) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as assert from 'assert';
import { spanToThrift } from '../src/transform';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import * as types from '@opentelemetry/api';
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
Expand Down Expand Up @@ -69,6 +70,7 @@ describe('transform', () => {
},
],
duration: [32, 800000000],
resource: Resource.empty(),
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -143,6 +145,7 @@ describe('transform', () => {
links: [],
events: [],
duration: [32, 800000000],
resource: Resource.empty(),
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -207,6 +210,7 @@ describe('transform', () => {
],
events: [],
duration: [32, 800000000],
resource: Resource.empty(),
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -245,6 +249,7 @@ describe('transform', () => {
links: [],
events: [],
duration: [32, 800000000],
resource: Resource.empty(),
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/resources": "^0.4.0",
"@types/mocha": "^5.2.7",
"@types/nock": "^11.1.0",
"@types/node": "^12.6.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { ExportResult } from '@opentelemetry/base';
import { ConsoleLogger, LogLevel } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import * as types from '@opentelemetry/api';
import * as assert from 'assert';
import * as nock from 'nock';
Expand Down Expand Up @@ -121,6 +122,7 @@ describe('Stackdriver Trace Exporter', () => {
isRemote: true,
},
status: { code: types.CanonicalCode.OK },
resource: Resource.empty(),
};

const result = await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('Stackdriver Trace Exporter', () => {
isRemote: true,
},
status: { code: types.CanonicalCode.OK },
resource: Resource.empty(),
};

getClientShouldFail = true;
Expand Down Expand Up @@ -188,6 +191,7 @@ describe('Stackdriver Trace Exporter', () => {
isRemote: true,
},
status: { code: types.CanonicalCode.OK },
resource: Resource.empty(),
};

batchWriteShouldFail = true;
Expand Down Expand Up @@ -219,6 +223,7 @@ describe('Stackdriver Trace Exporter', () => {
isRemote: true,
},
status: { code: types.CanonicalCode.OK },
resource: Resource.empty(),
};

await exporter['_projectId'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { VERSION as CORE_VERSION } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import * as types from '@opentelemetry/api';
import * as assert from 'assert';
import { getReadableSpanTransformer } from '../src/transform';
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('transform', () => {
name: 'my-span',
spanContext,
status: { code: types.CanonicalCode.OK },
resource: Resource.empty(),
};
});

Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/resources": "^0.4.0",
"@types/mocha": "^5.2.7",
"@types/nock": "^10.0.3",
"@types/node": "^12.6.9",
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ReadableSpan } from '@opentelemetry/tracing';
import { ExportResult } from '@opentelemetry/base';
import { NoopLogger, hrTimeToMicroseconds } from '@opentelemetry/core';
import * as types from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { ZipkinExporter } from '../src';
import * as zipkinTypes from '../src/types';
import { OT_REQUEST_HEADER } from '../src/utils';
Expand Down Expand Up @@ -48,6 +49,7 @@ function getReadableSpan() {
attributes: {},
links: [],
events: [],
resource: Resource.empty(),
};
return readableSpan;
}
Expand Down Expand Up @@ -154,6 +156,7 @@ describe('ZipkinExporter', () => {
attributes: { key3: 'value3' },
},
],
resource: Resource.empty(),
};
const span2: ReadableSpan = {
name: 'my-span',
Expand All @@ -173,6 +176,7 @@ describe('ZipkinExporter', () => {
attributes: {},
links: [],
events: [],
resource: Resource.empty(),
};

const exporter = new ZipkinExporter({
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"dependencies": {
"@opentelemetry/api": "^0.4.0",
"@opentelemetry/base": "^0.4.0",
"@opentelemetry/core": "^0.4.0"
"@opentelemetry/core": "^0.4.0",
"@opentelemetry/resources": "^0.4.0"
}
}
14 changes: 11 additions & 3 deletions packages/opentelemetry-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import * as types from '@opentelemetry/api';
import { ConsoleLogger } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { BaseBoundInstrument } from './BoundInstrument';
import { Metric, CounterMetric, MeasureMetric, ObserverMetric } from './Metric';
import {
Expand All @@ -36,6 +37,7 @@ export class Meter implements types.Meter {
private readonly _logger: types.Logger;
private readonly _metrics = new Map<string, Metric<BaseBoundInstrument>>();
private readonly _batcher: Batcher;
private readonly _resource: Resource;
readonly labels = Meter.labels;

/**
Expand All @@ -44,6 +46,7 @@ export class Meter implements types.Meter {
constructor(config: MeterConfig = DEFAULT_CONFIG) {
this._logger = config.logger || new ConsoleLogger(config.logLevel);
this._batcher = new UngroupedBatcher();
this._resource = config.resource || Resource.createTelemetrySDKResource();
// start the push controller
const exporter = config.exporter || new NoopExporter();
const interval = config.interval;
Expand Down Expand Up @@ -73,7 +76,7 @@ export class Meter implements types.Meter {
...options,
};

const measure = new MeasureMetric(name, opt, this._batcher);
const measure = new MeasureMetric(name, opt, this._batcher, this._resource);
this._registerMetric(name, measure);
return measure;
}
Expand Down Expand Up @@ -102,7 +105,7 @@ export class Meter implements types.Meter {
...DEFAULT_METRIC_OPTIONS,
...options,
};
const counter = new CounterMetric(name, opt, this._batcher);
const counter = new CounterMetric(name, opt, this._batcher, this._resource);
this._registerMetric(name, counter);
return counter;
}
Expand All @@ -129,7 +132,12 @@ export class Meter implements types.Meter {
...DEFAULT_METRIC_OPTIONS,
...options,
};
const observer = new ObserverMetric(name, opt, this._batcher);
const observer = new ObserverMetric(
name,
opt,
this._batcher,
this._resource
);
this._registerMetric(name, observer);
return observer;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-metrics/src/MeterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { ConsoleLogger } from '@opentelemetry/core';
import * as types from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { Meter } from '.';
import { DEFAULT_CONFIG, MeterConfig } from './types';

Expand All @@ -24,6 +25,7 @@ import { DEFAULT_CONFIG, MeterConfig } from './types';
*/
export class MeterProvider implements types.MeterProvider {
private readonly _meters: Map<string, Meter> = new Map();
readonly resource: Resource = Resource.createTelemetrySDKResource();
readonly logger: types.Logger;

constructor(private _config: MeterConfig = DEFAULT_CONFIG) {
Expand Down
Loading

0 comments on commit abd191b

Please sign in to comment.