@vtex/api 6.49.8-beta.0 → 6.49.8-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import { Types } from '@vtex/diagnostics-nodejs';
2
- export declare function getLogClient(): Promise<Types.LogClient>;
1
+ import { LogClient } from '@vtex/diagnostics-nodejs/dist/types';
2
+ export declare function getLogClient(account: string, workspace: string, appName: string): Promise<LogClient>;
@@ -1,32 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogClient = void 0;
4
+ const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
4
5
  const telemetry_1 = require("../telemetry");
5
- let client;
6
+ let logClient;
6
7
  let isInitializing = false;
7
8
  let initPromise = undefined;
8
- async function getLogClient() {
9
- if (client) {
10
- return client;
9
+ async function getLogClient(account, workspace, appName) {
10
+ if (logClient) {
11
+ return logClient;
11
12
  }
12
13
  if (initPromise) {
13
14
  return initPromise;
14
15
  }
15
16
  isInitializing = true;
16
- initPromise = initializeClient();
17
+ initPromise = initializeClient(account, workspace, appName);
17
18
  return initPromise;
18
19
  }
19
20
  exports.getLogClient = getLogClient;
20
- async function initializeClient() {
21
+ async function initializeClient(account, workspace, appName) {
21
22
  try {
22
- const { logsClient } = await (0, telemetry_1.initializeTelemetry)();
23
- client = logsClient;
24
- initPromise = undefined;
25
- return logsClient;
23
+ const telemetryClient = await (0, telemetry_1.getTelemetryClient)();
24
+ const logsConfig = diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
25
+ endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
26
+ path: process.env.OTEL_EXPORTER_OTLP_PATH || '/v1/logs',
27
+ protocol: 'http',
28
+ interval: 5,
29
+ timeoutSeconds: 5,
30
+ headers: { 'Content-Type': 'application/json' },
31
+ });
32
+ const logsExporter = diagnostics_nodejs_1.Exporters.CreateExporter(logsConfig, 'otlp');
33
+ await logsExporter.initialize();
34
+ const clientKey = `${account}-${workspace}-${appName}`;
35
+ logClient = await telemetryClient.newLogsClient({
36
+ exporter: logsExporter,
37
+ loggerName: `node-vtex-api-${clientKey}`,
38
+ });
39
+ return logClient;
26
40
  }
27
41
  catch (error) {
28
42
  console.error('Failed to initialize logs client:', error);
29
- initPromise = undefined;
30
43
  throw error;
31
44
  }
32
45
  finally {
@@ -89,7 +89,7 @@ class Logger {
89
89
  setTimeout(() => reject(new Error('Log client initialization timeout')), constants_1.LOG_CLIENT_INIT_TIMEOUT_MS);
90
90
  });
91
91
  this.logClient = await Promise.race([
92
- (0, client_1.getLogClient)(),
92
+ (0, client_1.getLogClient)(this.account, this.workspace, constants_1.APP.NAME),
93
93
  timeoutPromise
94
94
  ]);
95
95
  return this.logClient;
@@ -1,9 +1,3 @@
1
- import { Logs, Metrics, Traces } from '@vtex/diagnostics-nodejs';
2
- interface TelemetryClients {
3
- logsClient: Logs.LogClient;
4
- metricsClient: Metrics.MetricsClient;
5
- tracesClient: Traces.TraceClient;
6
- }
7
- export declare function initializeTelemetry(): Promise<TelemetryClients>;
8
- export declare function resetTelemetry(): void;
9
- export {};
1
+ import { TelemetryClient } from '@vtex/diagnostics-nodejs/dist/telemetry';
2
+ export declare function getTelemetryClient(): Promise<TelemetryClient>;
3
+ export declare function resetTelemetryClient(): void;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetTelemetry = exports.initializeTelemetry = void 0;
3
+ exports.resetTelemetryClient = exports.getTelemetryClient = void 0;
4
4
  const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
5
5
  const constants_1 = require("../../constants");
6
- const CLIENT_NAME = constants_1.APP.NAME || 'node-vtex-api';
7
- const APPLICATION_ID = constants_1.APP.ID || 'vtex-io-app';
8
- const EXPORTER_OTLP_ENDPOINT = process.env.EXPORTER_OTLP_ENDPOINT;
9
6
  class TelemetryClientSingleton {
10
7
  constructor() {
11
8
  this.initializationPromise = undefined;
@@ -16,72 +13,45 @@ class TelemetryClientSingleton {
16
13
  }
17
14
  return TelemetryClientSingleton.instance;
18
15
  }
19
- async initializeTelemetryClients() {
16
+ async initTelemetryClient() {
20
17
  try {
21
- const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)(APPLICATION_ID, CLIENT_NAME, 'node-vtex-api', {
18
+ const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)('node-vtex-api', constants_1.APP.ID || 'vtex-app', {
22
19
  additionalAttrs: {
23
20
  'version': constants_1.APP.VERSION || '',
24
21
  'environment': process.env.VTEX_WORKSPACE || 'development',
25
22
  },
26
23
  });
27
- const tracesClient = await telemetryClient.newTracesClient({
28
- exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateTracesExporterConfig({
29
- endpoint: EXPORTER_OTLP_ENDPOINT,
30
- }), 'otlp'),
31
- });
32
- const metricsClient = await telemetryClient.newMetricsClient({
33
- exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateMetricsExporterConfig({
34
- endpoint: EXPORTER_OTLP_ENDPOINT,
35
- interval: 5,
36
- timeoutSeconds: 5,
37
- }), 'otlp'),
38
- });
39
- const logsClient = await telemetryClient.newLogsClient({
40
- exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
41
- endpoint: EXPORTER_OTLP_ENDPOINT,
42
- }), 'otlp'),
43
- loggerName: `node-vtex-api-${APPLICATION_ID}`,
44
- });
45
- const instrumentations = [
46
- ...diagnostics_nodejs_1.Instrumentation.CommonInstrumentations.minimal(),
47
- ];
48
- telemetryClient.registerInstrumentations(instrumentations);
49
- const clients = {
50
- logsClient,
51
- metricsClient,
52
- tracesClient,
53
- };
54
- this.telemetryClients = clients;
55
- return clients;
24
+ this.telemetryClient = telemetryClient;
25
+ return telemetryClient;
56
26
  }
57
27
  catch (error) {
58
- console.error('Failed to initialize telemetry clients:', error);
28
+ console.error('Failed to initialize telemetry client:', error);
59
29
  throw error;
60
30
  }
61
31
  finally {
62
32
  this.initializationPromise = undefined;
63
33
  }
64
34
  }
65
- async getTelemetryClients() {
66
- if (this.telemetryClients) {
67
- return this.telemetryClients;
35
+ async getClient() {
36
+ if (this.telemetryClient) {
37
+ return this.telemetryClient;
68
38
  }
69
39
  if (this.initializationPromise) {
70
40
  return this.initializationPromise;
71
41
  }
72
- this.initializationPromise = this.initializeTelemetryClients();
42
+ this.initializationPromise = this.initTelemetryClient();
73
43
  return this.initializationPromise;
74
44
  }
75
45
  reset() {
76
- this.telemetryClients = undefined;
46
+ this.telemetryClient = undefined;
77
47
  this.initializationPromise = undefined;
78
48
  }
79
49
  }
80
- async function initializeTelemetry() {
81
- return TelemetryClientSingleton.getInstance().getTelemetryClients();
50
+ async function getTelemetryClient() {
51
+ return TelemetryClientSingleton.getInstance().getClient();
82
52
  }
83
- exports.initializeTelemetry = initializeTelemetry;
84
- function resetTelemetry() {
53
+ exports.getTelemetryClient = getTelemetryClient;
54
+ function resetTelemetryClient() {
85
55
  TelemetryClientSingleton.getInstance().reset();
86
56
  }
87
- exports.resetTelemetry = resetTelemetry;
57
+ exports.resetTelemetryClient = resetTelemetryClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.49.8-beta.0",
3
+ "version": "6.49.8-beta.1",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -49,13 +49,13 @@
49
49
  "dependencies": {
50
50
  "@types/koa": "^2.11.0",
51
51
  "@types/koa-compose": "^3.2.3",
52
- "@vtex/diagnostics-nodejs": "0.1.0-io-beta.19",
52
+ "@vtex/diagnostics-nodejs": "0.1.0-beta.10",
53
53
  "@vtex/node-error-report": "^0.0.3",
54
54
  "@wry/equality": "^0.1.9",
55
55
  "agentkeepalive": "^4.0.2",
56
56
  "apollo-server-errors": "^2.2.1",
57
57
  "archiver": "^3.0.0",
58
- "axios": "^1.8.4",
58
+ "axios": "^1.11.0",
59
59
  "axios-retry": "^3.1.2",
60
60
  "bluebird": "^3.5.4",
61
61
  "chalk": "^2.4.2",
@@ -124,8 +124,5 @@
124
124
  "typemoq": "^2.1.0",
125
125
  "typescript": "^4.4.4",
126
126
  "typescript-json-schema": "^0.52.0"
127
- },
128
- "resolutions": {
129
- "@grpc/grpc-js": "^1.13.4"
130
127
  }
131
128
  }