Skip to content

Commit

Permalink
feat(open-telemetry-node): Add ObservableGauge
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuin committed Jan 7, 2025
1 parent e528bf4 commit d4c5bb7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Counter, Histogram } from '@opentelemetry/api';
import { Counter, Histogram, ObservableGauge } from '@opentelemetry/api';
import { MetricOptions as OtelMetricOptions } from '@opentelemetry/api';
import { Gauge } from '../metrics/gauge';

export type MetricTypeMap = {
Gauge: Gauge;
Counter: Counter;
Histogram: Histogram;
ObservableGauge: ObservableGauge;
};

export type Metrics = MetricTypeMap[MetricType];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ describe('MetricProvider', () => {
expect(metric1).toBe(metric2);
});
});

it('should return an observable gauge when provided with observable gauge options', () => {
// Arrange
const options: MetricOptions<'ObservableGauge'> = {
name: 'test',
type: 'ObservableGauge'
};

// Act
const metric = metricProvider.getOrCreateMetric(options);

// Assert
expect(metric).toHaveProperty('addCallback');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class MetricProvider {
case 'Histogram':
metric = this.meter.createHistogram(name, opts) as TMetric;
break;
case 'ObservableGauge':
metric = this.meter.createObservableGauge(name, opts) as TMetric;
break;
default:
throw new Error(`Unknown metric type: ${opts.type}`);
}
Expand Down

0 comments on commit d4c5bb7

Please sign in to comment.