-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathmeter_provider.js
More file actions
62 lines (55 loc) · 1.89 KB
/
Copy pathmeter_provider.js
File metadata and controls
62 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
const Meter = require('./meter')
/**
* @typedef {import('@opentelemetry/api').Meter} Meter
* @typedef {import('@opentelemetry/api').MeterOptions} MeterOptions
* @typedef {import('./periodic_metric_reader')} PeriodicMetricReader
*/
/**
* MeterProvider is the main entry point for creating meters with a single reader for Datadog Agent export.
*
* This implementation follows the OpenTelemetry JavaScript API MeterProvider interface:
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api._opentelemetry_api.MeterProvider.html
*
* @class MeterProvider
* @implements {import('@opentelemetry/api').MeterProvider}
*/
class MeterProvider {
#meters = new Map()
/**
* Creates a new MeterProvider instance with a single reader for Datadog Agent export.
*
* @param {MeterOptions} [options] - MeterProvider options
* @param {PeriodicMetricReader} [options.reader] - Single MetricReader instance for
* exporting metrics to Datadog Agent
*/
constructor (options = {}) {
this.reader = options.reader
}
/**
* Gets or creates a meter instance.
*
* @param {string} name - Meter name (case-insensitive)
* @param {string} [version] - Meter version
* @param {MeterOptions} [options] - Additional options
* @returns {Meter} Meter instance
*/
getMeter (name, version = '', { schemaUrl = '', attributes = {} } = {}) {
const normalizedName = name.toLowerCase()
const key = `${normalizedName}@${version}@${schemaUrl}`
let meter = this.#meters.get(key)
if (!meter) {
meter = new Meter(this, { name: normalizedName, version, schemaUrl, attributes })
this.#meters.set(key, meter)
}
return meter
}
/**
* @param {Function} [done] Called after the metric export completes
*/
forceFlush (done) {
if (this.reader) this.reader.forceFlush(done)
else done?.()
}
}
module.exports = MeterProvider