Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Jan 25, 2024
2 parents 82b5d32 + 8648313 commit 51a895d
Show file tree
Hide file tree
Showing 23 changed files with 225 additions and 132 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* feat(sdk-metrics): add constructor option to add metric readers [#4427](https://github.com/open-telemetry/opentelemetry-js/pull/4427) @pichlermarc
* deprecates `MeterProvider.addMetricReader()` please use the constructor option `readers` instead.

### :bug: (Bug Fix)

* fix(sdk-trace-base): ensure attribute value length limit is enforced on span creation [#4417](https://github.com/open-telemetry/opentelemetry-js/pull/4417) @pichlermarc
* fix(sdk-trace-base): Export processed spans while exporter failed [#4287](https://github.com/open-telemetry/opentelemetry-js/pull/4287) @Zirak

### :books: (Refine Doc)

Expand Down
6 changes: 6 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* fix(instrumentation)!: pin import-in-the-middle@1.7.1 [#4441](https://github.com/open-telemetry/opentelemetry-js/pull/4441)
* Fixes a bug where, in some circumstances, ESM instrumentation packages would try to instrument CJS exports on ESM, causing the end-user application to crash.
* This breaking change only affects users that are using the *experimental* `@opentelemetry/instrumentation/hook.mjs` loader hook AND Node.js 18.19 or later:
* This reverts back to an older version of `import-in-the-middle` due to <https://github.com/DataDog/import-in-the-middle/issues/57>
* This version does not support Node.js 18.19 or later

### :rocket: (Enhancement)

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ const testResource = new Resource({
cost: 112.12,
});

let meterProvider = new MeterProvider({ resource: testResource });

let reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
let meterProvider = new MeterProvider({
resource: testResource,
readers: [reader],
});

let meter = meterProvider.getMeter('default', '0.0.1');

Expand All @@ -67,6 +68,7 @@ export async function collect() {
}

export function setUp() {
reader = new TestMetricReader();
meterProvider = new MeterProvider({
resource: testResource,
views: [
Expand All @@ -75,9 +77,8 @@ export function setUp() {
instrumentName: 'int-histogram',
}),
],
readers: [reader],
});
reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
meter = meterProvider.getMeter('default', '0.0.1');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ const defaultResource = Resource.default().merge(
})
);

let meterProvider = new MeterProvider({ resource: defaultResource });
let reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
let meterProvider = new MeterProvider({
resource: defaultResource,
readers: [reader],
});
let meter = meterProvider.getMeter('default', '0.0.1');

export async function collect() {
return (await reader.collect())!;
}

export function setUp(views?: View[]) {
meterProvider = new MeterProvider({ resource: defaultResource, views });
reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
meterProvider = new MeterProvider({
resource: defaultResource,
views,
readers: [reader],
});
meter = meterProvider.getMeter('default', '0.0.1');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ const testResource = new Resource({
cost: 112.12,
});

let meterProvider = new MeterProvider({ resource: testResource });

let reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
let meterProvider = new MeterProvider({
resource: testResource,
readers: [reader],
});

let meter = meterProvider.getMeter('default', '0.0.1');

Expand All @@ -66,6 +67,7 @@ export async function collect() {
}

export function setUp() {
reader = new TestMetricReader();
meterProvider = new MeterProvider({
resource: testResource,
views: [
Expand All @@ -74,9 +76,8 @@ export function setUp() {
instrumentName: 'int-histogram',
}),
],
readers: [reader],
});
reader = new TestMetricReader();
meterProvider.addMetricReader(reader);
meter = meterProvider.getMeter('default', '0.0.1');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ describe('PrometheusExporter', () => {

beforeEach(done => {
exporter = new PrometheusExporter({}, () => {
meterProvider = new MeterProvider();
meterProvider.addMetricReader(exporter);
meterProvider = new MeterProvider({
readers: [exporter],
});
meter = meterProvider.getMeter('test-prometheus', '1');
done();
});
Expand Down Expand Up @@ -533,8 +534,9 @@ describe('PrometheusExporter', () => {
let exporter: PrometheusExporter;

function setup(reader: PrometheusExporter) {
meterProvider = new MeterProvider();
meterProvider.addMetricReader(reader);
meterProvider = new MeterProvider({
readers: [exporter],
});

meter = meterProvider.getMeter('test-prometheus');
counter = meter.createCounter('counter');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const counter = meter.createCounter('test_total');
Expand Down Expand Up @@ -141,8 +141,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const histogram = meter.createHistogram('test');
Expand Down Expand Up @@ -206,8 +206,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const counter = meter.createCounter('test_total', {
Expand Down Expand Up @@ -261,8 +261,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const counter = meter.createUpDownCounter('test_total', {
Expand Down Expand Up @@ -315,8 +315,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const counter = meter.createUpDownCounter('test_total', {
Expand Down Expand Up @@ -369,8 +369,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const histogram = meter.createHistogram('test', {
Expand Down Expand Up @@ -424,8 +424,8 @@ describe('PrometheusSerializer', () => {
instrumentName: '*',
}),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const upDownCounter = meter.createUpDownCounter('test', {
Expand Down Expand Up @@ -474,8 +474,8 @@ describe('PrometheusSerializer', () => {
views: [
new View({ aggregation: new SumAggregation(), instrumentName: '*' }),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const { unit, exportAll = false } = options;
Expand Down Expand Up @@ -563,8 +563,8 @@ describe('PrometheusSerializer', () => {
views: [
new View({ aggregation: new SumAggregation(), instrumentName: '*' }),
],
readers: [reader],
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const counter = meter.createUpDownCounter(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ const protocol = 'http';
const hostname = 'localhost';
const pathname = '/test';
const tracerProvider = new NodeTracerProvider();
const meterProvider = new MeterProvider();
const metricsMemoryExporter = new InMemoryMetricExporter(
AggregationTemporality.DELTA
);
const metricReader = new TestMetricReader(metricsMemoryExporter);
const meterProvider = new MeterProvider({ readers: [metricReader] });

meterProvider.addMetricReader(metricReader);
instrumentation.setTracerProvider(tracerProvider);
instrumentation.setMeterProvider(meterProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"dependencies": {
"@types/shimmer": "^1.0.2",
"import-in-the-middle": "^1.7.2",
"import-in-the-middle": "1.7.1",
"require-in-the-middle": "^7.1.1",
"semver": "^7.5.2",
"shimmer": "^1.2.1"
Expand Down
9 changes: 5 additions & 4 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,16 @@ export class NodeSDK {
}

if (this._meterProviderConfig) {
const readers: MetricReader[] = [];
if (this._meterProviderConfig.reader) {
readers.push(this._meterProviderConfig.reader);
}
const meterProvider = new MeterProvider({
resource: this._resource,
views: this._meterProviderConfig?.views ?? [],
readers: readers,
});

if (this._meterProviderConfig.reader) {
meterProvider.addMetricReader(this._meterProviderConfig.reader);
}

this._meterProvider = meterProvider;

metrics.setGlobalMeterProvider(meterProvider);
Expand Down
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
const flush = () => {
this._isExporting = true;
this._flushOneBatch()
.then(() => {
.finally(() => {
this._isExporting = false;
if (this._finishedSpans.length > 0) {
this._clearTimer();
Expand Down
Loading

0 comments on commit 51a895d

Please sign in to comment.