opentelemetry-js
opentelemetry-js copied to clipboard
[draft] feat(sdk-metrics)!: use factory functions over classes
DRAFT: shows how it could look like if we'd use factory functions over class constructors. Currently types of private properties end up being part of the public interface, which causes breaking changes left, right and center. Using a factory function we can only expose what we want the user to use, this enables us to make larger changes to SDK internals without breaking users.
Note: This is combined with #4931 as it also eliminates some classes that we previously exported.
Old:
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto');
const meterProvider = new MeterProvider({
readers: [
new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 1000,
})
]
});
New:
const { createMeterProvider, createPeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto');
const meterProvider = createMeterProvider({
readers: [
createPeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 1000,
})
]
});
For a user it's actually a fairly minimal change but for us it means that we can freely modify the SDK's MeterProvider and all previously unintentionally public referenced and transitively referenced types.