UNPKG

@vtex/api

Version:
39 lines (38 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMetricClient = void 0; const telemetry_1 = require("../telemetry"); class MetricClientSingleton { constructor() { } static getInstance() { if (!MetricClientSingleton.instance) { MetricClientSingleton.instance = new MetricClientSingleton(); } return MetricClientSingleton.instance; } async getClient() { if (this.client) { return this.client; } if (this.initPromise) { return this.initPromise; } this.initPromise = this.initializeClient(); return this.initPromise; } async initializeClient() { try { const { metricsClient } = await (0, telemetry_1.initializeTelemetry)(); this.client = metricsClient; this.initPromise = undefined; return metricsClient; } catch (error) { console.error('Failed to initialize metrics client:', error); this.initPromise = undefined; throw error; } } } const getMetricClient = () => MetricClientSingleton.getInstance().getClient(); exports.getMetricClient = getMetricClient;