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

chore: pipe resource through to MetricRecord #1049

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 packages/opentelemetry-metrics/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
descriptor: this._descriptor,
labels: instrument.getLabels(),
aggregator: instrument.getAggregator(),
resource: this.resource,
}));
}

Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-metrics/src/export/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { ValueType, HrTime, Labels } from '@opentelemetry/api';
import { ExportResult } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';

/** The kind of metric. */
export enum MetricKind {
Expand Down Expand Up @@ -68,6 +69,7 @@ export interface MetricRecord {
readonly descriptor: MetricDescriptor;
readonly labels: Labels;
readonly aggregator: Aggregator;
readonly resource: Resource;
}

export interface MetricDescriptor {
Expand Down
23 changes: 20 additions & 3 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ describe('Meter', () => {
);
});

it('should return counter with resource', () => {
it('should pipe through resource', () => {
const counter = meter.createCounter('name') as CounterMetric;
assert.ok(counter.resource instanceof Resource);

counter.add(1, { foo: 'bar' });

const [record] = counter.getMetricRecord();
assert.ok(record.resource instanceof Resource);
});

describe('.bind()', () => {
Expand Down Expand Up @@ -284,9 +289,14 @@ describe('Meter', () => {
assert.strictEqual((measure as MeasureMetric)['_absolute'], false);
});

it('should return a measure with resource', () => {
it('should pipe through resource', () => {
const measure = meter.createMeasure('name') as MeasureMetric;
assert.ok(measure.resource instanceof Resource);

measure.record(1, { foo: 'bar' });

const [record] = measure.getMetricRecord();
assert.ok(record.resource instanceof Resource);
});

describe('names', () => {
Expand Down Expand Up @@ -487,9 +497,16 @@ describe('Meter', () => {
ensureMetric(metric5);
});

it('should return an observer with resource', () => {
it('should pipe through resource', () => {
const observer = meter.createObserver('name') as ObserverMetric;
assert.ok(observer.resource instanceof Resource);

observer.setCallback(result => {
result.observe(() => 42, { foo: 'bar' });
});

const [record] = observer.getMetricRecord();
assert.ok(record.resource instanceof Resource);
});
});

Expand Down