veryfront 0.1.912 → 0.1.913
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.
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/metrics/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,yBAAyB,CAAC;AAcjC,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAChF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/metrics/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,yBAAyB,CAAC;AAcjC,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAChF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAuWD,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,KAAK,SAAI,EACT,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE,uBAAuB,GAChC,IAAI,CAON;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE,uBAAuB,GAChC,IAAI,CAON;AAED,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE,uBAAuB,GAChC,IAAI,CAaN;AAED,eAAO,MAAM,OAAO;;;;uBAIO,OAAO,CAAC,IAAI,CAAC;uBAGnB,IAAI;CAWxB,CAAC"}
|
package/esm/src/metrics/index.js
CHANGED
|
@@ -113,6 +113,20 @@ function resolveOtlpMetricsUrl() {
|
|
|
113
113
|
const trimmed = endpoint.replace(/\/$/, "");
|
|
114
114
|
return trimmed.endsWith("/v1/metrics") ? trimmed : `${trimmed}/v1/metrics`;
|
|
115
115
|
}
|
|
116
|
+
function resolveInternalMetricsUrl() {
|
|
117
|
+
if (readEnv("OTEL_METRICS_ENABLED") !== "true")
|
|
118
|
+
return null;
|
|
119
|
+
const apiBaseUrl = readEnv("VERYFRONT_API_BASE_URL") ?? readEnv("VERYFRONT_API_URL");
|
|
120
|
+
const username = readEnv("VERYFRONT_API_INTERNAL_USER");
|
|
121
|
+
const password = readEnv("VERYFRONT_API_INTERNAL_PASS");
|
|
122
|
+
if (!apiBaseUrl || !username || !password)
|
|
123
|
+
return null;
|
|
124
|
+
return `${apiBaseUrl.replace(/\/$/, "")}/internal/metrics/otlp/v1/metrics`;
|
|
125
|
+
}
|
|
126
|
+
function buildBasicAuth(username, password) {
|
|
127
|
+
const credentials = `${username}:${password}`;
|
|
128
|
+
return `Basic ${globalThis.btoa(credentials)}`;
|
|
129
|
+
}
|
|
116
130
|
function parseHeaders(headerInput) {
|
|
117
131
|
if (!headerInput)
|
|
118
132
|
return {};
|
|
@@ -130,6 +144,24 @@ function parseHeaders(headerInput) {
|
|
|
130
144
|
}
|
|
131
145
|
return result;
|
|
132
146
|
}
|
|
147
|
+
function resolveDirectMetricsTarget() {
|
|
148
|
+
const internalUrl = resolveInternalMetricsUrl();
|
|
149
|
+
if (internalUrl) {
|
|
150
|
+
return {
|
|
151
|
+
url: internalUrl,
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: buildBasicAuth(readEnv("VERYFRONT_API_INTERNAL_USER") ?? "", readEnv("VERYFRONT_API_INTERNAL_PASS") ?? ""),
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const otlpUrl = resolveOtlpMetricsUrl();
|
|
158
|
+
if (!otlpUrl)
|
|
159
|
+
return null;
|
|
160
|
+
return {
|
|
161
|
+
url: otlpUrl,
|
|
162
|
+
headers: parseHeaders(readEnv("OTEL_EXPORTER_OTLP_HEADERS")),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
133
165
|
function toOtlpValue(value) {
|
|
134
166
|
if (typeof value === "boolean")
|
|
135
167
|
return { boolValue: value };
|
|
@@ -234,17 +266,17 @@ async function flushDirectMetrics() {
|
|
|
234
266
|
clearTimeout(directFlushTimer);
|
|
235
267
|
directFlushTimer = null;
|
|
236
268
|
}
|
|
237
|
-
const
|
|
238
|
-
if (!
|
|
269
|
+
const target = resolveDirectMetricsTarget();
|
|
270
|
+
if (!target || directQueue.length === 0) {
|
|
239
271
|
directQueue.length = 0;
|
|
240
272
|
return;
|
|
241
273
|
}
|
|
242
274
|
const batch = directQueue.splice(0, DIRECT_MAX_BATCH_SIZE);
|
|
243
275
|
try {
|
|
244
|
-
const response = await fetch(url, {
|
|
276
|
+
const response = await fetch(target.url, {
|
|
245
277
|
method: "POST",
|
|
246
278
|
headers: {
|
|
247
|
-
...
|
|
279
|
+
...target.headers,
|
|
248
280
|
"Content-Type": "application/json",
|
|
249
281
|
},
|
|
250
282
|
body: JSON.stringify(buildDirectOtlpBody(batch)),
|
|
@@ -261,7 +293,7 @@ async function flushDirectMetrics() {
|
|
|
261
293
|
}
|
|
262
294
|
}
|
|
263
295
|
function scheduleDirectFlush() {
|
|
264
|
-
if (directFlushTimer ||
|
|
296
|
+
if (directFlushTimer || resolveDirectMetricsTarget() === null)
|
|
265
297
|
return;
|
|
266
298
|
directFlushTimer = dntShim.setTimeout(() => {
|
|
267
299
|
void flushDirectMetrics();
|
|
@@ -279,7 +311,7 @@ function scheduleDirectFlush() {
|
|
|
279
311
|
}
|
|
280
312
|
}
|
|
281
313
|
function enqueueDirectMetric(kind, name, value, attributes) {
|
|
282
|
-
if (
|
|
314
|
+
if (resolveDirectMetricsTarget() === null)
|
|
283
315
|
return;
|
|
284
316
|
directQueue.push({
|
|
285
317
|
kind,
|
|
@@ -296,7 +328,7 @@ function enqueueDirectMetric(kind, name, value, attributes) {
|
|
|
296
328
|
}
|
|
297
329
|
export function counter(name, value = 1, attributes, options) {
|
|
298
330
|
const normalizedAttributes = normalizeAttributes(attributes);
|
|
299
|
-
if (
|
|
331
|
+
if (resolveDirectMetricsTarget() === null) {
|
|
300
332
|
getCounter(name, options)?.add(value, normalizedAttributes);
|
|
301
333
|
return;
|
|
302
334
|
}
|
|
@@ -304,7 +336,7 @@ export function counter(name, value = 1, attributes, options) {
|
|
|
304
336
|
}
|
|
305
337
|
export function histogram(name, value, attributes, options) {
|
|
306
338
|
const normalizedAttributes = normalizeAttributes(attributes);
|
|
307
|
-
if (
|
|
339
|
+
if (resolveDirectMetricsTarget() === null) {
|
|
308
340
|
getHistogram(name, options)?.record(value, normalizedAttributes);
|
|
309
341
|
return;
|
|
310
342
|
}
|
|
@@ -312,7 +344,7 @@ export function histogram(name, value, attributes, options) {
|
|
|
312
344
|
}
|
|
313
345
|
export function gauge(name, value, attributes, options) {
|
|
314
346
|
const normalizedAttributes = normalizeAttributes(attributes);
|
|
315
|
-
if (
|
|
347
|
+
if (resolveDirectMetricsTarget() !== null) {
|
|
316
348
|
enqueueDirectMetric("gauge", name, value, normalizedAttributes);
|
|
317
349
|
return;
|
|
318
350
|
}
|