@pingops/core 0.1.3 → 0.2.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.d.cts CHANGED
@@ -29,9 +29,10 @@ interface SpanPayload {
29
29
  };
30
30
  }
31
31
  /**
32
- * Attributes to propagate to HTTP spans
32
+ * Attributes to propagate to spans (e.g. when starting a trace with startTrace).
33
33
  */
34
- interface WrapHttpAttributes {
34
+ interface PingopsTraceAttributes {
35
+ traceId?: string;
35
36
  userId?: string;
36
37
  sessionId?: string;
37
38
  tags?: string[];
@@ -177,6 +178,26 @@ declare function extractHeadersFromAttributes(attributes: Record<string, unknown
177
178
  */
178
179
  declare function normalizeHeaders(headers: unknown): Record<string, string | string[] | undefined>;
179
180
  //#endregion
181
+ //#region src/filtering/body-decoder.d.ts
182
+ /**
183
+ * Minimal body handling: buffer to string for span attributes.
184
+ * No decompression or truncation; for compressed responses the instrumentation
185
+ * sends base64 + content-encoding so the backend can decompress.
186
+ */
187
+ /** Span attribute for response content-encoding when body is sent as base64. */
188
+ declare const HTTP_RESPONSE_CONTENT_ENCODING = "http.response.content_encoding";
189
+ /**
190
+ * Returns true if the content-encoding header indicates a compressed body
191
+ * (gzip, br, deflate, x-gzip, x-deflate). Used to decide whether to send
192
+ * body as base64 + content-encoding for backend decompression.
193
+ */
194
+ declare function isCompressedContentEncoding(headerValue: unknown): boolean;
195
+ /**
196
+ * Converts a buffer to a UTF-8 string for use as request/response body on spans.
197
+ * Returns null for null, undefined, or empty buffer.
198
+ */
199
+ declare function bufferToBodyString(buffer: Buffer | null | undefined): string | null;
200
+ //#endregion
180
201
  //#region src/utils/span-extractor.d.ts
181
202
  /**
182
203
  * Extracts structured payload from a span
@@ -220,11 +241,10 @@ declare function createLogger(prefix: string): Logger;
220
241
  * OpenTelemetry context keys for PingOps
221
242
  */
222
243
  /**
223
- * Context key for enabling HTTP instrumentation.
224
- * When set to true, HTTP requests will be automatically instrumented.
225
- * This allows wrapHttp to control which HTTP calls are captured.
244
+ * Context key for trace ID attribute.
245
+ * Used to propagate trace identifier to all spans in the context.
226
246
  */
227
- declare const PINGOPS_HTTP_ENABLED: symbol;
247
+ declare const PINGOPS_TRACE_ID: symbol;
228
248
  /**
229
249
  * Context key for user ID attribute.
230
250
  * Used to propagate user identifier to all spans in the context.
@@ -248,58 +268,28 @@ declare const PINGOPS_METADATA: symbol;
248
268
  /**
249
269
  * Context key for capturing request body.
250
270
  * When set, controls whether request bodies should be captured for HTTP spans.
251
- * This allows wrapHttp to control body capture per-request.
252
271
  */
253
272
  declare const PINGOPS_CAPTURE_REQUEST_BODY: symbol;
254
273
  /**
255
274
  * Context key for capturing response body.
256
275
  * When set, controls whether response bodies should be captured for HTTP spans.
257
- * This allows wrapHttp to control body capture per-request.
258
276
  */
259
277
  declare const PINGOPS_CAPTURE_RESPONSE_BODY: symbol;
260
278
  //#endregion
261
- //#region src/wrap-http.d.ts
279
+ //#region src/trace-id.d.ts
262
280
  /**
263
- * Options for wrapHttp function
281
+ * Deterministic and random trace ID generation for PingOps
264
282
  */
265
- interface WrapHttpOptions {
266
- attributes?: WrapHttpAttributes;
267
- /**
268
- * Callback to check if SDK is initialized.
269
- * Required to determine if global instrumentation is enabled.
270
- */
271
- checkInitialized: () => boolean;
272
- /**
273
- * Callback to check if global instrumentation is enabled.
274
- * Required to determine instrumentation behavior.
275
- */
276
- isGlobalInstrumentationEnabled: () => boolean;
277
- /**
278
- * Optional callback to ensure SDK is initialized (auto-initialization).
279
- * If not provided, wrapHttp will try to auto-initialize from environment variables.
280
- */
281
- ensureInitialized?: () => Promise<void>;
282
- }
283
283
  /**
284
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
285
- *
286
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
287
- * context, which are automatically propagated to all spans created within the wrapped function.
288
- *
289
- * Instrumentation behavior:
290
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
291
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
292
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
293
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
294
- *
295
- * Note: This is the low-level API. For a simpler API with automatic setup,
296
- * use `wrapHttp` from `@pingops/sdk` instead.
297
- *
298
- * @param options - Options including attributes and required callbacks
299
- * @param fn - Function to execute within the attribute context
300
- * @returns The result of the function
284
+ * Converts a Uint8Array to a lowercase hex string.
285
+ */
286
+ declare function uint8ArrayToHex(bytes: Uint8Array): string;
287
+ /**
288
+ * Creates a trace ID (32 hex chars).
289
+ * - If `seed` is provided: deterministic via SHA-256 of the seed (first 32 hex chars).
290
+ * - Otherwise: random 16 bytes as 32 hex chars.
301
291
  */
302
- declare function wrapHttp<T>(options: WrapHttpOptions, fn: () => T | Promise<T>): T | Promise<T>;
292
+ declare function createTraceId(seed?: string): Promise<string>;
303
293
  //#endregion
304
- export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, DomainRule, HeaderRedactionConfig, HeaderRedactionStrategy, LogLevel, Logger, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_HTTP_ENABLED, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_USER_ID, SpanPayload, WrapHttpAttributes, WrapHttpOptions, createLogger, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, wrapHttp };
294
+ export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, DomainRule, HTTP_RESPONSE_CONTENT_ENCODING, HeaderRedactionConfig, HeaderRedactionStrategy, LogLevel, Logger, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_TRACE_ID, PINGOPS_USER_ID, PingopsTraceAttributes, SpanPayload, bufferToBodyString, createLogger, createTraceId, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isCompressedContentEncoding, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, uint8ArrayToHex };
305
295
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/filtering/span-filter.ts","../src/filtering/domain-filter.ts","../src/filtering/sensitive-headers.ts","../src/filtering/header-filter.ts","../src/utils/span-extractor.ts","../src/utils/context-extractor.ts","../src/logger.ts","../src/context-keys.ts","../src/wrap-http.ts"],"sourcesContent":[],"mappings":";;;;;;;UAIiB,UAAA;EAAA,MAAA,EAAA,MAAU;EASV,KAAA,CAAA,EAAA,MAAW,EAAA;EAmBX,gBAAA,CAAA,EAAA,MAAkB,EAAA;;;;ACfnC;UDJiB,WAAA;;;EEuDD,YAAA,CAAA,EAAA,MAAiB;;;;EC5DpB,OAAA,EAAA,MAAA;EAqED,QAAA,EAAA,MAAA;EAsBK,UAAA,EH7EH,MG6EG,CAAA,MAAqB,EAAA,OAAA,CAWzB;EAwBA,MAAA,EAAA;IAgBG,IAAA,EAAA,MAAA;IAuDA,OAAA,CAAA,EAAA,MAAiB;;;;AC9IjC;;AAIoB,UJnCH,kBAAA,CImCG;EACjB,MAAA,CAAA,EAAA,MAAA;EAAM,SAAA,CAAA,EAAA,MAAA;EAyGO,IAAA,CAAA,EAAA,MAAA,EAAA;EAuHA,QAAA,CAAA,EJhQH,MIgQG,CAAA,MAAgB,EAAA,MAE7B,CAAA;;;;ACvNH;EACQ,kBAAA,CAAA,EAAA,OAAA;EACY;;;;;;;;AL7EpB;AASA;AAmBA;;;;ACfA;iBAAgB,cAAA,OAAqB;;;ADbrC;AASA;AAmBA;iBEoCgB,iBAAA,gCAEI,+BACD;;;;;;;AFnEnB;AASA;AAmBA;cGxBa;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fA;iBKEgB,kCAAA,gBACC,UACd;;;;;;;ANjBH;AASA;AAmBiB,KOzBL,QAAA,GPyBK,OAAkB,GAAA,MAItB,GAAA,MAAM,GAAA,OAAA;UO3BF,MAAA;;;ENQD,IAAA,CAAA,OAAA,EAAA,MAAc,EAAA,GAAA,IAAO,EAAA,OAAA,EAAA,CAAA,EAAY,IAAA;;;;ACmDjD;;;;AC5DA;AAqEY,iBIvDI,YAAA,CJuDmB,MAAA,EAAA,MAAA,CAAA,EIvDW,MJuDX;;;;;;;AHzEnC;AASA;AAmBA;;cQrBa;;APMb;;;cOAa;ANmDb;;;;AC5Da,cKeA,kBLfA,EAgEH,MAAA;AAKV;AAsBA;AAmCA;AAgBA;AAuDgB,cKhLH,YLgLoB,EAAA,MAEd;;;;AChJnB;AACW,cI7BE,gBJ6BF,EAAA,MAAA;;;;AA6GX;AAuHA;cI1Pa;;;AHqCb;;;AAOoB,cGnCP,6BHmCO,EAAA,MAAA;;;;AHlBpB;;UOrCiB,eAAA;eACF;ENxBF;AAqEb;AAsBA;AAmCA;EAgBgB,gBAAA,EAAA,GAAiB,GAAA,OAAA;EAuDjB;;;;EC9IA,8BAAa,EAAA,GAAA,GAAA,OAAA;EAClB;;;;EA6GK,iBAAA,CAAA,EAAA,GAAA,GK9HY,OL8HgB,CAAA,IAAA,CAAA;AAuH5C;;;;ACrNA;;;;;;;;;AC5DA;;;;ACZA;AAEA;AAaA;iBE+CgB,qBACL,2BACC,IAAI,QAAQ,KACrB,IAAI,QAAQ"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/filtering/span-filter.ts","../src/filtering/domain-filter.ts","../src/filtering/sensitive-headers.ts","../src/filtering/header-filter.ts","../src/filtering/body-decoder.ts","../src/utils/span-extractor.ts","../src/utils/context-extractor.ts","../src/logger.ts","../src/context-keys.ts","../src/trace-id.ts"],"sourcesContent":[],"mappings":";;;;;;;UAIiB,UAAA;EAAA,MAAA,EAAA,MAAU;EASV,KAAA,CA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H3C;AASA;AAmBiB,iBUzBD,eAAA,CVyBuB,KAK1B,EU9B0B,UV8BpB,CAAA,EAAA,MAAA;;;;ACpBnB;;iBSCsB,aAAA,iBAA8B"}
package/dist/index.d.mts CHANGED
@@ -29,9 +29,10 @@ interface SpanPayload {
29
29
  };
30
30
  }
31
31
  /**
32
- * Attributes to propagate to HTTP spans
32
+ * Attributes to propagate to spans (e.g. when starting a trace with startTrace).
33
33
  */
34
- interface WrapHttpAttributes {
34
+ interface PingopsTraceAttributes {
35
+ traceId?: string;
35
36
  userId?: string;
36
37
  sessionId?: string;
37
38
  tags?: string[];
@@ -177,6 +178,26 @@ declare function extractHeadersFromAttributes(attributes: Record<string, unknown
177
178
  */
178
179
  declare function normalizeHeaders(headers: unknown): Record<string, string | string[] | undefined>;
179
180
  //#endregion
181
+ //#region src/filtering/body-decoder.d.ts
182
+ /**
183
+ * Minimal body handling: buffer to string for span attributes.
184
+ * No decompression or truncation; for compressed responses the instrumentation
185
+ * sends base64 + content-encoding so the backend can decompress.
186
+ */
187
+ /** Span attribute for response content-encoding when body is sent as base64. */
188
+ declare const HTTP_RESPONSE_CONTENT_ENCODING = "http.response.content_encoding";
189
+ /**
190
+ * Returns true if the content-encoding header indicates a compressed body
191
+ * (gzip, br, deflate, x-gzip, x-deflate). Used to decide whether to send
192
+ * body as base64 + content-encoding for backend decompression.
193
+ */
194
+ declare function isCompressedContentEncoding(headerValue: unknown): boolean;
195
+ /**
196
+ * Converts a buffer to a UTF-8 string for use as request/response body on spans.
197
+ * Returns null for null, undefined, or empty buffer.
198
+ */
199
+ declare function bufferToBodyString(buffer: Buffer | null | undefined): string | null;
200
+ //#endregion
180
201
  //#region src/utils/span-extractor.d.ts
181
202
  /**
182
203
  * Extracts structured payload from a span
@@ -220,11 +241,10 @@ declare function createLogger(prefix: string): Logger;
220
241
  * OpenTelemetry context keys for PingOps
221
242
  */
222
243
  /**
223
- * Context key for enabling HTTP instrumentation.
224
- * When set to true, HTTP requests will be automatically instrumented.
225
- * This allows wrapHttp to control which HTTP calls are captured.
244
+ * Context key for trace ID attribute.
245
+ * Used to propagate trace identifier to all spans in the context.
226
246
  */
227
- declare const PINGOPS_HTTP_ENABLED: symbol;
247
+ declare const PINGOPS_TRACE_ID: symbol;
228
248
  /**
229
249
  * Context key for user ID attribute.
230
250
  * Used to propagate user identifier to all spans in the context.
@@ -248,58 +268,28 @@ declare const PINGOPS_METADATA: symbol;
248
268
  /**
249
269
  * Context key for capturing request body.
250
270
  * When set, controls whether request bodies should be captured for HTTP spans.
251
- * This allows wrapHttp to control body capture per-request.
252
271
  */
253
272
  declare const PINGOPS_CAPTURE_REQUEST_BODY: symbol;
254
273
  /**
255
274
  * Context key for capturing response body.
256
275
  * When set, controls whether response bodies should be captured for HTTP spans.
257
- * This allows wrapHttp to control body capture per-request.
258
276
  */
259
277
  declare const PINGOPS_CAPTURE_RESPONSE_BODY: symbol;
260
278
  //#endregion
261
- //#region src/wrap-http.d.ts
279
+ //#region src/trace-id.d.ts
262
280
  /**
263
- * Options for wrapHttp function
281
+ * Deterministic and random trace ID generation for PingOps
264
282
  */
265
- interface WrapHttpOptions {
266
- attributes?: WrapHttpAttributes;
267
- /**
268
- * Callback to check if SDK is initialized.
269
- * Required to determine if global instrumentation is enabled.
270
- */
271
- checkInitialized: () => boolean;
272
- /**
273
- * Callback to check if global instrumentation is enabled.
274
- * Required to determine instrumentation behavior.
275
- */
276
- isGlobalInstrumentationEnabled: () => boolean;
277
- /**
278
- * Optional callback to ensure SDK is initialized (auto-initialization).
279
- * If not provided, wrapHttp will try to auto-initialize from environment variables.
280
- */
281
- ensureInitialized?: () => Promise<void>;
282
- }
283
283
  /**
284
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
285
- *
286
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
287
- * context, which are automatically propagated to all spans created within the wrapped function.
288
- *
289
- * Instrumentation behavior:
290
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
291
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
292
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
293
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
294
- *
295
- * Note: This is the low-level API. For a simpler API with automatic setup,
296
- * use `wrapHttp` from `@pingops/sdk` instead.
297
- *
298
- * @param options - Options including attributes and required callbacks
299
- * @param fn - Function to execute within the attribute context
300
- * @returns The result of the function
284
+ * Converts a Uint8Array to a lowercase hex string.
285
+ */
286
+ declare function uint8ArrayToHex(bytes: Uint8Array): string;
287
+ /**
288
+ * Creates a trace ID (32 hex chars).
289
+ * - If `seed` is provided: deterministic via SHA-256 of the seed (first 32 hex chars).
290
+ * - Otherwise: random 16 bytes as 32 hex chars.
301
291
  */
302
- declare function wrapHttp<T>(options: WrapHttpOptions, fn: () => T | Promise<T>): T | Promise<T>;
292
+ declare function createTraceId(seed?: string): Promise<string>;
303
293
  //#endregion
304
- export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, DomainRule, HeaderRedactionConfig, HeaderRedactionStrategy, LogLevel, Logger, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_HTTP_ENABLED, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_USER_ID, SpanPayload, WrapHttpAttributes, WrapHttpOptions, createLogger, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, wrapHttp };
294
+ export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, DomainRule, HTTP_RESPONSE_CONTENT_ENCODING, HeaderRedactionConfig, HeaderRedactionStrategy, LogLevel, Logger, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_TRACE_ID, PINGOPS_USER_ID, PingopsTraceAttributes, SpanPayload, bufferToBodyString, createLogger, createTraceId, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isCompressedContentEncoding, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, uint8ArrayToHex };
305
295
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/filtering/span-filter.ts","../src/filtering/domain-filter.ts","../src/filtering/sensitive-headers.ts","../src/filtering/header-filter.ts","../src/utils/span-extractor.ts","../src/utils/context-extractor.ts","../src/logger.ts","../src/context-keys.ts","../src/wrap-http.ts"],"sourcesContent":[],"mappings":";;;;;;;UAIiB,UAAA;EAAA,MAAA,EAAA,MAAU;EASV,KAAA,CAAA,EAAA,MAAW,EAAA;EAmBX,gBAAA,CAAA,EAAA,MAAkB,EAAA;;;;ACfnC;UDJiB,WAAA;;;EEuDD,YAAA,CAAA,EAAA,MAAiB;;;;EC5DpB,OAAA,EAAA,MAAA;EAqED,QAAA,EAAA,MAAA;EAsBK,UAAA,EH7EH,MG6EG,CAAA,MAAqB,EAAA,OAAA,CAAA;EAmCzB,MAAA,EAAA;IAgBG,IAAA,EAAA,MAAA;IAuDA,OAAA,CAAA,EAAA,MAAiB;;;;AC9IjC;;AAIoB,UJnCH,kBAAA,CImCG;EACjB,MAAA,CAAA,EAAA,MAAA;EAAM,SAAA,CAAA,EAAA,MAAA;EAyGO,IAAA,CAAA,EAAA,MAAA,EAAA;EAuHA,QAAA,CAAA,EJhQH,MIgQG,CAAA,MAAgB,EAAA,MAE7B,CAAA;;;;ACvNH;EACQ,kBAAA,CAAA,EAAA,OAAA;EACY;;;;;;;;AL7EpB;AASA;AAmBA;;;;ACfA;iBAAgB,cAAA,OAAqB;;;ADbrC;AASA;AAmBA;iBEoCgB,iBAAA,gCAEI,+BACD;;;;;;;AFnEnB;AASA;A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AAmBA;;;;ACfA;iBKEgB,kCAAA,gBACC,UACd;;;;;;;ANjBH;AASA;AAmBiB,KOzBL,QAAA,GPyBK,OAAkB,GAAA,MAItB,GAAA,MAAM,GAAA,OAAA;UO3BF,MAAA;;;ENQD,IAAA,CAAA,OAAA,EAAA,MAAc,EAAA,GAAA,IAAO,EAAA,OAAA,EAAA,CAAY,EAAA,IAAA;;;;ACmDjD;;;;AC5DA;AAqEY,iBIvDI,YAAA,CJuDmB,MAAA,EAAA,MAAA,CAAA,EIvDW,MJuDX;;;;;;;AHzEnC;AASA;AAmBA;;cQrBa;;APMb;;;cOAa;ANmDb;;;;AC5Da,cKeA,kBLfA,EAgEH,MAAA;AAKV;AAsBA;AAmCA;AAgBA;AAuDgB,cKhLH,YLgLoB,EAAA,MAEd;;;;AChJnB;AACW,cI7BE,gBJ6BF,EAAA,MAAA;;;;AA6GX;AAuHA;cI1Pa;;;AHqCb;;;AAOoB,cGnCP,6BHmCO,EAAA,MAAA;;;;AHlBpB;;UOrCiB,eAAA;eACF;ENxBF;AAqEb;AAsBA;AAmCA;EAgBgB,gBAAA,EAAA,GAAiB,GAAA,OAAA;EAuDjB;;;;EC9IA,8BAAa,EAAA,GAAA,GAAA,OAAA;EAClB;;;;EA6GK,iBAAA,CAAA,EAAA,GAAA,GK9HY,OL8HgB,CAAA,IAAA,CAAA;AAuH5C;;;;ACrNA;;;;;;;;;AC5DA;;;;ACZA;AAEA;AAaA;iBE+CgB,qBACL,2BACC,IAAI,QAAQ,KACrB,IAAI,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/filtering/span-filter.ts","../src/filtering/domain-filter.ts","../src/filtering/sensitive-headers.ts","../src/filtering/header-filter.ts","../src/filtering/body-decoder.ts","../src/utils/span-extractor.ts","../src/utils/context-extractor.ts","../src/logger.ts","../src/context-keys.ts","../src/trace-id.ts"],"sourcesContent":[],"mappings":";;;;;;;UAIiB,UAAA;EAAA,MAAA,EAAA,MAAU;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AA;;;;;;;ALH3C;AASA;AAmBiB,iBUzBD,eAAA,CV8BH,KAAA,EU9B0B,UV8BpB,CAAA,EAAA,MAAA;;;;ACpBnB;;iBSCsB,aAAA,iBAA8B"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { SpanKind, context, createContextKey } from "@opentelemetry/api";
1
+ import { SpanKind, createContextKey } from "@opentelemetry/api";
2
2
 
3
3
  //#region src/logger.ts
4
4
  /**
@@ -574,6 +574,46 @@ function normalizeHeaders(headers) {
574
574
  return result;
575
575
  }
576
576
 
577
+ //#endregion
578
+ //#region src/filtering/body-decoder.ts
579
+ /**
580
+ * Minimal body handling: buffer to string for span attributes.
581
+ * No decompression or truncation; for compressed responses the instrumentation
582
+ * sends base64 + content-encoding so the backend can decompress.
583
+ */
584
+ /** Span attribute for response content-encoding when body is sent as base64. */
585
+ const HTTP_RESPONSE_CONTENT_ENCODING = "http.response.content_encoding";
586
+ const COMPRESSED_ENCODINGS = new Set([
587
+ "gzip",
588
+ "br",
589
+ "deflate",
590
+ "x-gzip",
591
+ "x-deflate"
592
+ ]);
593
+ function normalizeHeaderValue(v) {
594
+ if (v == null) return void 0;
595
+ return (Array.isArray(v) ? v.map(String).join(", ") : String(v)).trim() || void 0;
596
+ }
597
+ /**
598
+ * Returns true if the content-encoding header indicates a compressed body
599
+ * (gzip, br, deflate, x-gzip, x-deflate). Used to decide whether to send
600
+ * body as base64 + content-encoding for backend decompression.
601
+ */
602
+ function isCompressedContentEncoding(headerValue) {
603
+ const raw = normalizeHeaderValue(headerValue);
604
+ if (!raw) return false;
605
+ const first = raw.split(",")[0].trim().toLowerCase();
606
+ return COMPRESSED_ENCODINGS.has(first);
607
+ }
608
+ /**
609
+ * Converts a buffer to a UTF-8 string for use as request/response body on spans.
610
+ * Returns null for null, undefined, or empty buffer.
611
+ */
612
+ function bufferToBodyString(buffer) {
613
+ if (buffer == null || buffer.length === 0) return null;
614
+ return buffer.toString("utf8");
615
+ }
616
+
577
617
  //#endregion
578
618
  //#region src/utils/span-extractor.ts
579
619
  /**
@@ -662,11 +702,10 @@ function extractSpanPayload(span, domainAllowList, globalHeadersAllowList, globa
662
702
  * OpenTelemetry context keys for PingOps
663
703
  */
664
704
  /**
665
- * Context key for enabling HTTP instrumentation.
666
- * When set to true, HTTP requests will be automatically instrumented.
667
- * This allows wrapHttp to control which HTTP calls are captured.
705
+ * Context key for trace ID attribute.
706
+ * Used to propagate trace identifier to all spans in the context.
668
707
  */
669
- const PINGOPS_HTTP_ENABLED = createContextKey("pingops-http-enabled");
708
+ const PINGOPS_TRACE_ID = createContextKey("pingops-trace-id");
670
709
  /**
671
710
  * Context key for user ID attribute.
672
711
  * Used to propagate user identifier to all spans in the context.
@@ -690,13 +729,11 @@ const PINGOPS_METADATA = createContextKey("pingops-metadata");
690
729
  /**
691
730
  * Context key for capturing request body.
692
731
  * When set, controls whether request bodies should be captured for HTTP spans.
693
- * This allows wrapHttp to control body capture per-request.
694
732
  */
695
733
  const PINGOPS_CAPTURE_REQUEST_BODY = createContextKey("pingops-capture-request-body");
696
734
  /**
697
735
  * Context key for capturing response body.
698
736
  * When set, controls whether response bodies should be captured for HTTP spans.
699
- * This allows wrapHttp to control body capture per-request.
700
737
  */
701
738
  const PINGOPS_CAPTURE_RESPONSE_BODY = createContextKey("pingops-capture-response-body");
702
739
 
@@ -711,6 +748,8 @@ const PINGOPS_CAPTURE_RESPONSE_BODY = createContextKey("pingops-capture-response
711
748
  */
712
749
  function getPropagatedAttributesFromContext(parentContext) {
713
750
  const attributes = {};
751
+ const traceId = parentContext.getValue(PINGOPS_TRACE_ID);
752
+ if (traceId !== void 0 && typeof traceId === "string") attributes["pingops.trace_id"] = traceId;
714
753
  const userId = parentContext.getValue(PINGOPS_USER_ID);
715
754
  if (userId !== void 0 && typeof userId === "string") attributes["pingops.user_id"] = userId;
716
755
  const sessionId = parentContext.getValue(PINGOPS_SESSION_ID);
@@ -725,100 +764,30 @@ function getPropagatedAttributesFromContext(parentContext) {
725
764
  }
726
765
 
727
766
  //#endregion
728
- //#region src/wrap-http.ts
767
+ //#region src/trace-id.ts
729
768
  /**
730
- * wrapHttp - Wraps a function to set attributes on HTTP spans created within the wrapped block.
731
- *
732
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
733
- * context, which are automatically propagated to all spans created within the wrapped function.
734
- *
735
- * Instrumentation behavior:
736
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
737
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
738
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
739
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
769
+ * Deterministic and random trace ID generation for PingOps
740
770
  */
741
- const logger = createLogger("[PingOps wrapHttp]");
742
771
  /**
743
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
744
- *
745
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
746
- * context, which are automatically propagated to all spans created within the wrapped function.
747
- *
748
- * Instrumentation behavior:
749
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
750
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
751
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
752
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
753
- *
754
- * Note: This is the low-level API. For a simpler API with automatic setup,
755
- * use `wrapHttp` from `@pingops/sdk` instead.
756
- *
757
- * @param options - Options including attributes and required callbacks
758
- * @param fn - Function to execute within the attribute context
759
- * @returns The result of the function
760
- */
761
- function wrapHttp(options, fn) {
762
- logger.debug("wrapHttp called", {
763
- hasAttributes: !!options.attributes,
764
- hasUserId: !!options.attributes?.userId,
765
- hasSessionId: !!options.attributes?.sessionId,
766
- hasTags: !!options.attributes?.tags,
767
- hasMetadata: !!options.attributes?.metadata
768
- });
769
- const normalizedOptions = "checkInitialized" in options && "isGlobalInstrumentationEnabled" in options ? options : (() => {
770
- throw new Error("wrapHttp requires checkInitialized and isGlobalInstrumentationEnabled callbacks. Use wrapHttp from @pingops/sdk for automatic setup.");
771
- })();
772
- const { checkInitialized, ensureInitialized } = normalizedOptions;
773
- if (checkInitialized()) {
774
- logger.debug("SDK already initialized, executing wrapHttp synchronously");
775
- return executeWrapHttpWithContext(normalizedOptions, fn);
776
- }
777
- if (ensureInitialized) {
778
- logger.debug("SDK not initialized, using provided ensureInitialized callback");
779
- return ensureInitialized().then(() => {
780
- logger.debug("SDK initialized, executing wrapHttp");
781
- return executeWrapHttpWithContext(normalizedOptions, fn);
782
- }).catch((error) => {
783
- logger.error("Failed to initialize SDK for wrapHttp", { error: error instanceof Error ? error.message : String(error) });
784
- throw error;
785
- });
786
- }
787
- logger.debug("SDK not initialized and no ensureInitialized callback provided, executing wrapHttp");
788
- return executeWrapHttpWithContext(normalizedOptions, fn);
772
+ * Converts a Uint8Array to a lowercase hex string.
773
+ */
774
+ function uint8ArrayToHex(bytes) {
775
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
789
776
  }
790
- function executeWrapHttpWithContext(options, fn) {
791
- const { attributes, isGlobalInstrumentationEnabled } = options;
792
- const globalInstrumentationEnabled = isGlobalInstrumentationEnabled();
793
- logger.debug("Executing wrapHttp context", {
794
- hasAttributes: !!attributes,
795
- globalInstrumentationEnabled
796
- });
797
- let contextWithAttributes = context.active();
798
- if (!globalInstrumentationEnabled) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_HTTP_ENABLED, true);
799
- if (attributes) {
800
- if (attributes.userId !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_USER_ID, attributes.userId);
801
- if (attributes.sessionId !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_SESSION_ID, attributes.sessionId);
802
- if (attributes.tags !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_TAGS, attributes.tags);
803
- if (attributes.metadata !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_METADATA, attributes.metadata);
804
- if (attributes.captureRequestBody !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_CAPTURE_REQUEST_BODY, attributes.captureRequestBody);
805
- if (attributes.captureResponseBody !== void 0) contextWithAttributes = contextWithAttributes.setValue(PINGOPS_CAPTURE_RESPONSE_BODY, attributes.captureResponseBody);
777
+ /**
778
+ * Creates a trace ID (32 hex chars).
779
+ * - If `seed` is provided: deterministic via SHA-256 of the seed (first 32 hex chars).
780
+ * - Otherwise: random 16 bytes as 32 hex chars.
781
+ */
782
+ async function createTraceId(seed) {
783
+ if (seed) {
784
+ const data = new TextEncoder().encode(seed);
785
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
786
+ return uint8ArrayToHex(new Uint8Array(hashBuffer)).slice(0, 32);
806
787
  }
807
- return context.with(contextWithAttributes, () => {
808
- try {
809
- const result = fn();
810
- if (result instanceof Promise) return result.catch((err) => {
811
- logger.error("Error in wrapHttp async execution", { error: err instanceof Error ? err.message : String(err) });
812
- throw err;
813
- });
814
- return result;
815
- } catch (err) {
816
- logger.error("Error in wrapHttp sync execution", { error: err instanceof Error ? err.message : String(err) });
817
- throw err;
818
- }
819
- });
788
+ return uint8ArrayToHex(crypto.getRandomValues(new Uint8Array(16)));
820
789
  }
821
790
 
822
791
  //#endregion
823
- export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, HeaderRedactionStrategy, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_HTTP_ENABLED, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_USER_ID, createLogger, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, wrapHttp };
792
+ export { DEFAULT_REDACTION_CONFIG, DEFAULT_SENSITIVE_HEADER_PATTERNS, HTTP_RESPONSE_CONTENT_ENCODING, HeaderRedactionStrategy, PINGOPS_CAPTURE_REQUEST_BODY, PINGOPS_CAPTURE_RESPONSE_BODY, PINGOPS_METADATA, PINGOPS_SESSION_ID, PINGOPS_TAGS, PINGOPS_TRACE_ID, PINGOPS_USER_ID, bufferToBodyString, createLogger, createTraceId, extractHeadersFromAttributes, extractSpanPayload, filterHeaders, getPropagatedAttributesFromContext, isCompressedContentEncoding, isSensitiveHeader, isSpanEligible, normalizeHeaders, redactHeaderValue, shouldCaptureSpan, uint8ArrayToHex };
824
793
  //# sourceMappingURL=index.mjs.map