1 | ;
|
2 | /*
|
3 | * Copyright The OpenTelemetry Authors
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * https://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.MetricsAPI = void 0;
|
19 | const NoopMeterProvider_1 = require("../metrics/NoopMeterProvider");
|
20 | const global_utils_1 = require("../internal/global-utils");
|
21 | const diag_1 = require("./diag");
|
22 | const API_NAME = 'metrics';
|
23 | /**
|
24 | * Singleton object which represents the entry point to the OpenTelemetry Metrics API
|
25 | */
|
26 | class MetricsAPI {
|
27 | /** Empty private constructor prevents end users from constructing a new instance of the API */
|
28 | constructor() { }
|
29 | /** Get the singleton instance of the Metrics API */
|
30 | static getInstance() {
|
31 | if (!this._instance) {
|
32 | this._instance = new MetricsAPI();
|
33 | }
|
34 | return this._instance;
|
35 | }
|
36 | /**
|
37 | * Set the current global meter provider.
|
38 | * Returns true if the meter provider was successfully registered, else false.
|
39 | */
|
40 | setGlobalMeterProvider(provider) {
|
41 | return (0, global_utils_1.registerGlobal)(API_NAME, provider, diag_1.DiagAPI.instance());
|
42 | }
|
43 | /**
|
44 | * Returns the global meter provider.
|
45 | */
|
46 | getMeterProvider() {
|
47 | return (0, global_utils_1.getGlobal)(API_NAME) || NoopMeterProvider_1.NOOP_METER_PROVIDER;
|
48 | }
|
49 | /**
|
50 | * Returns a meter from the global meter provider.
|
51 | */
|
52 | getMeter(name, version, options) {
|
53 | return this.getMeterProvider().getMeter(name, version, options);
|
54 | }
|
55 | /** Remove the global meter provider */
|
56 | disable() {
|
57 | (0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
58 | }
|
59 | }
|
60 | exports.MetricsAPI = MetricsAPI;
|
61 | //# sourceMappingURL=metrics.js.map |
\ | No newline at end of file |