Skip to content

Commit abd191b

Browse files
authored
SDK Resource (#846)
* 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
1 parent 69d738c commit abd191b

File tree

40 files changed

+329
-36
lines changed

40 files changed

+329
-36
lines changed

packages/opentelemetry-base/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "0.4.0",
44
"description": "OpenTelemetry base provides base code for the SDK packages",
55
"main": "build/src/index.js",
6+
"browser": {
7+
"./src/platform/index.ts": "./src/platform/browser/index.ts",
8+
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
9+
},
610
"types": "build/src/index.d.ts",
711
"repository": "open-telemetry/opentelemetry-js",
812
"scripts": {

packages/opentelemetry-base/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
export * from './ExportResult';
18+
export * from './platform';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2020, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { VERSION } from '../../version';
18+
19+
/** Constants describing the SDK in use */
20+
export const SDK_INFO = {
21+
NAME: 'opentelemetry',
22+
RUNTIME: 'browser',
23+
LANGUAGE: 'webjs',
24+
VERSION: VERSION,
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*!
2+
* Copyright 2020, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export * from './constants';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
* Copyright 2020, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Use the node platform by default. The "browser" field of package.json is used
18+
// to override this file to use `./browser/index.ts` when packaged with
19+
// webpack, Rollup, etc.
20+
export * from './node';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2020, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { VERSION } from '../../version';
18+
19+
/** Constants describing the SDK in use */
20+
export const SDK_INFO = {
21+
NAME: 'opentelemetry',
22+
RUNTIME: 'node',
23+
LANGUAGE: 'nodejs',
24+
VERSION: VERSION,
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*!
2+
* Copyright 2020, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export * from './constants';

packages/opentelemetry-exporter-collector/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@babel/core": "^7.6.0",
53+
"@opentelemetry/resources": "^0.4.0",
5354
"@types/mocha": "^5.2.5",
5455
"@types/node": "^12.6.8",
5556
"@types/sinon": "^7.0.13",

packages/opentelemetry-exporter-collector/test/helper.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { TraceFlags } from '@opentelemetry/api';
1818
import * as core from '@opentelemetry/core';
1919
import { ReadableSpan } from '@opentelemetry/tracing';
20+
import { Resource } from '@opentelemetry/resources';
2021
import * as assert from 'assert';
2122
import * as transform from '../src/transform';
2223
import * as collectorTypes from '../src/types';
@@ -68,6 +69,7 @@ export const mockedReadableSpan: ReadableSpan = {
6869
},
6970
],
7071
duration: [0, 8885000],
72+
resource: Resource.empty(),
7173
};
7274

7375
export function ensureSpanIsCorrect(span: collectorTypes.Span) {

packages/opentelemetry-exporter-jaeger/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"access": "public"
4141
},
4242
"devDependencies": {
43+
"@opentelemetry/resources": "^0.4.0",
4344
"@types/mocha": "^5.2.7",
4445
"@types/node": "^12.6.9",
4546
"codecov": "^3.6.1",

packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ThriftProcess } from '../src/types';
2222
import { ReadableSpan } from '@opentelemetry/tracing';
2323
import { ExportResult } from '@opentelemetry/base';
2424
import { TraceFlags } from '@opentelemetry/api';
25+
import { Resource } from '@opentelemetry/resources';
2526

2627
describe('JaegerExporter', () => {
2728
describe('constructor', () => {
@@ -127,6 +128,7 @@ describe('JaegerExporter', () => {
127128
links: [],
128129
events: [],
129130
duration: [32, 800000000],
131+
resource: Resource.empty(),
130132
};
131133

132134
exporter.export([readableSpan], (result: ExportResult) => {

packages/opentelemetry-exporter-jaeger/test/transform.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import * as assert from 'assert';
1818
import { spanToThrift } from '../src/transform';
1919
import { ReadableSpan } from '@opentelemetry/tracing';
20+
import { Resource } from '@opentelemetry/resources';
2021
import * as types from '@opentelemetry/api';
2122
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
2223
import { hrTimeToMicroseconds } from '@opentelemetry/core';
@@ -69,6 +70,7 @@ describe('transform', () => {
6970
},
7071
],
7172
duration: [32, 800000000],
73+
resource: Resource.empty(),
7274
};
7375

7476
const thriftSpan = spanToThrift(readableSpan);
@@ -143,6 +145,7 @@ describe('transform', () => {
143145
links: [],
144146
events: [],
145147
duration: [32, 800000000],
148+
resource: Resource.empty(),
146149
};
147150

148151
const thriftSpan = spanToThrift(readableSpan);
@@ -207,6 +210,7 @@ describe('transform', () => {
207210
],
208211
events: [],
209212
duration: [32, 800000000],
213+
resource: Resource.empty(),
210214
};
211215

212216
const thriftSpan = spanToThrift(readableSpan);
@@ -245,6 +249,7 @@ describe('transform', () => {
245249
links: [],
246250
events: [],
247251
duration: [32, 800000000],
252+
resource: Resource.empty(),
248253
};
249254

250255
const thriftSpan = spanToThrift(readableSpan);

packages/opentelemetry-exporter-stackdriver-trace/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"access": "public"
4242
},
4343
"devDependencies": {
44+
"@opentelemetry/resources": "^0.4.0",
4445
"@types/mocha": "^5.2.7",
4546
"@types/nock": "^11.1.0",
4647
"@types/node": "^12.6.9",

packages/opentelemetry-exporter-stackdriver-trace/test/exporter.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { ExportResult } from '@opentelemetry/base';
1818
import { ConsoleLogger, LogLevel } from '@opentelemetry/core';
1919
import { ReadableSpan } from '@opentelemetry/tracing';
20+
import { Resource } from '@opentelemetry/resources';
2021
import * as types from '@opentelemetry/api';
2122
import * as assert from 'assert';
2223
import * as nock from 'nock';
@@ -121,6 +122,7 @@ describe('Stackdriver Trace Exporter', () => {
121122
isRemote: true,
122123
},
123124
status: { code: types.CanonicalCode.OK },
125+
resource: Resource.empty(),
124126
};
125127

126128
const result = await new Promise((resolve, reject) => {
@@ -155,6 +157,7 @@ describe('Stackdriver Trace Exporter', () => {
155157
isRemote: true,
156158
},
157159
status: { code: types.CanonicalCode.OK },
160+
resource: Resource.empty(),
158161
};
159162

160163
getClientShouldFail = true;
@@ -188,6 +191,7 @@ describe('Stackdriver Trace Exporter', () => {
188191
isRemote: true,
189192
},
190193
status: { code: types.CanonicalCode.OK },
194+
resource: Resource.empty(),
191195
};
192196

193197
batchWriteShouldFail = true;
@@ -219,6 +223,7 @@ describe('Stackdriver Trace Exporter', () => {
219223
isRemote: true,
220224
},
221225
status: { code: types.CanonicalCode.OK },
226+
resource: Resource.empty(),
222227
};
223228

224229
await exporter['_projectId'];

packages/opentelemetry-exporter-stackdriver-trace/test/transform.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { VERSION as CORE_VERSION } from '@opentelemetry/core';
1818
import { ReadableSpan } from '@opentelemetry/tracing';
19+
import { Resource } from '@opentelemetry/resources';
1920
import * as types from '@opentelemetry/api';
2021
import * as assert from 'assert';
2122
import { getReadableSpanTransformer } from '../src/transform';
@@ -50,6 +51,7 @@ describe('transform', () => {
5051
name: 'my-span',
5152
spanContext,
5253
status: { code: types.CanonicalCode.OK },
54+
resource: Resource.empty(),
5355
};
5456
});
5557

packages/opentelemetry-exporter-zipkin/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"access": "public"
4040
},
4141
"devDependencies": {
42+
"@opentelemetry/resources": "^0.4.0",
4243
"@types/mocha": "^5.2.7",
4344
"@types/nock": "^10.0.3",
4445
"@types/node": "^12.6.9",

packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ReadableSpan } from '@opentelemetry/tracing';
2020
import { ExportResult } from '@opentelemetry/base';
2121
import { NoopLogger, hrTimeToMicroseconds } from '@opentelemetry/core';
2222
import * as types from '@opentelemetry/api';
23+
import { Resource } from '@opentelemetry/resources';
2324
import { ZipkinExporter } from '../src';
2425
import * as zipkinTypes from '../src/types';
2526
import { OT_REQUEST_HEADER } from '../src/utils';
@@ -48,6 +49,7 @@ function getReadableSpan() {
4849
attributes: {},
4950
links: [],
5051
events: [],
52+
resource: Resource.empty(),
5153
};
5254
return readableSpan;
5355
}
@@ -154,6 +156,7 @@ describe('ZipkinExporter', () => {
154156
attributes: { key3: 'value3' },
155157
},
156158
],
159+
resource: Resource.empty(),
157160
};
158161
const span2: ReadableSpan = {
159162
name: 'my-span',
@@ -173,6 +176,7 @@ describe('ZipkinExporter', () => {
173176
attributes: {},
174177
links: [],
175178
events: [],
179+
resource: Resource.empty(),
176180
};
177181

178182
const exporter = new ZipkinExporter({

packages/opentelemetry-metrics/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"dependencies": {
6060
"@opentelemetry/api": "^0.4.0",
6161
"@opentelemetry/base": "^0.4.0",
62-
"@opentelemetry/core": "^0.4.0"
62+
"@opentelemetry/core": "^0.4.0",
63+
"@opentelemetry/resources": "^0.4.0"
6364
}
6465
}

packages/opentelemetry-metrics/src/Meter.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import * as types from '@opentelemetry/api';
1818
import { ConsoleLogger } from '@opentelemetry/core';
19+
import { Resource } from '@opentelemetry/resources';
1920
import { BaseBoundInstrument } from './BoundInstrument';
2021
import { Metric, CounterMetric, MeasureMetric, ObserverMetric } from './Metric';
2122
import {
@@ -36,6 +37,7 @@ export class Meter implements types.Meter {
3637
private readonly _logger: types.Logger;
3738
private readonly _metrics = new Map<string, Metric<BaseBoundInstrument>>();
3839
private readonly _batcher: Batcher;
40+
private readonly _resource: Resource;
3941
readonly labels = Meter.labels;
4042

4143
/**
@@ -44,6 +46,7 @@ export class Meter implements types.Meter {
4446
constructor(config: MeterConfig = DEFAULT_CONFIG) {
4547
this._logger = config.logger || new ConsoleLogger(config.logLevel);
4648
this._batcher = new UngroupedBatcher();
49+
this._resource = config.resource || Resource.createTelemetrySDKResource();
4750
// start the push controller
4851
const exporter = config.exporter || new NoopExporter();
4952
const interval = config.interval;
@@ -73,7 +76,7 @@ export class Meter implements types.Meter {
7376
...options,
7477
};
7578

76-
const measure = new MeasureMetric(name, opt, this._batcher);
79+
const measure = new MeasureMetric(name, opt, this._batcher, this._resource);
7780
this._registerMetric(name, measure);
7881
return measure;
7982
}
@@ -102,7 +105,7 @@ export class Meter implements types.Meter {
102105
...DEFAULT_METRIC_OPTIONS,
103106
...options,
104107
};
105-
const counter = new CounterMetric(name, opt, this._batcher);
108+
const counter = new CounterMetric(name, opt, this._batcher, this._resource);
106109
this._registerMetric(name, counter);
107110
return counter;
108111
}
@@ -129,7 +132,12 @@ export class Meter implements types.Meter {
129132
...DEFAULT_METRIC_OPTIONS,
130133
...options,
131134
};
132-
const observer = new ObserverMetric(name, opt, this._batcher);
135+
const observer = new ObserverMetric(
136+
name,
137+
opt,
138+
this._batcher,
139+
this._resource
140+
);
133141
this._registerMetric(name, observer);
134142
return observer;
135143
}

packages/opentelemetry-metrics/src/MeterProvider.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { ConsoleLogger } from '@opentelemetry/core';
1818
import * as types from '@opentelemetry/api';
19+
import { Resource } from '@opentelemetry/resources';
1920
import { Meter } from '.';
2021
import { DEFAULT_CONFIG, MeterConfig } from './types';
2122

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

2931
constructor(private _config: MeterConfig = DEFAULT_CONFIG) {

0 commit comments

Comments
 (0)