Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2

### :rocket: Features

* feat(configuration): add Prometheus exporter support
Comment thread
MikeGoldsmith marked this conversation as resolved.
Outdated
* feat(sampler-composite): add ComposableAnnotatingSampler and ComposableRuleBasedSampler [#6305](https://github.com/open-telemetry/opentelemetry-js/pull/6305) @trentm
* feat(configuration): parse config for rc 3 [#6304](https://github.com/open-telemetry/opentelemetry-js/pull/6304) @maryliag
* feat(instrumentation): use the `internals: true` option with import-in-the-middle hook, allowing instrumentations to hook internal files in ES modules [#6344](https://github.com/open-telemetry/opentelemetry-js/pull/6344) @trentm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
ExporterTemporalityPreference,
initializeDefaultMeterProviderConfiguration,
PeriodicMetricReader,
PullMetricReader,
} from './models/meterProviderModel';
import { OtlpHttpEncoding } from './models/commonModel';
import { diag } from '@opentelemetry/api';
Expand Down Expand Up @@ -360,13 +361,29 @@ export function setMeterProvider(config: ConfigurationModel): void {
}
for (let i = 0; i < exportersType.length; i++) {
const exporterType = exportersType[i];
if (exporterType === 'prometheus') {
// Prometheus uses a pull reader
const pullReader: PullMetricReader = {
exporter: {
'prometheus/development': {
host:
getStringFromEnv('OTEL_EXPORTER_PROMETHEUS_HOST') ?? 'localhost',
port: getNumberFromEnv('OTEL_EXPORTER_PROMETHEUS_PORT') ?? 9464,
without_scope_info: false,
without_target_info: false,
},
},
};
config.meter_provider.readers.push({ pull: pullReader });
continue;
}

const readerPeriodicInfo = { ...readerPeriodic };
const timeout = getNumberFromEnv('OTEL_METRIC_EXPORT_TIMEOUT') ?? 30000;
if (timeout) {
readerPeriodicInfo.timeout = timeout;
}

// TODO: add prometheus exporter support
if (exporterType === 'console') {
readerPeriodicInfo.exporter = { console: {} };
} else {
Expand Down
58 changes: 58 additions & 0 deletions experimental/packages/configuration/test/ConfigFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,64 @@ describe('ConfigFactory', function () {
assert.deepStrictEqual(configFactory.getConfigModel(), expectedConfig);
});

it('should return config with meter_provider with prometheus exporter', function () {
process.env.OTEL_METRICS_EXPORTER = 'prometheus';

const expectedConfig: ConfigurationModel = {
...defaultConfig,
meter_provider: {
readers: [
{
pull: {
exporter: {
'prometheus/development': {
host: 'localhost',
port: 9464,
without_scope_info: false,
without_target_info: false,
},
},
},
},
],
exemplar_filter: ExemplarFilter.TraceBased,
views: [],
},
};
const configFactory = createConfigFactory();
assert.deepStrictEqual(configFactory.getConfigModel(), expectedConfig);
});

it('should return config with meter_provider with prometheus exporter and custom port', function () {
process.env.OTEL_METRICS_EXPORTER = 'prometheus';
process.env.OTEL_EXPORTER_PROMETHEUS_HOST = '0.0.0.0';
process.env.OTEL_EXPORTER_PROMETHEUS_PORT = '8080';

const expectedConfig: ConfigurationModel = {
...defaultConfig,
meter_provider: {
readers: [
{
pull: {
exporter: {
'prometheus/development': {
host: '0.0.0.0',
port: 8080,
without_scope_info: false,
without_target_info: false,
},
},
},
},
],
exemplar_filter: ExemplarFilter.TraceBased,
views: [],
},
};
const configFactory = createConfigFactory();
assert.deepStrictEqual(configFactory.getConfigModel(), expectedConfig);
});

it('should return config with meter_provider with no exporter', function () {
process.env.OTEL_METRICS_EXPORTER = 'none,console';
const configFactory = createConfigFactory();
Expand Down