Skip to content

Commit

Permalink
chore: pipe resource through to MetricRecord (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed May 13, 2020
1 parent 6aa8ed4 commit 1827870
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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

0 comments on commit 1827870

Please sign in to comment.