@pingops/otel 0.2.6 → 0.3.0
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/dist/index.cjs +121 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +22 -21
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +122 -133
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config.ts","../src/span-processor.ts","../src/tracer-provider.ts","../src/instrumentations/index.ts","../src/instrumentations/http/pingops-http.ts","../src/instrumentations/http/http.ts","../src/instrumentations/undici/types.ts","../src/instrumentations/undici/pingops-undici.ts","../src/instrumentations/undici/undici.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAgBA;AAKA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config.ts","../src/span-processor.ts","../src/tracer-provider.ts","../src/instrumentations/index.ts","../src/instrumentations/http/pingops-http.ts","../src/instrumentations/http/http.ts","../src/instrumentations/undici/types.ts","../src/instrumentations/undici/pingops-undici.ts","../src/instrumentations/undici/undici.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAgBA;AAKA;;;;;AA4GgC,KAjHpB,iBAAA,GAiHoB,WAAA,GAAA,SAAA;;;;ACgBnB,UD5HI,sBAAA,CC4HiB;EAoBZ;;;;EAgNO,UAAA,CAAA,EAAA,MAAA;EAkBF;;;;;;ACpS3B;EA6BgB,OAAA,EAAA,MAAA;EA2EM;;;;EC1LN,KAAA,CAAA,EAAA,OAAA;;;;EC2BH,WAAA,EAAA,MAAA;EAOI;AA0WjB;AAEA;EAIa,gBAAA,CAAA,EAAA,MAAA,EAAA;;;;EC3WG,eAAA,CAAA,EAAA,MAAA,EAAA;EACG;;;EACU,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AA,eG8BrC,cH9BqC,CAAA,SG+B5C,qBH/B4C,CAAA;;sBGiChC,sBAAsB;;EFN/B,WAAA,CAAA,EEQG,mBFHf,CEGmC,WFHnC,CAAA;EAEgB;EA0WJ,YAAA,CAAA,EEvWI,oBFuWqD,CEvWhC,WFuWgC,EEvWnB,YFuWmB,CAAA;EAErD;EAIJ,aAAA,CAAA,EE3WK,qBF2WsB,CE3WA,WF4WjB,CAAA;;;;EC5WP,uBAAA,CAAA,EAAA;IACG,cAAA,CAAA,EAAA,MAAA,EAAA;IAAR,eAAA,CAAA,EAAA,MAAA,EAAA;EACR,CAAA;EAA0B;;;;ECvDZ,kBAAa,CAAA,EAAA,MAAA;EAuBb;AAMjB;AAEA;;EAA4D,mBAAA,CAAA,EAAA,MAAA;;;;cCqD/C,qBAAA,SAA8B,oBAAoB;;;;uBAMzC;;EP7EV,OAAA,CAAA,CAAA,EAAA,IAAA;EAKK,MAAA,CAAA,CAAA,EAAA,IAAA;EAyEG,UAAA,wBAAA,CAAA,CAAA,EAAA,IAAA;EAKD,QAAA,kBAAA;EAMC,QAAA,mBAAA;EAwBL,QAAA,gBAAA;EAAiB,QAAA,gBAAA;;;;ECgBnB,QAAA,eAAqB;EAoBZ,QAAA,UAAA;EAqEN,QAAA,mBAAA;EAAqB,QAAA,qBAAA;EAuCvB,QAAA,gBAAA;;;;;;;;ADjQd;AAKA;AAyEoB,iBQvEJ,2BAAA,CAAA,CRuEI,EQvE2B,qBRuE3B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,11 @@ type PingopsExportMode = "immediate" | "batched";
|
|
|
22
22
|
* Configuration parameters for the PingopsSpanProcessor.
|
|
23
23
|
*/
|
|
24
24
|
interface PingopsProcessorConfig {
|
|
25
|
+
/**
|
|
26
|
+
* PingOps SDK version to attach on exported spans.
|
|
27
|
+
* Intended to be set by @pingops/sdk.
|
|
28
|
+
*/
|
|
29
|
+
sdkVersion?: string;
|
|
25
30
|
/**
|
|
26
31
|
* API key for authentication. Can also be set via PINGOPS_API_KEY environment variable.
|
|
27
32
|
*/
|
|
@@ -62,7 +67,7 @@ interface PingopsProcessorConfig {
|
|
|
62
67
|
* Note: this is the number of raw bytes observed at the instrumentation layer.
|
|
63
68
|
* For compressed bodies, this is the compressed size.
|
|
64
69
|
*
|
|
65
|
-
* @defaultValue
|
|
70
|
+
* @defaultValue 10240 (10 KB)
|
|
66
71
|
*/
|
|
67
72
|
maxRequestBodySize?: number;
|
|
68
73
|
/**
|
|
@@ -72,7 +77,7 @@ interface PingopsProcessorConfig {
|
|
|
72
77
|
* Note: this is the number of raw bytes observed at the instrumentation layer.
|
|
73
78
|
* For compressed bodies, this is the compressed size.
|
|
74
79
|
*
|
|
75
|
-
* @defaultValue
|
|
80
|
+
* @defaultValue 10240 (10 KB)
|
|
76
81
|
*/
|
|
77
82
|
maxResponseBodySize?: number;
|
|
78
83
|
/**
|
|
@@ -198,22 +203,26 @@ declare function getInstrumentations(): Instrumentation[];
|
|
|
198
203
|
declare const PingopsSemanticAttributes: {
|
|
199
204
|
HTTP_REQUEST_BODY: string;
|
|
200
205
|
HTTP_RESPONSE_BODY: string;
|
|
206
|
+
HTTP_REQUEST_BODY_SIZE: string;
|
|
207
|
+
HTTP_RESPONSE_BODY_SIZE: string;
|
|
201
208
|
};
|
|
202
209
|
interface PingopsInstrumentationConfig {
|
|
203
210
|
/**
|
|
204
211
|
* Maximum size of request body to capture in bytes
|
|
205
|
-
* @defaultValue
|
|
212
|
+
* @defaultValue 10240 (10 KB)
|
|
206
213
|
*/
|
|
207
214
|
maxRequestBodySize?: number;
|
|
208
215
|
/**
|
|
209
216
|
* Maximum size of response body to capture in bytes
|
|
210
|
-
* @defaultValue
|
|
217
|
+
* @defaultValue 10240 (10 KB)
|
|
211
218
|
*/
|
|
212
219
|
maxResponseBodySize?: number;
|
|
213
220
|
}
|
|
214
221
|
declare const PingopsHttpSemanticAttributes: {
|
|
215
222
|
HTTP_REQUEST_BODY: string;
|
|
216
223
|
HTTP_RESPONSE_BODY: string;
|
|
224
|
+
HTTP_REQUEST_BODY_SIZE: string;
|
|
225
|
+
HTTP_RESPONSE_BODY_SIZE: string;
|
|
217
226
|
};
|
|
218
227
|
interface PingopsHttpInstrumentationConfig extends HttpInstrumentationConfig, PingopsInstrumentationConfig {}
|
|
219
228
|
declare class PingopsHttpInstrumentation extends HttpInstrumentation {
|
|
@@ -266,21 +275,13 @@ interface UndiciResponse {
|
|
|
266
275
|
statusCode: number;
|
|
267
276
|
statusText: string;
|
|
268
277
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
(span: Span$1, info: {
|
|
277
|
-
request: RequestType;
|
|
278
|
-
response: ResponseType;
|
|
279
|
-
}): void;
|
|
280
|
-
}
|
|
281
|
-
interface StartSpanHookFunction<T = UndiciRequest> {
|
|
282
|
-
(request: T): Attributes;
|
|
283
|
-
}
|
|
278
|
+
type IgnoreRequestFunction<T = UndiciRequest> = (request: T) => boolean;
|
|
279
|
+
type RequestHookFunction<T = UndiciRequest> = (span: Span$1, request: T) => void;
|
|
280
|
+
type ResponseHookFunction<RequestType = UndiciRequest, ResponseType = UndiciResponse> = (span: Span$1, info: {
|
|
281
|
+
request: RequestType;
|
|
282
|
+
response: ResponseType;
|
|
283
|
+
}) => void;
|
|
284
|
+
type StartSpanHookFunction<T = UndiciRequest> = (request: T) => Attributes;
|
|
284
285
|
interface UndiciInstrumentationConfig<RequestType = UndiciRequest, ResponseType = UndiciResponse> extends InstrumentationConfig {
|
|
285
286
|
/** Not trace all outgoing requests that matched with custom function */
|
|
286
287
|
ignoreRequestHook?: IgnoreRequestFunction<RequestType>;
|
|
@@ -299,12 +300,12 @@ interface UndiciInstrumentationConfig<RequestType = UndiciRequest, ResponseType
|
|
|
299
300
|
};
|
|
300
301
|
/**
|
|
301
302
|
* Maximum size of request body to capture in bytes
|
|
302
|
-
* @defaultValue
|
|
303
|
+
* @defaultValue 10240 (10 KB)
|
|
303
304
|
*/
|
|
304
305
|
maxRequestBodySize?: number;
|
|
305
306
|
/**
|
|
306
307
|
* Maximum size of response body to capture in bytes
|
|
307
|
-
* @defaultValue
|
|
308
|
+
* @defaultValue 10240 (10 KB)
|
|
308
309
|
*/
|
|
309
310
|
maxResponseBodySize?: number;
|
|
310
311
|
}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/span-processor.ts","../src/tracer-provider.ts","../src/instrumentations/index.ts","../src/instrumentations/http/pingops-http.ts","../src/instrumentations/http/http.ts","../src/instrumentations/undici/types.ts","../src/instrumentations/undici/pingops-undici.ts","../src/instrumentations/undici/undici.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAgBA;AAKA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/span-processor.ts","../src/tracer-provider.ts","../src/instrumentations/index.ts","../src/instrumentations/http/pingops-http.ts","../src/instrumentations/http/http.ts","../src/instrumentations/undici/types.ts","../src/instrumentations/undici/pingops-undici.ts","../src/instrumentations/undici/undici.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAgBA;AAKA;;;;;AA4GgC,KAjHpB,iBAAA,GAiHoB,WAAA,GAAA,SAAA;;;;ACgBnB,UD5HI,sBAAA,CC4HiB;EAoBZ;;;;EAgNO,UAAA,CAAA,EAAA,MAAA;EAkBF;;;;;;ACpS3B;EA6BgB,OAAA,EAAA,MAAA;EA2EM;;;;EC1LN,KAAA,CAAA,EAAA,OAAA;;;;EC2BH,WAAA,EAAA,MAAA;EAOI;AA0WjB;AAEA;EAIa,gBAAA,CAAA,EAAA,MAAA,EAAA;;;;EC3WG,eAAA,CAAA,EAAA,MAAA,EAAA;EACG;;;EACU,kBAAA,CAAA,EAAA,OAAA;;;;ECvDZ,mBAAa,CAAA,EAAA,OAAA;EAuBb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;EFN/B,WAAA,CAAA,EEQG,mBFHf,CEGmC,WFHnC,CAAA;EAEgB;EA0WJ,YAAA,CAAA,EEvWI,oBFuWqD,CEvWhC,WFuWgC,EEvWnB,YFuWmB,CAAA;EAErD;EAIJ,aAAA,CAAA,EE3WK,qBF2WsB,CE3WA,WF4WjB,CAAA;;;;EC5WP,uBAAA,CAAA,EAAA;IACG,cAAA,CAAA,EAAA,MAAA,EAAA;IAAR,eAAA,CAAA,EAAA,MAAA,EAAA;EACR,CAAA;EAA0B;;;;ECvDZ,kBAAa,CAAA,EAAA,MAAA;EAuBb;AAMjB;AAEA;;EAA4D,mBAAA,CAAA,EAAA,MAAA;;;;cCqD/C,qBAAA,SAA8B,oBAAoB;;;;uBAMzC;;EP7EV,OAAA,CAAA,CAAA,EAAA,IAAA;EAKK,MAAA,CAAA,CAAA,EAAA,IAAA;EAyEG,UAAA,wBAAA,CAAA,CAAA,EAAA,IAAA;EAKD,QAAA,kBAAA;EAMC,QAAA,mBAAA;EAwBL,QAAA,gBAAA;EAAiB,QAAA,gBAAA;;;;ECgBnB,QAAA,eAAqB;EAoBZ,QAAA,UAAA;EAqEN,QAAA,mBAAA;EAAqB,QAAA,qBAAA;EAuCvB,QAAA,gBAAA;;;;;;;;ADjQd;AAKA;AAyEoB,iBQvEJ,2BAAA,CAAA,CRuEI,EQvE2B,qBRuE3B"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BatchSpanProcessor, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
2
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
3
|
-
import { HTTP_RESPONSE_CONTENT_ENCODING, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, bufferToBodyString, createLogger, extractSpanPayload, getHttpUrlFromAttributes, getPropagatedAttributesFromContext, isCompressedContentEncoding, isSpanEligible, shouldCaptureSpan } from "@pingops/core";
|
|
3
|
+
import { HTTP_RESPONSE_CONTENT_ENCODING, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_INTENTIONAL_SUPPRESSION, bufferToBodyString, createLogger, extractDomainFromUrl, extractSpanPayload, getHttpUrlFromAttributes, getPropagatedAttributesFromContext, isCompressedContentEncoding, isSpanEligible, shouldCaptureSpan } from "@pingops/core";
|
|
4
4
|
import { INVALID_SPAN_CONTEXT, ROOT_CONTEXT, SpanKind, SpanStatusCode, ValueType, context, propagation, trace } from "@opentelemetry/api";
|
|
5
5
|
import "@opentelemetry/sdk-trace-node";
|
|
6
6
|
import "@opentelemetry/resources";
|
|
@@ -106,6 +106,7 @@ var PingopsSpanProcessor = class {
|
|
|
106
106
|
});
|
|
107
107
|
this.config = {
|
|
108
108
|
debug: config.debug ?? false,
|
|
109
|
+
sdkVersion: config.sdkVersion,
|
|
109
110
|
headersAllowList: config.headersAllowList,
|
|
110
111
|
headersDenyList: config.headersDenyList,
|
|
111
112
|
domainAllowList: config.domainAllowList,
|
|
@@ -143,6 +144,7 @@ var PingopsSpanProcessor = class {
|
|
|
143
144
|
spanId: spanContext.spanId,
|
|
144
145
|
traceId: spanContext.traceId
|
|
145
146
|
});
|
|
147
|
+
if (this.config.sdkVersion) span.setAttribute("pingops.sdk.version", this.config.sdkVersion);
|
|
146
148
|
const propagatedAttributes = getPropagatedAttributesFromContext(parentContext);
|
|
147
149
|
if (Object.keys(propagatedAttributes).length > 0) {
|
|
148
150
|
for (const [key, value] of Object.entries(propagatedAttributes)) if (typeof value === "string" || Array.isArray(value)) span.setAttribute(key, value);
|
|
@@ -395,6 +397,7 @@ function shouldIgnoreOutboundInstrumentation(requestUrl) {
|
|
|
395
397
|
*/
|
|
396
398
|
function resolveOutboundSpanParentContext(activeContext, requestUrl) {
|
|
397
399
|
if (!isTracingSuppressed(activeContext)) return activeContext;
|
|
400
|
+
if (activeContext.getValue(PINGOPS_INTENTIONAL_SUPPRESSION) === true) return activeContext;
|
|
398
401
|
if (isExporterRequestUrl(requestUrl)) return activeContext;
|
|
399
402
|
if (!hasLoggedSuppressionLeakWarning) {
|
|
400
403
|
logger.warn("Detected suppressed context for outbound user request; running instrumentation on ROOT_CONTEXT to prevent Noop spans from suppression leakage");
|
|
@@ -403,18 +406,74 @@ function resolveOutboundSpanParentContext(activeContext, requestUrl) {
|
|
|
403
406
|
return ROOT_CONTEXT;
|
|
404
407
|
}
|
|
405
408
|
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/instrumentations/body-utils.ts
|
|
411
|
+
const HTTP_REQUEST_BODY = "http.request.body";
|
|
412
|
+
const HTTP_RESPONSE_BODY = "http.response.body";
|
|
413
|
+
const HTTP_REQUEST_BODY_SIZE = "http.request.body.size";
|
|
414
|
+
const HTTP_RESPONSE_BODY_SIZE = "http.response.body.size";
|
|
415
|
+
const DEFAULT_MAX_REQUEST_BODY_SIZE = 10 * 1024;
|
|
416
|
+
const DEFAULT_MAX_RESPONSE_BODY_SIZE = 10 * 1024;
|
|
417
|
+
/**
|
|
418
|
+
* Gets domain rule configuration for a given URL.
|
|
419
|
+
*/
|
|
420
|
+
function getDomainRule(url, domainAllowList) {
|
|
421
|
+
if (!domainAllowList) return;
|
|
422
|
+
const domain = extractDomainFromUrl(url);
|
|
423
|
+
for (const rule of domainAllowList) if (domain === rule.domain || domain.endsWith(`.${rule.domain}`) || domain === rule.domain.slice(1)) return rule;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Determines if request body should be captured based on priority:
|
|
427
|
+
* context > domain rule > global config > default (false).
|
|
428
|
+
*/
|
|
429
|
+
function shouldCaptureRequestBody(url) {
|
|
430
|
+
const contextValue = context.active().getValue(PINGOPS_CAPTURE_REQUEST_BODY);
|
|
431
|
+
if (contextValue !== void 0) return contextValue;
|
|
432
|
+
if (url) {
|
|
433
|
+
const domainRule = getDomainRule(url, getGlobalConfig()?.domainAllowList);
|
|
434
|
+
if (domainRule?.captureRequestBody !== void 0) return domainRule.captureRequestBody;
|
|
435
|
+
}
|
|
436
|
+
const globalConfig$1 = getGlobalConfig();
|
|
437
|
+
if (globalConfig$1?.captureRequestBody !== void 0) return globalConfig$1.captureRequestBody;
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Determines if response body should be captured based on priority:
|
|
442
|
+
* context > domain rule > global config > default (false).
|
|
443
|
+
*/
|
|
444
|
+
function shouldCaptureResponseBody(url) {
|
|
445
|
+
const contextValue = context.active().getValue(PINGOPS_CAPTURE_RESPONSE_BODY);
|
|
446
|
+
if (contextValue !== void 0) return contextValue;
|
|
447
|
+
if (url) {
|
|
448
|
+
const domainRule = getDomainRule(url, getGlobalConfig()?.domainAllowList);
|
|
449
|
+
if (domainRule?.captureResponseBody !== void 0) return domainRule.captureResponseBody;
|
|
450
|
+
}
|
|
451
|
+
const globalConfig$1 = getGlobalConfig();
|
|
452
|
+
if (globalConfig$1?.captureResponseBody !== void 0) return globalConfig$1.captureResponseBody;
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Normalizes supported HTTP chunk types into a Buffer.
|
|
457
|
+
*/
|
|
458
|
+
function toBufferChunk(data) {
|
|
459
|
+
if (typeof data === "string") return Buffer.from(data);
|
|
460
|
+
if (Buffer.isBuffer(data)) return data;
|
|
461
|
+
if (data instanceof Uint8Array) return Buffer.from(data);
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
|
|
406
465
|
//#endregion
|
|
407
466
|
//#region src/instrumentations/http/pingops-http.ts
|
|
408
467
|
/**
|
|
409
468
|
* Pingops HTTP instrumentation that extends HttpInstrumentation
|
|
410
469
|
* with request/response body capture
|
|
411
470
|
*/
|
|
412
|
-
const DEFAULT_MAX_REQUEST_BODY_SIZE$1 = 4 * 1024;
|
|
413
|
-
const DEFAULT_MAX_RESPONSE_BODY_SIZE$1 = 4 * 1024;
|
|
414
471
|
const LEGACY_ATTR_HTTP_URL = "http.url";
|
|
415
472
|
const PingopsSemanticAttributes = {
|
|
416
|
-
HTTP_REQUEST_BODY
|
|
417
|
-
HTTP_RESPONSE_BODY
|
|
473
|
+
HTTP_REQUEST_BODY,
|
|
474
|
+
HTTP_RESPONSE_BODY,
|
|
475
|
+
HTTP_REQUEST_BODY_SIZE,
|
|
476
|
+
HTTP_RESPONSE_BODY_SIZE
|
|
418
477
|
};
|
|
419
478
|
/**
|
|
420
479
|
* Manually flattens a nested object into dot-notation keys
|
|
@@ -427,7 +486,7 @@ function isPrimitiveArray(value) {
|
|
|
427
486
|
}
|
|
428
487
|
function flatten(obj, prefix = "") {
|
|
429
488
|
const result = {};
|
|
430
|
-
for (const key in obj) if (Object.
|
|
489
|
+
for (const key in obj) if (Object.hasOwn(obj, key)) {
|
|
431
490
|
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
432
491
|
const value = obj[key];
|
|
433
492
|
if (isPlainObject(value)) Object.assign(result, flatten(value, newKey));
|
|
@@ -446,61 +505,12 @@ function setAttributeValue(span, attrName, attrValue) {
|
|
|
446
505
|
} else if (isPlainObject(attrValue)) span.setAttributes(flatten({ [attrName]: attrValue }));
|
|
447
506
|
}
|
|
448
507
|
/**
|
|
449
|
-
*
|
|
450
|
-
*/
|
|
451
|
-
function extractDomainFromUrl$1(url) {
|
|
452
|
-
try {
|
|
453
|
-
return new URL(url).hostname;
|
|
454
|
-
} catch {
|
|
455
|
-
const match = url.match(/^(?:https?:\/\/)?([^/]+)/);
|
|
456
|
-
return match ? match[1] : "";
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Gets domain rule configuration for a given URL
|
|
461
|
-
*/
|
|
462
|
-
function getDomainRule$1(url, domainAllowList) {
|
|
463
|
-
if (!domainAllowList) return;
|
|
464
|
-
const domain = extractDomainFromUrl$1(url);
|
|
465
|
-
for (const rule of domainAllowList) if (domain === rule.domain || domain.endsWith(`.${rule.domain}`) || domain === rule.domain.slice(1)) return rule;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Determines if request body should be captured based on priority:
|
|
469
|
-
* context > domain rule > global config > default (false)
|
|
470
|
-
*/
|
|
471
|
-
function shouldCaptureRequestBody$1(url) {
|
|
472
|
-
const contextValue = context.active().getValue(PINGOPS_CAPTURE_REQUEST_BODY);
|
|
473
|
-
if (contextValue !== void 0) return contextValue;
|
|
474
|
-
if (url) {
|
|
475
|
-
const domainRule = getDomainRule$1(url, getGlobalConfig()?.domainAllowList);
|
|
476
|
-
if (domainRule?.captureRequestBody !== void 0) return domainRule.captureRequestBody;
|
|
477
|
-
}
|
|
478
|
-
const globalConfig$1 = getGlobalConfig();
|
|
479
|
-
if (globalConfig$1?.captureRequestBody !== void 0) return globalConfig$1.captureRequestBody;
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Determines if response body should be captured based on priority:
|
|
484
|
-
* context > domain rule > global config > default (false)
|
|
485
|
-
*/
|
|
486
|
-
function shouldCaptureResponseBody$1(url) {
|
|
487
|
-
const contextValue = context.active().getValue(PINGOPS_CAPTURE_RESPONSE_BODY);
|
|
488
|
-
if (contextValue !== void 0) return contextValue;
|
|
489
|
-
if (url) {
|
|
490
|
-
const domainRule = getDomainRule$1(url, getGlobalConfig()?.domainAllowList);
|
|
491
|
-
if (domainRule?.captureResponseBody !== void 0) return domainRule.captureResponseBody;
|
|
492
|
-
}
|
|
493
|
-
const globalConfig$1 = getGlobalConfig();
|
|
494
|
-
if (globalConfig$1?.captureResponseBody !== void 0) return globalConfig$1.captureResponseBody;
|
|
495
|
-
return false;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Captures request body from string or Buffer data
|
|
508
|
+
* Captures request body from a chunk buffer.
|
|
499
509
|
*/
|
|
500
510
|
function captureRequestBody(span, data, maxSize, semanticAttr, url) {
|
|
501
|
-
if (!shouldCaptureRequestBody
|
|
511
|
+
if (!shouldCaptureRequestBody(url)) return;
|
|
502
512
|
if (data.length && data.length <= maxSize) try {
|
|
503
|
-
const requestBody =
|
|
513
|
+
const requestBody = data.toString("utf-8");
|
|
504
514
|
if (requestBody) setAttributeValue(span, semanticAttr, requestBody);
|
|
505
515
|
} catch (e) {
|
|
506
516
|
console.error("Error occurred while capturing request body:", e);
|
|
@@ -510,12 +520,12 @@ function captureRequestBody(span, data, maxSize, semanticAttr, url) {
|
|
|
510
520
|
* Captures response body from chunks
|
|
511
521
|
*/
|
|
512
522
|
function captureResponseBody(span, chunks, semanticAttr, responseHeaders, url, maxSize) {
|
|
513
|
-
if (!shouldCaptureResponseBody
|
|
523
|
+
if (!shouldCaptureResponseBody(url)) return;
|
|
514
524
|
if (chunks === null) {
|
|
515
525
|
const contentEncoding = responseHeaders?.["content-encoding"];
|
|
516
526
|
const contentType = responseHeaders?.["content-type"];
|
|
517
527
|
const toHeaderString = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.join(", ") : "unknown";
|
|
518
|
-
setAttributeValue(span, semanticAttr, `[truncated response body; exceeded maxResponseBodySize=${maxSize ?? DEFAULT_MAX_RESPONSE_BODY_SIZE
|
|
528
|
+
setAttributeValue(span, semanticAttr, `[truncated response body; exceeded maxResponseBodySize=${maxSize ?? DEFAULT_MAX_RESPONSE_BODY_SIZE}; content-type=${toHeaderString(contentType)}; content-encoding=${toHeaderString(contentEncoding)}]`);
|
|
519
529
|
return;
|
|
520
530
|
}
|
|
521
531
|
if (chunks.length) try {
|
|
@@ -634,7 +644,9 @@ var PingopsHttpInstrumentation = class extends HttpInstrumentation {
|
|
|
634
644
|
const headers = extractRequestHeaders(request);
|
|
635
645
|
if (headers) captureRequestHeaders(span, headers);
|
|
636
646
|
if (request instanceof ClientRequest) {
|
|
637
|
-
const maxRequestBodySize = config?.maxRequestBodySize || DEFAULT_MAX_REQUEST_BODY_SIZE
|
|
647
|
+
const maxRequestBodySize = config?.maxRequestBodySize || DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
648
|
+
let requestBodySize = 0;
|
|
649
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);
|
|
638
650
|
const hostHeader = request.getHeader("host");
|
|
639
651
|
const host = typeof hostHeader === "string" ? hostHeader : Array.isArray(hostHeader) ? hostHeader.join(",") : typeof hostHeader === "number" ? String(hostHeader) : void 0;
|
|
640
652
|
const url = request.path && host ? `${request.protocol || "http:"}//${host}${request.path}` : void 0;
|
|
@@ -647,11 +659,21 @@ var PingopsHttpInstrumentation = class extends HttpInstrumentation {
|
|
|
647
659
|
const originalWrite = request.write.bind(request);
|
|
648
660
|
const originalEnd = request.end.bind(request);
|
|
649
661
|
request.write = ((data, ...rest) => {
|
|
650
|
-
|
|
662
|
+
const chunkBuffer = toBufferChunk(data);
|
|
663
|
+
if (chunkBuffer) {
|
|
664
|
+
requestBodySize += chunkBuffer.length;
|
|
665
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);
|
|
666
|
+
captureRequestBody(span, chunkBuffer, maxRequestBodySize, PingopsSemanticAttributes.HTTP_REQUEST_BODY, url);
|
|
667
|
+
}
|
|
651
668
|
return originalWrite(data, ...rest);
|
|
652
669
|
});
|
|
653
670
|
request.end = ((data, ...rest) => {
|
|
654
|
-
|
|
671
|
+
const chunkBuffer = toBufferChunk(data);
|
|
672
|
+
if (chunkBuffer) {
|
|
673
|
+
requestBodySize += chunkBuffer.length;
|
|
674
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);
|
|
675
|
+
captureRequestBody(span, chunkBuffer, maxRequestBodySize, PingopsSemanticAttributes.HTTP_REQUEST_BODY, url);
|
|
676
|
+
}
|
|
655
677
|
return originalEnd(data, ...rest);
|
|
656
678
|
});
|
|
657
679
|
}
|
|
@@ -669,19 +691,19 @@ var PingopsHttpInstrumentation = class extends HttpInstrumentation {
|
|
|
669
691
|
span.setAttribute(ATTR_URL_PATH, path);
|
|
670
692
|
if (query) span.setAttribute(ATTR_URL_QUERY, query);
|
|
671
693
|
}
|
|
672
|
-
const maxResponseBodySize = config?.maxResponseBodySize || DEFAULT_MAX_RESPONSE_BODY_SIZE
|
|
694
|
+
const maxResponseBodySize = config?.maxResponseBodySize || DEFAULT_MAX_RESPONSE_BODY_SIZE;
|
|
673
695
|
const url = response.url || void 0;
|
|
674
696
|
let chunks = [];
|
|
675
697
|
let totalSize = 0;
|
|
676
|
-
|
|
698
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 0);
|
|
699
|
+
const shouldCapture = shouldCaptureResponseBody(url);
|
|
677
700
|
response.prependListener("data", (chunk) => {
|
|
678
|
-
if (!chunk
|
|
679
|
-
|
|
680
|
-
if (typeof chunk === "string") chunkBuffer = Buffer.from(chunk);
|
|
681
|
-
else if (Buffer.isBuffer(chunk)) chunkBuffer = chunk;
|
|
682
|
-
else if (chunk instanceof Uint8Array) chunkBuffer = Buffer.from(chunk);
|
|
701
|
+
if (!chunk) return;
|
|
702
|
+
const chunkBuffer = toBufferChunk(chunk);
|
|
683
703
|
if (!chunkBuffer) return;
|
|
684
704
|
totalSize += chunkBuffer.length;
|
|
705
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_RESPONSE_BODY_SIZE, totalSize);
|
|
706
|
+
if (!shouldCapture) return;
|
|
685
707
|
if (chunks && totalSize <= maxResponseBodySize) chunks.push(chunkBuffer);
|
|
686
708
|
else chunks = null;
|
|
687
709
|
});
|
|
@@ -689,6 +711,7 @@ var PingopsHttpInstrumentation = class extends HttpInstrumentation {
|
|
|
689
711
|
const finalizeCapture = () => {
|
|
690
712
|
if (finalized) return;
|
|
691
713
|
finalized = true;
|
|
714
|
+
span.setAttribute(PingopsSemanticAttributes.HTTP_RESPONSE_BODY_SIZE, totalSize);
|
|
692
715
|
captureResponseBody(span, chunks, PingopsSemanticAttributes.HTTP_RESPONSE_BODY, headers, url, maxResponseBodySize);
|
|
693
716
|
};
|
|
694
717
|
response.prependOnceListener("end", finalizeCapture);
|
|
@@ -737,59 +760,6 @@ function createHttpInstrumentation(config) {
|
|
|
737
760
|
|
|
738
761
|
//#endregion
|
|
739
762
|
//#region src/instrumentations/undici/pingops-undici.ts
|
|
740
|
-
const DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024;
|
|
741
|
-
const DEFAULT_MAX_RESPONSE_BODY_SIZE = 4 * 1024;
|
|
742
|
-
const HTTP_REQUEST_BODY = "http.request.body";
|
|
743
|
-
const HTTP_RESPONSE_BODY = "http.response.body";
|
|
744
|
-
/**
|
|
745
|
-
* Extracts domain from URL
|
|
746
|
-
*/
|
|
747
|
-
function extractDomainFromUrl(url) {
|
|
748
|
-
try {
|
|
749
|
-
return new URL$1(url).hostname;
|
|
750
|
-
} catch {
|
|
751
|
-
const match = url.match(/^(?:https?:\/\/)?([^/]+)/);
|
|
752
|
-
return match ? match[1] : "";
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* Gets domain rule configuration for a given URL
|
|
757
|
-
*/
|
|
758
|
-
function getDomainRule(url, domainAllowList) {
|
|
759
|
-
if (!domainAllowList) return;
|
|
760
|
-
const domain = extractDomainFromUrl(url);
|
|
761
|
-
for (const rule of domainAllowList) if (domain === rule.domain || domain.endsWith(`.${rule.domain}`) || domain === rule.domain.slice(1)) return rule;
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Determines if request body should be captured based on priority:
|
|
765
|
-
* context > domain rule > global config > default (false)
|
|
766
|
-
*/
|
|
767
|
-
function shouldCaptureRequestBody(url) {
|
|
768
|
-
const contextValue = context.active().getValue(PINGOPS_CAPTURE_REQUEST_BODY);
|
|
769
|
-
if (contextValue !== void 0) return contextValue;
|
|
770
|
-
if (url) {
|
|
771
|
-
const domainRule = getDomainRule(url, getGlobalConfig()?.domainAllowList);
|
|
772
|
-
if (domainRule?.captureRequestBody !== void 0) return domainRule.captureRequestBody;
|
|
773
|
-
}
|
|
774
|
-
const globalConfig$1 = getGlobalConfig();
|
|
775
|
-
if (globalConfig$1?.captureRequestBody !== void 0) return globalConfig$1.captureRequestBody;
|
|
776
|
-
return false;
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Determines if response body should be captured based on priority:
|
|
780
|
-
* context > domain rule > global config > default (false)
|
|
781
|
-
*/
|
|
782
|
-
function shouldCaptureResponseBody(url) {
|
|
783
|
-
const contextValue = context.active().getValue(PINGOPS_CAPTURE_RESPONSE_BODY);
|
|
784
|
-
if (contextValue !== void 0) return contextValue;
|
|
785
|
-
if (url) {
|
|
786
|
-
const domainRule = getDomainRule(url, getGlobalConfig()?.domainAllowList);
|
|
787
|
-
if (domainRule?.captureResponseBody !== void 0) return domainRule.captureResponseBody;
|
|
788
|
-
}
|
|
789
|
-
const globalConfig$1 = getGlobalConfig();
|
|
790
|
-
if (globalConfig$1?.captureResponseBody !== void 0) return globalConfig$1.captureResponseBody;
|
|
791
|
-
return false;
|
|
792
|
-
}
|
|
793
763
|
var UndiciInstrumentation = class extends InstrumentationBase {
|
|
794
764
|
_recordFromReq = /* @__PURE__ */ new WeakMap();
|
|
795
765
|
constructor(config = {}) {
|
|
@@ -897,7 +867,9 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
897
867
|
[ATTR_URL_FULL]: requestUrl.toString(),
|
|
898
868
|
[ATTR_URL_PATH]: requestUrl.pathname,
|
|
899
869
|
[ATTR_URL_QUERY]: requestUrl.search,
|
|
900
|
-
[ATTR_URL_SCHEME]: urlScheme
|
|
870
|
+
[ATTR_URL_SCHEME]: urlScheme,
|
|
871
|
+
[HTTP_REQUEST_BODY_SIZE]: 0,
|
|
872
|
+
[HTTP_RESPONSE_BODY_SIZE]: 0
|
|
901
873
|
};
|
|
902
874
|
const schemePorts = {
|
|
903
875
|
https: "443",
|
|
@@ -940,6 +912,10 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
940
912
|
responseBodyChunks: [],
|
|
941
913
|
requestBodySize: 0,
|
|
942
914
|
responseBodySize: 0,
|
|
915
|
+
requestBodyCaptureSize: 0,
|
|
916
|
+
responseBodyCaptureSize: 0,
|
|
917
|
+
requestBodyCaptureExceeded: false,
|
|
918
|
+
responseBodyCaptureExceeded: false,
|
|
943
919
|
url: requestUrl.toString()
|
|
944
920
|
});
|
|
945
921
|
}
|
|
@@ -986,11 +962,13 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
986
962
|
const record = this._recordFromReq.get(request);
|
|
987
963
|
if (!record) return;
|
|
988
964
|
const { span, attributes, startTime } = record;
|
|
965
|
+
span.setAttribute(HTTP_REQUEST_BODY_SIZE, record.requestBodySize);
|
|
966
|
+
span.setAttribute(HTTP_RESPONSE_BODY_SIZE, record.responseBodySize);
|
|
989
967
|
if (shouldCaptureResponseBody(record.url)) {
|
|
990
968
|
const maxResponseBodySize = this.getConfig().maxResponseBodySize ?? DEFAULT_MAX_RESPONSE_BODY_SIZE;
|
|
991
969
|
const contentEncoding = record.attributes?.["http.response.header.content-encoding"] ?? void 0;
|
|
992
970
|
const contentType = record.attributes?.["http.response.header.content-type"] ?? void 0;
|
|
993
|
-
if (record.
|
|
971
|
+
if (record.responseBodyCaptureExceeded) span.setAttribute(HTTP_RESPONSE_BODY, `[truncated response body; exceeded maxResponseBodySize=${maxResponseBodySize}; content-type=${contentType ?? "unknown"}; content-encoding=${contentEncoding ?? "identity"}]`);
|
|
994
972
|
else if (record.responseBodyChunks.length > 0) try {
|
|
995
973
|
const responseBodyBuffer = Buffer.concat(record.responseBodyChunks);
|
|
996
974
|
if (isCompressedContentEncoding(contentEncoding)) {
|
|
@@ -1012,8 +990,10 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
1012
990
|
const record = this._recordFromReq.get(request);
|
|
1013
991
|
if (!record) return;
|
|
1014
992
|
const { span, attributes, startTime } = record;
|
|
993
|
+
span.setAttribute(HTTP_REQUEST_BODY_SIZE, record.requestBodySize);
|
|
994
|
+
span.setAttribute(HTTP_RESPONSE_BODY_SIZE, record.responseBodySize);
|
|
1015
995
|
if (shouldCaptureRequestBody(record.url)) {
|
|
1016
|
-
if (record.requestBodyChunks.length > 0 && record.
|
|
996
|
+
if (record.requestBodyChunks.length > 0 && !record.requestBodyCaptureExceeded) try {
|
|
1017
997
|
const requestBody = Buffer.concat(record.requestBodyChunks).toString("utf-8");
|
|
1018
998
|
if (requestBody) span.setAttribute(HTTP_REQUEST_BODY, requestBody);
|
|
1019
999
|
} catch (e) {
|
|
@@ -1034,24 +1014,29 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
1034
1014
|
onBodyChunkSent({ request, chunk }) {
|
|
1035
1015
|
const record = this._recordFromReq.get(request);
|
|
1036
1016
|
if (!record) return;
|
|
1017
|
+
record.requestBodySize += chunk.length;
|
|
1037
1018
|
if (!shouldCaptureRequestBody(record.url)) return;
|
|
1038
1019
|
const maxRequestBodySize = this.getConfig().maxRequestBodySize ?? DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
1039
|
-
if (record.
|
|
1020
|
+
if (!record.requestBodyCaptureExceeded && record.requestBodyCaptureSize + chunk.length <= maxRequestBodySize) {
|
|
1040
1021
|
record.requestBodyChunks.push(chunk);
|
|
1041
|
-
record.
|
|
1022
|
+
record.requestBodyCaptureSize += chunk.length;
|
|
1042
1023
|
} else {
|
|
1043
|
-
record.
|
|
1024
|
+
record.requestBodyCaptureExceeded = true;
|
|
1044
1025
|
record.requestBodyChunks = [];
|
|
1026
|
+
record.requestBodyCaptureSize = 0;
|
|
1045
1027
|
}
|
|
1046
1028
|
}
|
|
1047
1029
|
onBodySent({ request }) {
|
|
1048
1030
|
const record = this._recordFromReq.get(request);
|
|
1049
1031
|
if (!record) return;
|
|
1032
|
+
record.span.setAttribute(HTTP_REQUEST_BODY_SIZE, record.requestBodySize);
|
|
1050
1033
|
if (!shouldCaptureRequestBody(record.url)) {
|
|
1051
1034
|
record.requestBodyChunks = [];
|
|
1035
|
+
record.requestBodyCaptureSize = 0;
|
|
1036
|
+
record.requestBodyCaptureExceeded = false;
|
|
1052
1037
|
return;
|
|
1053
1038
|
}
|
|
1054
|
-
if (record.
|
|
1039
|
+
if (record.requestBodyCaptureExceeded) {
|
|
1055
1040
|
const maxRequestBodySize = this.getConfig().maxRequestBodySize ?? DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
1056
1041
|
record.span.setAttribute(HTTP_REQUEST_BODY, `[truncated request body; exceeded maxRequestBodySize=${maxRequestBodySize}]`);
|
|
1057
1042
|
} else if (record.requestBodyChunks.length > 0) try {
|
|
@@ -1061,18 +1046,22 @@ var UndiciInstrumentation = class extends InstrumentationBase {
|
|
|
1061
1046
|
this._diag.error("Error occurred while capturing request body:", e);
|
|
1062
1047
|
}
|
|
1063
1048
|
record.requestBodyChunks = [];
|
|
1049
|
+
record.requestBodyCaptureSize = 0;
|
|
1050
|
+
record.requestBodyCaptureExceeded = false;
|
|
1064
1051
|
}
|
|
1065
1052
|
onBodyChunkReceived({ request, chunk }) {
|
|
1066
1053
|
const record = this._recordFromReq.get(request);
|
|
1067
1054
|
if (!record) return;
|
|
1055
|
+
record.responseBodySize += chunk.length;
|
|
1068
1056
|
if (!shouldCaptureResponseBody(record.url)) return;
|
|
1069
1057
|
const maxResponseBodySize = this.getConfig().maxResponseBodySize ?? DEFAULT_MAX_RESPONSE_BODY_SIZE;
|
|
1070
|
-
if (record.
|
|
1058
|
+
if (!record.responseBodyCaptureExceeded && record.responseBodyCaptureSize + chunk.length <= maxResponseBodySize) {
|
|
1071
1059
|
record.responseBodyChunks.push(chunk);
|
|
1072
|
-
record.
|
|
1060
|
+
record.responseBodyCaptureSize += chunk.length;
|
|
1073
1061
|
} else {
|
|
1074
|
-
record.
|
|
1062
|
+
record.responseBodyCaptureExceeded = true;
|
|
1075
1063
|
record.responseBodyChunks = [];
|
|
1064
|
+
record.responseBodyCaptureSize = 0;
|
|
1076
1065
|
}
|
|
1077
1066
|
}
|
|
1078
1067
|
recordRequestDuration(attributes, startTime) {
|