@pingops/core 0.1.2 → 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[];
@@ -160,17 +161,16 @@ declare function filterHeaders(headers: Record<string, string | string[] | undef
160
161
  /**
161
162
  * Extracts and normalizes headers from OpenTelemetry span attributes
162
163
  *
163
- * Handles flat array format headers (e.g., 'http.request.header.0', 'http.request.header.1')
164
- * and converts them to proper key-value objects.
165
- *
166
- * Some OpenTelemetry instrumentations store headers as flat arrays:
167
- * - 'http.request.header.0': 'Content-Type'
168
- * - 'http.request.header.1': 'application/json'
169
- * - 'http.request.header.2': 'Authorization'
170
- * - 'http.request.header.3': 'Bearer token'
164
+ * Handles two formats:
165
+ * 1. Flat array format (e.g., 'http.request.header.0', 'http.request.header.1')
166
+ * - 'http.request.header.0': 'Content-Type'
167
+ * - 'http.request.header.1': 'application/json'
168
+ * 2. Direct key-value format (e.g., 'http.request.header.date', 'http.request.header.content-type')
169
+ * - 'http.request.header.date': 'Mon, 12 Jan 2026 20:22:38 GMT'
170
+ * - 'http.request.header.content-type': 'application/json'
171
171
  *
172
172
  * This function converts them to:
173
- * - { 'Content-Type': 'application/json', 'Authorization': 'Bearer token' }
173
+ * - { 'Content-Type': 'application/json', 'date': 'Mon, 12 Jan 2026 20:22:38 GMT' }
174
174
  */
175
175
  declare function extractHeadersFromAttributes(attributes: Record<string, unknown>, headerPrefix: "http.request.header" | "http.response.header"): Record<string, string | string[] | undefined> | null;
176
176
  /**
@@ -178,6 +178,26 @@ declare function extractHeadersFromAttributes(attributes: Record<string, unknown
178
178
  */
179
179
  declare function normalizeHeaders(headers: unknown): Record<string, string | string[] | undefined>;
180
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
181
201
  //#region src/utils/span-extractor.d.ts
182
202
  /**
183
203
  * Extracts structured payload from a span
@@ -221,11 +241,10 @@ declare function createLogger(prefix: string): Logger;
221
241
  * OpenTelemetry context keys for PingOps
222
242
  */
223
243
  /**
224
- * Context key for enabling HTTP instrumentation.
225
- * When set to true, HTTP requests will be automatically instrumented.
226
- * 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.
227
246
  */
228
- declare const PINGOPS_HTTP_ENABLED: symbol;
247
+ declare const PINGOPS_TRACE_ID: symbol;
229
248
  /**
230
249
  * Context key for user ID attribute.
231
250
  * Used to propagate user identifier to all spans in the context.
@@ -249,58 +268,28 @@ declare const PINGOPS_METADATA: symbol;
249
268
  /**
250
269
  * Context key for capturing request body.
251
270
  * When set, controls whether request bodies should be captured for HTTP spans.
252
- * This allows wrapHttp to control body capture per-request.
253
271
  */
254
272
  declare const PINGOPS_CAPTURE_REQUEST_BODY: symbol;
255
273
  /**
256
274
  * Context key for capturing response body.
257
275
  * When set, controls whether response bodies should be captured for HTTP spans.
258
- * This allows wrapHttp to control body capture per-request.
259
276
  */
260
277
  declare const PINGOPS_CAPTURE_RESPONSE_BODY: symbol;
261
278
  //#endregion
262
- //#region src/wrap-http.d.ts
279
+ //#region src/trace-id.d.ts
263
280
  /**
264
- * Options for wrapHttp function
281
+ * Deterministic and random trace ID generation for PingOps
265
282
  */
266
- interface WrapHttpOptions {
267
- attributes?: WrapHttpAttributes;
268
- /**
269
- * Callback to check if SDK is initialized.
270
- * Required to determine if global instrumentation is enabled.
271
- */
272
- checkInitialized: () => boolean;
273
- /**
274
- * Callback to check if global instrumentation is enabled.
275
- * Required to determine instrumentation behavior.
276
- */
277
- isGlobalInstrumentationEnabled: () => boolean;
278
- /**
279
- * Optional callback to ensure SDK is initialized (auto-initialization).
280
- * If not provided, wrapHttp will try to auto-initialize from environment variables.
281
- */
282
- ensureInitialized?: () => Promise<void>;
283
- }
284
283
  /**
285
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
286
- *
287
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
288
- * context, which are automatically propagated to all spans created within the wrapped function.
289
- *
290
- * Instrumentation behavior:
291
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
292
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
293
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
294
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
295
- *
296
- * Note: This is the low-level API. For a simpler API with automatic setup,
297
- * use `wrapHttp` from `@pingops/sdk` instead.
298
- *
299
- * @param options - Options including attributes and required callbacks
300
- * @param fn - Function to execute within the attribute context
301
- * @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.
302
291
  */
303
- declare function wrapHttp<T>(options: WrapHttpOptions, fn: () => T | Promise<T>): T | Promise<T>;
292
+ declare function createTraceId(seed?: string): Promise<string>;
304
293
  //#endregion
305
- 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 };
306
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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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;;;;ACvJnB;AACW,cItBE,gBJsBF,EAAA,MAAA;;;;AA8GX;AA+EA;cI5Ma;;;AHqCb;;;AAOoB,cGnCP,6BHmCO,EAAA,MAAA;;;;AHlBpB;;UOrCiB,eAAA;eACF;ENxBF;AAqEb;AAsBA;AAmCA;EAgBgB,gBAAA,EAAA,GAAiB,GAAA,OAAA;EAuDjB;;;;ECrJA,8BAAa,EAAA,GAAA,GAAA,OAAA;EAClB;;;;EA8GK,iBAAA,CAAA,EAAA,GAAA,GKxHY,OLwHgB,CAAA,IAAA,CAAA;AA+E5C;;;;ACvKA;;;;;;;;;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,CAAA,EAAA,MAAW,EAAA;EAmBX,gBAAA,CAAA,EAAA,MAAsB,EAAA;;;;ACfvC;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;IA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AA,EAAA,qBAAA,GAAA,sBAAA,CAAA,EAAN,MAAM,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,EAAA,GAAA,SAAA,CAAA,GAAA,IAAA;AAoHT;;;iBAAgB,gBAAA,oBAEb;;;;;;;AJlSH;AASA;AAmBiB,cKzBJ,8BAAA,GL8BM,gCAAA;;;;ACpBnB;;iBIWgB,2BAAA;;AHwChB;;;iBG7BgB,kBAAA,SACN;;;ALRV;;;iBM+CgB,kBAAA,OACR,gCACY,8KAKA,wBACjB;;;ANnFH;AASA;AAmBA;;;;ACfA;iBMGgB,kCAAA,gBACC,UACd;;;;;;;APlBH;AASA;AAmBiB,KQzBL,QAAA,GRyBK,OAAsB,GAAA,MAAA,GAK1B,MAAM,GAAA,OAAA;UQ5BF,MAAA;;;EPQD,IAAA,CAAA,OAAA,EAAA,MAAc,EAAA,GAAA,IAAO,EAAA,OAAA,EAAA,CAAA,EAAY,IAAA;;;;ACmDjD;;;;AC5DA;AAqEY,iBKvDI,YAAA,CLuDmB,MAAA,EAAA,MAAA,CAAA,EKvDW,MLuDX;;;;;;;AHzEnC;AASA;AAmBA;cStBa;;;AROb;;cQDa;;APoDb;;;cO9Ca;ANdb;AAqEA;AAsBA;AAmCA;AAgBgB,cM1HH,YN0HoB,EAAA,MAAA;AAuDjC;;;;AC9IgB,cK7BH,gBL6BgB,EAAA,MAAA;;;;;AA8Gb,cKrIH,4BLsIC,EAAA,MAEX;AAoHH;;;;AC7Ra,cIyCA,6BJzC8B,EAAA,MAAA;;;;;;;ALH3C;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[];
@@ -160,17 +161,16 @@ declare function filterHeaders(headers: Record<string, string | string[] | undef
160
161
  /**
161
162
  * Extracts and normalizes headers from OpenTelemetry span attributes
162
163
  *
163
- * Handles flat array format headers (e.g., 'http.request.header.0', 'http.request.header.1')
164
- * and converts them to proper key-value objects.
165
- *
166
- * Some OpenTelemetry instrumentations store headers as flat arrays:
167
- * - 'http.request.header.0': 'Content-Type'
168
- * - 'http.request.header.1': 'application/json'
169
- * - 'http.request.header.2': 'Authorization'
170
- * - 'http.request.header.3': 'Bearer token'
164
+ * Handles two formats:
165
+ * 1. Flat array format (e.g., 'http.request.header.0', 'http.request.header.1')
166
+ * - 'http.request.header.0': 'Content-Type'
167
+ * - 'http.request.header.1': 'application/json'
168
+ * 2. Direct key-value format (e.g., 'http.request.header.date', 'http.request.header.content-type')
169
+ * - 'http.request.header.date': 'Mon, 12 Jan 2026 20:22:38 GMT'
170
+ * - 'http.request.header.content-type': 'application/json'
171
171
  *
172
172
  * This function converts them to:
173
- * - { 'Content-Type': 'application/json', 'Authorization': 'Bearer token' }
173
+ * - { 'Content-Type': 'application/json', 'date': 'Mon, 12 Jan 2026 20:22:38 GMT' }
174
174
  */
175
175
  declare function extractHeadersFromAttributes(attributes: Record<string, unknown>, headerPrefix: "http.request.header" | "http.response.header"): Record<string, string | string[] | undefined> | null;
176
176
  /**
@@ -178,6 +178,26 @@ declare function extractHeadersFromAttributes(attributes: Record<string, unknown
178
178
  */
179
179
  declare function normalizeHeaders(headers: unknown): Record<string, string | string[] | undefined>;
180
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
181
201
  //#region src/utils/span-extractor.d.ts
182
202
  /**
183
203
  * Extracts structured payload from a span
@@ -221,11 +241,10 @@ declare function createLogger(prefix: string): Logger;
221
241
  * OpenTelemetry context keys for PingOps
222
242
  */
223
243
  /**
224
- * Context key for enabling HTTP instrumentation.
225
- * When set to true, HTTP requests will be automatically instrumented.
226
- * 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.
227
246
  */
228
- declare const PINGOPS_HTTP_ENABLED: symbol;
247
+ declare const PINGOPS_TRACE_ID: symbol;
229
248
  /**
230
249
  * Context key for user ID attribute.
231
250
  * Used to propagate user identifier to all spans in the context.
@@ -249,58 +268,28 @@ declare const PINGOPS_METADATA: symbol;
249
268
  /**
250
269
  * Context key for capturing request body.
251
270
  * When set, controls whether request bodies should be captured for HTTP spans.
252
- * This allows wrapHttp to control body capture per-request.
253
271
  */
254
272
  declare const PINGOPS_CAPTURE_REQUEST_BODY: symbol;
255
273
  /**
256
274
  * Context key for capturing response body.
257
275
  * When set, controls whether response bodies should be captured for HTTP spans.
258
- * This allows wrapHttp to control body capture per-request.
259
276
  */
260
277
  declare const PINGOPS_CAPTURE_RESPONSE_BODY: symbol;
261
278
  //#endregion
262
- //#region src/wrap-http.d.ts
279
+ //#region src/trace-id.d.ts
263
280
  /**
264
- * Options for wrapHttp function
281
+ * Deterministic and random trace ID generation for PingOps
265
282
  */
266
- interface WrapHttpOptions {
267
- attributes?: WrapHttpAttributes;
268
- /**
269
- * Callback to check if SDK is initialized.
270
- * Required to determine if global instrumentation is enabled.
271
- */
272
- checkInitialized: () => boolean;
273
- /**
274
- * Callback to check if global instrumentation is enabled.
275
- * Required to determine instrumentation behavior.
276
- */
277
- isGlobalInstrumentationEnabled: () => boolean;
278
- /**
279
- * Optional callback to ensure SDK is initialized (auto-initialization).
280
- * If not provided, wrapHttp will try to auto-initialize from environment variables.
281
- */
282
- ensureInitialized?: () => Promise<void>;
283
- }
284
283
  /**
285
- * Wraps a function to set attributes on HTTP spans created within the wrapped block.
286
- *
287
- * This function sets attributes (userId, sessionId, tags, metadata) in the OpenTelemetry
288
- * context, which are automatically propagated to all spans created within the wrapped function.
289
- *
290
- * Instrumentation behavior:
291
- * - If `initializePingops` was called: All HTTP requests are instrumented by default.
292
- * `wrapHttp` only adds attributes to spans created within the wrapped block.
293
- * - If `initializePingops` was NOT called: Only HTTP requests within `wrapHttp` blocks
294
- * are instrumented. Requests outside `wrapHttp` are not instrumented.
295
- *
296
- * Note: This is the low-level API. For a simpler API with automatic setup,
297
- * use `wrapHttp` from `@pingops/sdk` instead.
298
- *
299
- * @param options - Options including attributes and required callbacks
300
- * @param fn - Function to execute within the attribute context
301
- * @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.
302
291
  */
303
- declare function wrapHttp<T>(options: WrapHttpOptions, fn: () => T | Promise<T>): T | Promise<T>;
292
+ declare function createTraceId(seed?: string): Promise<string>;
304
293
  //#endregion
305
- 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 };
306
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;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;AHqCb;;;AAOoB,cGnCP,6BHmCO,EAAA,MAAA;;;;AHlBpB;;UOrCiB,eAAA;eACF;ENxBF;AAqEb;AAsBA;AAmCA;EAgBgB,gBAAA,EAAA,GAAiB,GAAA,OAAA;EAuDjB;;;;ECrJA,8BAAa,EAAA,GAAA,GAAA,OAAA;EAClB;;;;EA8GK,iBAAA,CAAA,EAAA,GAAA,GKxHY,OLwHgB,CAAA,IAAA,CAAA;AA+E5C;;;;ACvKA;;;;;;;;;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;EASV,KAAA,CAAA,EAAA,MAAW,EAAA;EAmBX,gBAAA,CAAA,EAAA,MAAsB,EAAA;;;;ACfvC;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,sBAAA,CImCG;EACjB,OAAA,CAAA,EAAA,MAAA;EAAM,MAAA,CAAA,EAAA,MAAA;EAyGO,SAAA,CAAA,EAAA,MAAA;EAuHA,IAAA,CAAA,EAAA,MAAA,EAAA;aJ/PH;;;AK9Bb;AAqBA;EAWgB,kBAAA,CAAA,EAAkB,OAAA;;;;ACwCl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