@vtvlive/interactive-apm 0.0.3 → 0.0.5

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.
Files changed (42) hide show
  1. package/dist/factories/tracing-provider.factory.d.ts +6 -4
  2. package/dist/factories/tracing-provider.factory.d.ts.map +1 -1
  3. package/dist/factories/tracing-provider.factory.js +17 -14
  4. package/dist/index.d.ts +12 -11
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/init/elastic-apm-init.d.ts +25 -3
  7. package/dist/init/elastic-apm-init.d.ts.map +1 -1
  8. package/dist/init/elastic-apm-init.js +12 -12
  9. package/dist/init/opentelemetry-init.d.ts +6 -2
  10. package/dist/init/opentelemetry-init.d.ts.map +1 -1
  11. package/dist/init/opentelemetry-init.js +46 -42
  12. package/dist/interfaces/tracing-provider.interface.d.ts +13 -3
  13. package/dist/interfaces/tracing-provider.interface.d.ts.map +1 -1
  14. package/dist/modules/tracing.module.d.ts +5 -5
  15. package/dist/modules/tracing.module.d.ts.map +1 -1
  16. package/dist/modules/tracing.module.js +2 -1
  17. package/dist/providers/elastic-apm.tracing-provider.d.ts +23 -5
  18. package/dist/providers/elastic-apm.tracing-provider.d.ts.map +1 -1
  19. package/dist/providers/elastic-apm.tracing-provider.js +94 -30
  20. package/dist/providers/opentelemetry.tracing-provider.d.ts +6 -5
  21. package/dist/providers/opentelemetry.tracing-provider.d.ts.map +1 -1
  22. package/dist/providers/opentelemetry.tracing-provider.js +178 -85
  23. package/dist/services/tracing.service.d.ts +6 -5
  24. package/dist/services/tracing.service.d.ts.map +1 -1
  25. package/dist/services/tracing.service.js +2 -2
  26. package/dist/types/apm-provider.type.d.ts +2 -0
  27. package/dist/types/apm-provider.type.d.ts.map +1 -1
  28. package/dist/types/apm.types.d.ts +132 -0
  29. package/dist/types/apm.types.d.ts.map +1 -0
  30. package/dist/types/apm.types.js +15 -0
  31. package/dist/types/otlp-transport.type.d.ts +2 -0
  32. package/dist/types/otlp-transport.type.d.ts.map +1 -1
  33. package/dist/utils/debug-exporter-wrapper.d.ts +13 -2
  34. package/dist/utils/debug-exporter-wrapper.d.ts.map +1 -1
  35. package/dist/utils/debug-exporter-wrapper.js +82 -42
  36. package/dist/utils/debug-logger.d.ts +34 -9
  37. package/dist/utils/debug-logger.d.ts.map +1 -1
  38. package/dist/utils/debug-logger.js +37 -28
  39. package/dist/utils/tracing.helper.d.ts +2 -2
  40. package/dist/utils/tracing.helper.d.ts.map +1 -1
  41. package/dist/utils/tracing.helper.js +8 -4
  42. package/package.json +15 -4
@@ -0,0 +1,132 @@
1
+ /**
2
+ * APM Common Types
3
+ *
4
+ * Defines common types that work with both Elastic APM and OpenTelemetry providers.
5
+ * This provides type safety and IntelliSense for users of this package.
6
+ */
7
+ import { ApmProvider, type ApmProviderType, SpanKind } from "./apm-provider.type";
8
+ import { OtlpTransport, type OtlpTransportType } from "./otlp-transport.type";
9
+ export { ApmProvider, type ApmProviderType, SpanKind, OtlpTransport, type OtlpTransportType };
10
+ /**
11
+ * Common Span interface - works with both Elastic APM and OpenTelemetry
12
+ */
13
+ export interface ISpan {
14
+ /** Span name */
15
+ name: string;
16
+ /** End the span */
17
+ end(): void;
18
+ /** Set an attribute on the span */
19
+ setAttribute(key: string, value: string | number | boolean | string[] | undefined): void;
20
+ /** Add an event to the span */
21
+ addEvent?(name: string, attributes?: Record<string, unknown>): void;
22
+ /** Set the span status */
23
+ setStatus?(status: SpanStatus): void;
24
+ /** Record an exception on the span */
25
+ recordException?(error: Error | unknown): void;
26
+ }
27
+ /**
28
+ * Span status
29
+ */
30
+ export interface SpanStatus {
31
+ code: number;
32
+ message?: string;
33
+ }
34
+ /**
35
+ * Common Tracer interface
36
+ */
37
+ export interface ITracer {
38
+ /** Start a new span */
39
+ startSpan(name: string, options?: SpanOptions): ISpan;
40
+ /** Get the currently active span */
41
+ getActiveSpan?(): ISpan | undefined;
42
+ /** Start a span with a parent context */
43
+ startSpanWithParent?<T>(name: string, fn: (span: ISpan) => Promise<T> | T, options?: SpanOptions): Promise<T>;
44
+ }
45
+ /**
46
+ * Span options
47
+ */
48
+ export interface SpanOptions {
49
+ /** Span attributes */
50
+ attributes?: Record<string, string | number | boolean>;
51
+ /** Span kind (server, client, internal, etc.) */
52
+ kind?: SpanKind;
53
+ /** Parent span context */
54
+ parent?: ISpan;
55
+ }
56
+ /**
57
+ * Common APM Provider configuration
58
+ */
59
+ export interface IApmProviderConfig {
60
+ /** Service name */
61
+ serviceName?: string;
62
+ /** Environment (development, staging, production) */
63
+ environment?: string;
64
+ /** Secret token for authentication */
65
+ secretToken?: string;
66
+ /** Enable debug logging */
67
+ debug?: boolean;
68
+ }
69
+ /**
70
+ * Elastic APM specific configuration
71
+ */
72
+ export interface IElasticApmConfig extends IApmProviderConfig {
73
+ /** APM server URL */
74
+ serverUrl?: string;
75
+ /** Secret token */
76
+ secretToken?: string;
77
+ /** API key */
78
+ apiKey?: string;
79
+ /** Server timeout in milliseconds */
80
+ serverTimeout?: number;
81
+ /** Disable instrumentations */
82
+ disableInstrumentations?: string[];
83
+ }
84
+ /**
85
+ * OpenTelemetry specific configuration
86
+ */
87
+ export interface IOpenTelemetryConfig extends IApmProviderConfig {
88
+ /** OTLP endpoint URL */
89
+ otlpEndpoint?: string;
90
+ /** OTLP transport type (http, grpc, proto) */
91
+ otlpTransport?: OtlpTransport | string;
92
+ /** OTLP auth token */
93
+ otlpAuthToken?: string;
94
+ /** OTLP headers */
95
+ otlpHeaders?: Record<string, string>;
96
+ /** Enable console exporter */
97
+ enableConsoleExporter?: boolean;
98
+ }
99
+ /**
100
+ * Export result from span export
101
+ */
102
+ export interface IExportResult {
103
+ /** Export status code (0 = success, non-zero = error) */
104
+ code: number;
105
+ /** Error if export failed */
106
+ error?: Error;
107
+ }
108
+ /**
109
+ * Span processor interface
110
+ */
111
+ export interface ISpanProcessor {
112
+ /** Called when a span is started */
113
+ onStart(span: ISpan, parentContext?: unknown): void;
114
+ /** Called when a span is ended */
115
+ onEnd(span: ISpan): void;
116
+ /** Force flush any pending spans */
117
+ forceFlush(): Promise<void>;
118
+ /** Shutdown the processor */
119
+ shutdown(): Promise<void>;
120
+ }
121
+ /**
122
+ * Span exporter interface
123
+ */
124
+ export interface ISpanExporter {
125
+ /** Export spans */
126
+ export(spans: ISpan[], callback: (result: IExportResult) => void): void;
127
+ /** Shutdown the exporter */
128
+ shutdown(): Promise<void>;
129
+ /** Force flush (optional) */
130
+ forceFlush?(): Promise<void>;
131
+ }
132
+ //# sourceMappingURL=apm.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apm.types.d.ts","sourceRoot":"","sources":["../../src/types/apm.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IAEb,mBAAmB;IACnB,GAAG,IAAI,IAAI,CAAC;IAEZ,mCAAmC;IACnC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IAEzF,+BAA+B;IAC/B,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAEpE,0BAA0B;IAC1B,SAAS,CAAC,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAErC,sCAAsC;IACtC,eAAe,CAAC,CAAC,KAAK,E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C,CAAC;IAE1B,6BAA6B;IAC7B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * APM Common Types
4
+ *
5
+ * Defines common types that work with both Elastic APM and OpenTelemetry providers.
6
+ * This provides type safety and IntelliSense for users of this package.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OtlpTransport = exports.SpanKind = exports.ApmProvider = void 0;
10
+ // Import enums from their source files
11
+ const apm_provider_type_1 = require("./apm-provider.type");
12
+ Object.defineProperty(exports, "ApmProvider", { enumerable: true, get: function () { return apm_provider_type_1.ApmProvider; } });
13
+ Object.defineProperty(exports, "SpanKind", { enumerable: true, get: function () { return apm_provider_type_1.SpanKind; } });
14
+ const otlp_transport_type_1 = require("./otlp-transport.type");
15
+ Object.defineProperty(exports, "OtlpTransport", { enumerable: true, get: function () { return otlp_transport_type_1.OtlpTransport; } });
@@ -11,4 +11,6 @@ export declare enum OtlpTransport {
11
11
  GRPC = "grpc",
12
12
  PROTO = "proto"
13
13
  }
14
+ /** OTLP Transport type string */
15
+ export type OtlpTransportType = `${OtlpTransport}`;
14
16
  //# sourceMappingURL=otlp-transport.type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"otlp-transport.type.d.ts","sourceRoot":"","sources":["../../src/types/otlp-transport.type.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB"}
1
+ {"version":3,"file":"otlp-transport.type.d.ts","sourceRoot":"","sources":["../../src/types/otlp-transport.type.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,iCAAiC;AACjC,MAAM,MAAM,iBAAiB,GAAG,GAAG,aAAa,EAAE,CAAC"}
@@ -16,10 +16,21 @@
16
16
  * @param endpointUrl The OTLP endpoint URL for logging
17
17
  * @returns Wrapped exporter with debug capabilities
18
18
  */
19
- export declare function createDebugExporter(baseExporter: any, endpointUrl: string): any;
19
+ export declare function createDebugExporter(baseExporter: {
20
+ export(spans: unknown[], callback: (result: unknown) => void): void;
21
+ shutdown(): Promise<void>;
22
+ forceFlush?(): Promise<void>;
23
+ }, endpointUrl: string): {
24
+ export(spans: unknown[], callback: (result: unknown) => void): void;
25
+ shutdown(): Promise<void>;
26
+ forceFlush?(): Promise<void>;
27
+ };
20
28
  /**
21
29
  * Create an HTTP interceptor for more detailed debugging
22
30
  * This can be used to intercept the actual HTTP requests made by OTLP exporter
23
31
  */
24
- export declare function createHttpRequestInterceptor(): any;
32
+ export declare function createHttpRequestInterceptor(): {
33
+ install(): void;
34
+ uninstall(): void;
35
+ } | null;
25
36
  //# sourceMappingURL=debug-exporter-wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug-exporter-wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/debug-exporter-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,GAAG,CA6E/E;AAyBD;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,GAAG,CA4FlD"}
1
+ {"version":3,"file":"debug-exporter-wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/debug-exporter-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE;IACZ,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACpE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,EACD,WAAW,EAAE,MAAM,GAClB;IACD,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACpE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CA6FA;AAyBD;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI;IAC9C,OAAO,IAAI,IAAI,CAAC;IAChB,SAAS,IAAI,IAAI,CAAC;CACnB,GAAG,IAAI,CAwKP"}
@@ -27,8 +27,9 @@ function createDebugExporter(baseExporter, endpointUrl) {
27
27
  return {
28
28
  export: (spans, resultCallback) => {
29
29
  baseExporter.export(spans, (result) => {
30
- if (result.error) {
31
- (0, debug_logger_1.logExportFailure)('OpenTelemetry', result.error);
30
+ const exportResult = result;
31
+ if (exportResult.error) {
32
+ (0, debug_logger_1.logExportFailure)("OpenTelemetry", exportResult.error);
32
33
  }
33
34
  resultCallback(result);
34
35
  });
@@ -48,28 +49,32 @@ function createDebugExporter(baseExporter, endpointUrl) {
48
49
  export: (spans, resultCallback) => {
49
50
  const startTime = Date.now();
50
51
  // Log what we're about to send
51
- (0, debug_logger_1.logRequest)('OpenTelemetry', endpointUrl, getExporterHeaders(baseExporter), {
52
+ (0, debug_logger_1.logRequest)("OpenTelemetry", endpointUrl, getExporterHeaders(baseExporter), {
52
53
  spanCount: spans.length,
53
- spans: spans.map((s) => ({
54
- name: s.name,
55
- kind: s.kind,
56
- startTime: s.startTime,
57
- endTime: s.endTime,
58
- })),
54
+ spans: spans.map((s) => {
55
+ const span = s;
56
+ return {
57
+ name: span.name,
58
+ kind: span.kind,
59
+ startTime: span.startTime,
60
+ endTime: span.endTime,
61
+ };
62
+ }),
59
63
  });
60
64
  // Wrap the result callback to capture response
61
65
  baseExporter.export(spans, (result) => {
62
66
  const duration = Date.now() - startTime;
63
- if (result.error) {
64
- (0, debug_logger_1.logExportFailure)('OpenTelemetry', result.error, {
67
+ const exportResult = result;
68
+ if (exportResult.error) {
69
+ (0, debug_logger_1.logExportFailure)("OpenTelemetry", exportResult.error, {
65
70
  endpoint: endpointUrl,
66
71
  spanCount: spans.length,
67
72
  duration: `${duration}ms`,
68
73
  });
69
74
  }
70
75
  else {
71
- (0, debug_logger_1.logExportSuccess)('OpenTelemetry', spans.length);
72
- (0, debug_logger_1.logResponse)('OpenTelemetry', 200, { 'content-type': 'application/json' }, {
76
+ (0, debug_logger_1.logExportSuccess)("OpenTelemetry", spans.length);
77
+ (0, debug_logger_1.logResponse)("OpenTelemetry", 200, { "content-type": "application/json" }, {
73
78
  message: `Exported ${spans.length} span(s) in ${duration}ms`,
74
79
  });
75
80
  }
@@ -77,13 +82,14 @@ function createDebugExporter(baseExporter, endpointUrl) {
77
82
  });
78
83
  },
79
84
  shutdown: async () => {
80
- (0, debug_logger_1.logRequest)('OpenTelemetry', endpointUrl, {}, { action: 'shutdown' });
85
+ (0, debug_logger_1.logRequest)("OpenTelemetry", endpointUrl, {}, { action: "shutdown" });
81
86
  try {
82
87
  await baseExporter.shutdown();
83
- (0, debug_logger_1.logResponse)('OpenTelemetry', 200, {}, { message: 'Exporter shutdown complete' });
88
+ (0, debug_logger_1.logResponse)("OpenTelemetry", 200, {}, { message: "Exporter shutdown complete" });
84
89
  }
85
90
  catch (err) {
86
- (0, debug_logger_1.logResponse)('OpenTelemetry', 500, {}, { message: 'Exporter shutdown failed', error: err?.message || err });
91
+ const errorMessage = err instanceof Error ? err.message : String(err);
92
+ (0, debug_logger_1.logResponse)("OpenTelemetry", 500, {}, { message: "Exporter shutdown failed", error: errorMessage });
87
93
  throw err;
88
94
  }
89
95
  },
@@ -113,7 +119,7 @@ function getExporterHeaders(exporter) {
113
119
  return { ...exporter.headers };
114
120
  }
115
121
  }
116
- catch (error) {
122
+ catch {
117
123
  // Silently fail if we can't access headers
118
124
  }
119
125
  return {};
@@ -126,16 +132,31 @@ function createHttpRequestInterceptor() {
126
132
  if (!(0, debug_logger_1.isDebugEnabled)()) {
127
133
  return null;
128
134
  }
129
- const originalRequest = require('http').request;
130
- const originalHttpsRequest = require('https').request;
135
+ const originalRequest = require("http").request;
136
+ const originalHttpsRequest = require("https").request;
131
137
  return {
132
138
  install: () => {
133
- const { logRequest: logReq, logResponse: logResp } = require('./debug-logger');
139
+ const { logRequest: logReq, logResponse: logResp } = require("./debug-logger");
134
140
  // Override http.request
135
- require('http').request = function (options, ...args) {
136
- const url = typeof options === 'string' ? options : `${options.protocol || 'http:'}//${options.hostname || options.host}${options.path || '/'}`;
141
+ require("http").request = function (options, ...args) {
142
+ const opts = typeof options === "string" ? undefined : options;
143
+ let url;
144
+ if (typeof options === "string") {
145
+ url = options;
146
+ }
147
+ else {
148
+ const protocol = opts?.protocol || "http:";
149
+ const hostname = opts?.hostname || opts?.host || "localhost";
150
+ const port = opts?.port;
151
+ const path = opts?.path || "/";
152
+ // Build URL with port if specified
153
+ const hostWithPort = port ? `${hostname}:${port}` : hostname;
154
+ url = `${protocol}//${hostWithPort}${path}`;
155
+ }
137
156
  // Only intercept APM-related requests
138
- if (url.includes('/v1/traces') || url.includes('/v1/metrics') || url.includes('/intake/v2/traces')) {
157
+ if (url.includes("/v1/traces") ||
158
+ url.includes("/v1/metrics") ||
159
+ url.includes("/intake/v2/traces")) {
139
160
  const req = originalRequest.call(this, options, ...args);
140
161
  const originalWrite = req.write.bind(req);
141
162
  req.write = function (chunk, ...rest) {
@@ -144,20 +165,22 @@ function createHttpRequestInterceptor() {
144
165
  if (Buffer.isBuffer(chunk) || chunk instanceof Uint8Array) {
145
166
  logData = `<binary data: ${chunk.length} bytes>`;
146
167
  }
147
- else if (typeof chunk === 'string') {
168
+ else if (typeof chunk === "string") {
148
169
  logData = chunk;
149
170
  }
150
171
  else {
151
172
  logData = chunk?.toString();
152
173
  }
153
- logReq('OpenTelemetry', url, options.headers || {}, logData);
174
+ logReq("OpenTelemetry", url, typeof opts === "object" ? (opts.headers || {}) : {}, logData);
154
175
  return originalWrite(chunk, ...rest);
155
176
  };
156
- req.on('response', (res) => {
157
- let body = '';
158
- res.on('data', (chunk) => { body += chunk; });
159
- res.on('end', () => {
160
- logResp('OpenTelemetry', res.statusCode, res.headers, body);
177
+ req.on("response", (res) => {
178
+ let body = "";
179
+ res.on("data", (chunk) => {
180
+ body += chunk;
181
+ });
182
+ res.on("end", () => {
183
+ logResp("OpenTelemetry", res.statusCode, res.headers, body);
161
184
  });
162
185
  });
163
186
  return req;
@@ -165,10 +188,25 @@ function createHttpRequestInterceptor() {
165
188
  return originalRequest.call(this, options, ...args);
166
189
  };
167
190
  // Override https.request
168
- require('https').request = function (options, ...args) {
169
- const url = typeof options === 'string' ? options : `${options.protocol || 'https:'}//${options.hostname || options.host}${options.path || '/'}`;
191
+ require("https").request = function (options, ...args) {
192
+ const opts = typeof options === "string" ? undefined : options;
193
+ let url;
194
+ if (typeof options === "string") {
195
+ url = options;
196
+ }
197
+ else {
198
+ const protocol = opts?.protocol || "https:";
199
+ const hostname = opts?.hostname || opts?.host || "localhost";
200
+ const port = opts?.port;
201
+ const path = opts?.path || "/";
202
+ // Build URL with port if specified
203
+ const hostWithPort = port ? `${hostname}:${port}` : hostname;
204
+ url = `${protocol}//${hostWithPort}${path}`;
205
+ }
170
206
  // Only intercept APM-related requests
171
- if (url.includes('/v1/traces') || url.includes('/v1/metrics') || url.includes('/intake/v2/traces')) {
207
+ if (url.includes("/v1/traces") ||
208
+ url.includes("/v1/metrics") ||
209
+ url.includes("/intake/v2/traces")) {
172
210
  const req = originalHttpsRequest.call(this, options, ...args);
173
211
  const originalWrite = req.write.bind(req);
174
212
  req.write = function (chunk, ...rest) {
@@ -177,20 +215,22 @@ function createHttpRequestInterceptor() {
177
215
  if (Buffer.isBuffer(chunk) || chunk instanceof Uint8Array) {
178
216
  logData = `<binary data: ${chunk.length} bytes>`;
179
217
  }
180
- else if (typeof chunk === 'string') {
218
+ else if (typeof chunk === "string") {
181
219
  logData = chunk;
182
220
  }
183
221
  else {
184
222
  logData = chunk?.toString();
185
223
  }
186
- logReq('OpenTelemetry', url, options.headers || {}, logData);
224
+ logReq("OpenTelemetry", url, typeof opts === "object" ? (opts.headers || {}) : {}, logData);
187
225
  return originalWrite(chunk, ...rest);
188
226
  };
189
- req.on('response', (res) => {
190
- let body = '';
191
- res.on('data', (chunk) => { body += chunk; });
192
- res.on('end', () => {
193
- logResp('OpenTelemetry', res.statusCode, res.headers, body);
227
+ req.on("response", (res) => {
228
+ let body = "";
229
+ res.on("data", (chunk) => {
230
+ body += chunk;
231
+ });
232
+ res.on("end", () => {
233
+ logResp("OpenTelemetry", res.statusCode, res.headers, body);
194
234
  });
195
235
  });
196
236
  return req;
@@ -200,8 +240,8 @@ function createHttpRequestInterceptor() {
200
240
  },
201
241
  uninstall: () => {
202
242
  // Restore original functions
203
- require('http').request = originalRequest;
204
- require('https').request = originalHttpsRequest;
243
+ require("http").request = originalRequest;
244
+ require("https").request = originalHttpsRequest;
205
245
  },
206
246
  };
207
247
  }
@@ -4,6 +4,30 @@
4
4
  * Provides centralized debug logging that only outputs when APM_DEBUG=true.
5
5
  * Used by both Elastic APM and OpenTelemetry providers.
6
6
  */
7
+ /**
8
+ * Represents a span for logging purposes
9
+ */
10
+ interface LogSpan {
11
+ name: string;
12
+ kind: number;
13
+ startTime: number;
14
+ endTime: number;
15
+ attributes?: Record<string, unknown>;
16
+ status?: unknown;
17
+ }
18
+ /**
19
+ * Configuration object for APM providers
20
+ */
21
+ type ApmConfig = Record<string, unknown> | unknown[];
22
+ /**
23
+ * Request details for export failure logging
24
+ */
25
+ interface ExportFailureDetails {
26
+ endpoint?: string;
27
+ spanCount?: number;
28
+ duration?: string;
29
+ [key: string]: unknown;
30
+ }
7
31
  /**
8
32
  * Check if debug mode is enabled via environment variable
9
33
  */
@@ -16,23 +40,23 @@ export declare function sanitizeHeaders(headers: Record<string, string>): Record
16
40
  * Sanitize config object for logging (mask sensitive values)
17
41
  * Handles arrays and circular references safely
18
42
  */
19
- export declare function sanitizeConfig(config: any, seen?: WeakMap<object, any>): any;
43
+ export declare function sanitizeConfig<T extends ApmConfig>(config: T, seen?: WeakMap<object, unknown>): T;
20
44
  /**
21
45
  * Debug log - only outputs when APM_DEBUG=true
22
46
  */
23
- export declare function debugLog(message: string, ...args: any[]): void;
47
+ export declare function debugLog(message: string, ...args: unknown[]): void;
24
48
  /**
25
49
  * Info log - always outputs
26
50
  */
27
- export declare function infoLog(message: string, ...args: any[]): void;
51
+ export declare function infoLog(message: string, ...args: unknown[]): void;
28
52
  /**
29
53
  * Error log - always outputs
30
54
  */
31
- export declare function errorLog(message: string, ...args: any[]): void;
55
+ export declare function errorLog(message: string, ...args: unknown[]): void;
32
56
  /**
33
57
  * Log initialization details
34
58
  */
35
- export declare function logInitialization(provider: string, config: Record<string, any>): void;
59
+ export declare function logInitialization(provider: string, config: ApmConfig): void;
36
60
  /**
37
61
  * Log span export success (debug mode only)
38
62
  */
@@ -40,17 +64,18 @@ export declare function logExportSuccess(provider: string, spanCount: number): v
40
64
  /**
41
65
  * Log span export failure - ALWAYS logs regardless of debug mode
42
66
  */
43
- export declare function logExportFailure(provider: string, error: any, requestDetails?: any): void;
67
+ export declare function logExportFailure(provider: string, error: Error | unknown, requestDetails?: ExportFailureDetails): void;
44
68
  /**
45
69
  * Log outgoing HTTP request (for debugging APM communication)
46
70
  */
47
- export declare function logRequest(provider: string, url: string, headers: Record<string, string>, body?: any): void;
71
+ export declare function logRequest(provider: string, url: string, headers: Record<string, string>, body?: unknown): void;
48
72
  /**
49
73
  * Log incoming HTTP response (for debugging APM communication)
50
74
  */
51
- export declare function logResponse(provider: string, statusCode: number, headers: Record<string, string>, body?: any): void;
75
+ export declare function logResponse(provider: string, statusCode: number, headers: Record<string, string>, body?: unknown): void;
52
76
  /**
53
77
  * Log span details (when debug mode is on)
54
78
  */
55
- export declare function logSpan(provider: string, span: any): void;
79
+ export declare function logSpan(provider: string, span: LogSpan): void;
80
+ export {};
56
81
  //# sourceMappingURL=debug-logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug-logger.d.ts","sourceRoot":"","sources":["../../src/utils/debug-logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAgBD;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMvF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAiB,GAAG,GAAG,CA8C3F;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAI9D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE7D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE9D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAsBrF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAI1E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,GAAG,GAAG,IAAI,CAQz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