Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console-metric-exporter): add temporality configuration #3387

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Nov 7, 2022

Which problem is this PR solving?

As pointed out by @reyang

I haven't looked deeper so I could be wrong, it seems the ConsoleExporter is only supporting CUMULATIVE?

The specification requires both CUMULATIVE and DELTA to be supported https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/stdout.md#opentelemetry-metrics-exporter---standard-output.

InMemoryExporter seems to be covering both

selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality {
.

Originally posted by @reyang in open-telemetry/community#1204 (comment)

Fixes #3395

Short description of the changes

This PR adds configuration options to allow for both DELTA and CUMULATIVE preference in the ConsoleMetricExporter

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Existing Tests
  • Added Unit Tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@pichlermarc pichlermarc requested a review from a team November 7, 2022 12:24
@pichlermarc pichlermarc marked this pull request as draft November 7, 2022 12:24
@codecov
Copy link

codecov bot commented Nov 7, 2022

Codecov Report

Merging #3387 (4a7676c) into main (74e39c7) will increase coverage by 0.82%.
The diff coverage is 100.00%.

❗ Current head 4a7676c differs from pull request most recent head 921c67f. Consider uploading reports for the commit 921c67f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3387      +/-   ##
==========================================
+ Coverage   92.43%   93.26%   +0.82%     
==========================================
  Files         240      247       +7     
  Lines        6871     7346     +475     
  Branches     1422     1512      +90     
==========================================
+ Hits         6351     6851     +500     
+ Misses        520      495      -25     
Impacted Files Coverage Δ
...es/sdk-metrics/src/export/ConsoleMetricExporter.ts 82.60% <100.00%> (+1.65%) ⬆️
...emetry-instrumentation-xml-http-request/src/xhr.ts 97.58% <0.00%> (ø)
...-instrumentation-fetch/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)
...ry-context-zone-peer-dep/src/ZoneContextManager.ts 85.18% <0.00%> (ø)
...ation-xml-http-request/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)
...mentation-xml-http-request/src/enums/EventNames.ts 100.00% <0.00%> (ø)
...es/opentelemetry-context-zone-peer-dep/src/util.ts 100.00% <0.00%> (ø)
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 97.02% <0.00%> (ø)
packages/opentelemetry-sdk-trace-web/src/utils.ts 95.00% <0.00%> (+29.37%) ⬆️

@pichlermarc pichlermarc force-pushed the feature/console-metrics-exporter-temp branch from dc45af9 to 5e6d2ff Compare November 7, 2022 12:31
@pichlermarc pichlermarc force-pushed the feature/console-metrics-exporter-temp branch from 5e6d2ff to d914b4b Compare November 7, 2022 12:34
Comment on lines 47 to 114
describe('export', () => {
let previousConsoleDir: any;
let exporter: ConsoleMetricExporter;
let meterProvider: MeterProvider;
let meterReader: PeriodicExportingMetricReader;
let meter: metrics.Meter;

beforeEach(() => {
previousConsoleDir = console.dir;
console.dir = () => {};

exporter = new ConsoleMetricExporter();
meterProvider = new MeterProvider({ resource: defaultResource });
meter = meterProvider.getMeter('ConsoleMetricExporter', '1.0.0');
meterReader = new PeriodicExportingMetricReader({
exporter: exporter,
exportIntervalMillis: 100,
exportTimeoutMillis: 100
});
meterProvider.addMetricReader(meterReader);
});
meterProvider.addMetricReader(meterReader);
});

afterEach(async () => {
console.dir = previousConsoleDir;
afterEach(async () => {
console.dir = previousConsoleDir;

await meterReader.shutdown();
});

it('should export information about metric', async () => {
const counter = meter.createCounter('counter_total', {
description: 'a test description',
});
const counterAttribute = { key1: 'attributeValue1' };
counter.add(10, counterAttribute);
counter.add(10, counterAttribute);

const histogram = meter.createHistogram('histogram', { description: 'a histogram' });
histogram.record(10);
histogram.record(100);
histogram.record(1000);

const spyConsole = sinon.spy(console, 'dir');
const spyExport = sinon.spy(exporter, 'export');

await waitForNumberOfExports(spyExport, 1);
const resourceMetrics = spyExport.args[0];
const firstResourceMetric = resourceMetrics[0];
const consoleArgs = spyConsole.args[0];
const consoleMetric = consoleArgs[0];
const keys = Object.keys(consoleMetric).sort().join(',');

await meterReader.shutdown();
const expectedKeys = [
'dataPointType',
'dataPoints',
'descriptor',
].join(',');

assert.ok(firstResourceMetric.resource.attributes.resourceKey === 'my-resource', 'resourceKey');
assert.ok(keys === expectedKeys, 'expectedKeys');
assert.ok(consoleMetric.descriptor.name === 'counter_total', 'name');
assert.ok(consoleMetric.descriptor.description === 'a test description', 'description');
assert.ok(consoleMetric.descriptor.type === 'COUNTER', 'type');
assert.ok(consoleMetric.descriptor.unit === '', 'unit');
assert.ok(consoleMetric.descriptor.valueType === 1, 'valueType');
assert.ok(consoleMetric.dataPoints[0].attributes.key1 === 'attributeValue1', 'ensure metric attributes exists');

assert.ok(spyExport.calledOnce);
});
Copy link
Member Author

@pichlermarc pichlermarc Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code here is not new and has only been moved into a new describe block, as the setup is not needed for the tests that I added.

@pichlermarc pichlermarc marked this pull request as ready for review November 7, 2022 12:53
@dyladan
Copy link
Member

dyladan commented Nov 8, 2022

Looks good. Seems like this just logs directly the data structure as it comes from the SDK so no real "logic" changes required. All temporality except selection is handled by the SDK

@dyladan dyladan merged commit 258b677 into open-telemetry:main Nov 10, 2022
@dyladan dyladan deleted the feature/console-metrics-exporter-temp branch November 10, 2022 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[metric spec review] ConsoleExporter should support delta and cumulative
5 participants