@vtvlive/interactive-apm 0.0.3 → 0.0.4
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/factories/tracing-provider.factory.d.ts +6 -4
- package/dist/factories/tracing-provider.factory.d.ts.map +1 -1
- package/dist/factories/tracing-provider.factory.js +17 -14
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/init/elastic-apm-init.d.ts +25 -3
- package/dist/init/elastic-apm-init.d.ts.map +1 -1
- package/dist/init/elastic-apm-init.js +12 -12
- package/dist/init/opentelemetry-init.d.ts +6 -2
- package/dist/init/opentelemetry-init.d.ts.map +1 -1
- package/dist/init/opentelemetry-init.js +46 -42
- package/dist/interfaces/tracing-provider.interface.d.ts +13 -3
- package/dist/interfaces/tracing-provider.interface.d.ts.map +1 -1
- package/dist/modules/tracing.module.d.ts +5 -5
- package/dist/modules/tracing.module.d.ts.map +1 -1
- package/dist/modules/tracing.module.js +2 -1
- package/dist/providers/elastic-apm.tracing-provider.d.ts +23 -5
- package/dist/providers/elastic-apm.tracing-provider.d.ts.map +1 -1
- package/dist/providers/elastic-apm.tracing-provider.js +94 -30
- package/dist/providers/opentelemetry.tracing-provider.d.ts +6 -5
- package/dist/providers/opentelemetry.tracing-provider.d.ts.map +1 -1
- package/dist/providers/opentelemetry.tracing-provider.js +178 -85
- package/dist/services/tracing.service.d.ts +6 -5
- package/dist/services/tracing.service.d.ts.map +1 -1
- package/dist/services/tracing.service.js +2 -2
- package/dist/types/apm.types.d.ts +162 -0
- package/dist/types/apm.types.d.ts.map +1 -0
- package/dist/types/apm.types.js +37 -0
- package/dist/utils/debug-exporter-wrapper.d.ts +13 -2
- package/dist/utils/debug-exporter-wrapper.d.ts.map +1 -1
- package/dist/utils/debug-exporter-wrapper.js +82 -42
- package/dist/utils/debug-logger.d.ts +34 -9
- package/dist/utils/debug-logger.d.ts.map +1 -1
- package/dist/utils/debug-logger.js +37 -28
- package/dist/utils/tracing.helper.d.ts +2 -2
- package/dist/utils/tracing.helper.d.ts.map +1 -1
- package/dist/utils/tracing.helper.js +8 -4
- package/package.json +15 -4
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Common Span interface - works with both Elastic APM and OpenTelemetry
|
|
9
|
+
*/
|
|
10
|
+
export interface ISpan {
|
|
11
|
+
/** Span name */
|
|
12
|
+
name: string;
|
|
13
|
+
/** End the span */
|
|
14
|
+
end(): void;
|
|
15
|
+
/** Set an attribute on the span */
|
|
16
|
+
setAttribute(key: string, value: string | number | boolean | string[] | undefined): void;
|
|
17
|
+
/** Add an event to the span */
|
|
18
|
+
addEvent?(name: string, attributes?: Record<string, unknown>): void;
|
|
19
|
+
/** Set the span status */
|
|
20
|
+
setStatus?(status: SpanStatus): void;
|
|
21
|
+
/** Record an exception on the span */
|
|
22
|
+
recordException?(error: Error | unknown): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Span status
|
|
26
|
+
*/
|
|
27
|
+
export interface SpanStatus {
|
|
28
|
+
code: number;
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Common Tracer interface
|
|
33
|
+
*/
|
|
34
|
+
export interface ITracer {
|
|
35
|
+
/** Start a new span */
|
|
36
|
+
startSpan(name: string, options?: SpanOptions): ISpan;
|
|
37
|
+
/** Get the currently active span */
|
|
38
|
+
getActiveSpan?(): ISpan | undefined;
|
|
39
|
+
/** Start a span with a parent context */
|
|
40
|
+
startSpanWithParent?<T>(name: string, fn: (span: ISpan) => Promise<T> | T, options?: SpanOptions): Promise<T>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Span options
|
|
44
|
+
*/
|
|
45
|
+
export interface SpanOptions {
|
|
46
|
+
/** Span attributes */
|
|
47
|
+
attributes?: Record<string, string | number | boolean>;
|
|
48
|
+
/** Span kind (server, client, internal, etc.) */
|
|
49
|
+
kind?: SpanKind;
|
|
50
|
+
/** Parent span context */
|
|
51
|
+
parent?: ISpan;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Span kind enumeration
|
|
55
|
+
*/
|
|
56
|
+
export declare enum SpanKind {
|
|
57
|
+
INTERNAL = 0,
|
|
58
|
+
SERVER = 1,
|
|
59
|
+
CLIENT = 2,
|
|
60
|
+
PRODUCER = 3,
|
|
61
|
+
CONSUMER = 4
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Common APM Provider configuration
|
|
65
|
+
*/
|
|
66
|
+
export interface IApmProviderConfig {
|
|
67
|
+
/** Service name */
|
|
68
|
+
serviceName?: string;
|
|
69
|
+
/** Environment (development, staging, production) */
|
|
70
|
+
environment?: string;
|
|
71
|
+
/** Secret token for authentication */
|
|
72
|
+
secretToken?: string;
|
|
73
|
+
/** Enable debug logging */
|
|
74
|
+
debug?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Elastic APM specific configuration
|
|
78
|
+
*/
|
|
79
|
+
export interface IElasticApmConfig extends IApmProviderConfig {
|
|
80
|
+
/** APM server URL */
|
|
81
|
+
serverUrl?: string;
|
|
82
|
+
/** Secret token */
|
|
83
|
+
secretToken?: string;
|
|
84
|
+
/** API key */
|
|
85
|
+
apiKey?: string;
|
|
86
|
+
/** Server timeout in milliseconds */
|
|
87
|
+
serverTimeout?: number;
|
|
88
|
+
/** Disable instrumentations */
|
|
89
|
+
disableInstrumentations?: string[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* OpenTelemetry specific configuration
|
|
93
|
+
*/
|
|
94
|
+
export interface IOpenTelemetryConfig extends IApmProviderConfig {
|
|
95
|
+
/** OTLP endpoint URL */
|
|
96
|
+
otlpEndpoint?: string;
|
|
97
|
+
/** OTLP transport type (http, grpc, proto) */
|
|
98
|
+
otlpTransport?: OtlpTransport | string;
|
|
99
|
+
/** OTLP auth token */
|
|
100
|
+
otlpAuthToken?: string;
|
|
101
|
+
/** OTLP headers */
|
|
102
|
+
otlpHeaders?: Record<string, string>;
|
|
103
|
+
/** Enable console exporter */
|
|
104
|
+
enableConsoleExporter?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* OTLP Transport types
|
|
108
|
+
*/
|
|
109
|
+
export declare enum OtlpTransport {
|
|
110
|
+
HTTP = "http",
|
|
111
|
+
GRPC = "grpc",
|
|
112
|
+
PROTO = "proto"
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* OTLP Transport type string
|
|
116
|
+
*/
|
|
117
|
+
export type OtlpTransportType = `${OtlpTransport}`;
|
|
118
|
+
/**
|
|
119
|
+
* APM Provider types
|
|
120
|
+
*/
|
|
121
|
+
export declare enum ApmProvider {
|
|
122
|
+
ELASTIC = "elastic-apm",
|
|
123
|
+
OPENTELEMETRY = "opentelemetry"
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* APM Provider type string
|
|
127
|
+
*/
|
|
128
|
+
export type ApmProviderType = `${ApmProvider}`;
|
|
129
|
+
/**
|
|
130
|
+
* Export result from span export
|
|
131
|
+
*/
|
|
132
|
+
export interface IExportResult {
|
|
133
|
+
/** Export status code (0 = success, non-zero = error) */
|
|
134
|
+
code: number;
|
|
135
|
+
/** Error if export failed */
|
|
136
|
+
error?: Error;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Span processor interface
|
|
140
|
+
*/
|
|
141
|
+
export interface ISpanProcessor {
|
|
142
|
+
/** Called when a span is started */
|
|
143
|
+
onStart(span: ISpan, parentContext?: unknown): void;
|
|
144
|
+
/** Called when a span is ended */
|
|
145
|
+
onEnd(span: ISpan): void;
|
|
146
|
+
/** Force flush any pending spans */
|
|
147
|
+
forceFlush(): Promise<void>;
|
|
148
|
+
/** Shutdown the processor */
|
|
149
|
+
shutdown(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Span exporter interface
|
|
153
|
+
*/
|
|
154
|
+
export interface ISpanExporter {
|
|
155
|
+
/** Export spans */
|
|
156
|
+
export(spans: ISpan[], callback: (result: IExportResult) => void): void;
|
|
157
|
+
/** Shutdown the exporter */
|
|
158
|
+
shutdown(): Promise<void>;
|
|
159
|
+
/** Force flush (optional) */
|
|
160
|
+
forceFlush?(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
//# 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;AAEH;;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,EAAE,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WA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AC,IAAI,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,IAAI,CAAC;IAExE,4BAA4B;IAC5B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B,6BAA6B;IAC7B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.ApmProvider = exports.OtlpTransport = exports.SpanKind = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Span kind enumeration
|
|
12
|
+
*/
|
|
13
|
+
var SpanKind;
|
|
14
|
+
(function (SpanKind) {
|
|
15
|
+
SpanKind[SpanKind["INTERNAL"] = 0] = "INTERNAL";
|
|
16
|
+
SpanKind[SpanKind["SERVER"] = 1] = "SERVER";
|
|
17
|
+
SpanKind[SpanKind["CLIENT"] = 2] = "CLIENT";
|
|
18
|
+
SpanKind[SpanKind["PRODUCER"] = 3] = "PRODUCER";
|
|
19
|
+
SpanKind[SpanKind["CONSUMER"] = 4] = "CONSUMER";
|
|
20
|
+
})(SpanKind || (exports.SpanKind = SpanKind = {}));
|
|
21
|
+
/**
|
|
22
|
+
* OTLP Transport types
|
|
23
|
+
*/
|
|
24
|
+
var OtlpTransport;
|
|
25
|
+
(function (OtlpTransport) {
|
|
26
|
+
OtlpTransport["HTTP"] = "http";
|
|
27
|
+
OtlpTransport["GRPC"] = "grpc";
|
|
28
|
+
OtlpTransport["PROTO"] = "proto";
|
|
29
|
+
})(OtlpTransport || (exports.OtlpTransport = OtlpTransport = {}));
|
|
30
|
+
/**
|
|
31
|
+
* APM Provider types
|
|
32
|
+
*/
|
|
33
|
+
var ApmProvider;
|
|
34
|
+
(function (ApmProvider) {
|
|
35
|
+
ApmProvider["ELASTIC"] = "elastic-apm";
|
|
36
|
+
ApmProvider["OPENTELEMETRY"] = "opentelemetry";
|
|
37
|
+
})(ApmProvider || (exports.ApmProvider = ApmProvider = {}));
|
|
@@ -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:
|
|
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():
|
|
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;
|
|
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
|
-
|
|
31
|
-
|
|
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)(
|
|
52
|
+
(0, debug_logger_1.logRequest)("OpenTelemetry", endpointUrl, getExporterHeaders(baseExporter), {
|
|
52
53
|
spanCount: spans.length,
|
|
53
|
-
spans: spans.map((s) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
64
|
-
|
|
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)(
|
|
72
|
-
(0, debug_logger_1.logResponse)(
|
|
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)(
|
|
85
|
+
(0, debug_logger_1.logRequest)("OpenTelemetry", endpointUrl, {}, { action: "shutdown" });
|
|
81
86
|
try {
|
|
82
87
|
await baseExporter.shutdown();
|
|
83
|
-
(0, debug_logger_1.logResponse)(
|
|
88
|
+
(0, debug_logger_1.logResponse)("OpenTelemetry", 200, {}, { message: "Exporter shutdown complete" });
|
|
84
89
|
}
|
|
85
90
|
catch (err) {
|
|
86
|
-
|
|
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
|
|
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(
|
|
130
|
-
const originalHttpsRequest = require(
|
|
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(
|
|
139
|
+
const { logRequest: logReq, logResponse: logResp } = require("./debug-logger");
|
|
134
140
|
// Override http.request
|
|
135
|
-
require(
|
|
136
|
-
const
|
|
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(
|
|
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 ===
|
|
168
|
+
else if (typeof chunk === "string") {
|
|
148
169
|
logData = chunk;
|
|
149
170
|
}
|
|
150
171
|
else {
|
|
151
172
|
logData = chunk?.toString();
|
|
152
173
|
}
|
|
153
|
-
logReq(
|
|
174
|
+
logReq("OpenTelemetry", url, typeof opts === "object" ? (opts.headers || {}) : {}, logData);
|
|
154
175
|
return originalWrite(chunk, ...rest);
|
|
155
176
|
};
|
|
156
|
-
req.on(
|
|
157
|
-
let body =
|
|
158
|
-
res.on(
|
|
159
|
-
|
|
160
|
-
|
|
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(
|
|
169
|
-
const
|
|
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(
|
|
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 ===
|
|
218
|
+
else if (typeof chunk === "string") {
|
|
181
219
|
logData = chunk;
|
|
182
220
|
}
|
|
183
221
|
else {
|
|
184
222
|
logData = chunk?.toString();
|
|
185
223
|
}
|
|
186
|
-
logReq(
|
|
224
|
+
logReq("OpenTelemetry", url, typeof opts === "object" ? (opts.headers || {}) : {}, logData);
|
|
187
225
|
return originalWrite(chunk, ...rest);
|
|
188
226
|
};
|
|
189
|
-
req.on(
|
|
190
|
-
let body =
|
|
191
|
-
res.on(
|
|
192
|
-
|
|
193
|
-
|
|
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(
|
|
204
|
-
require(
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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?:
|
|
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?:
|
|
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:
|
|
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;
|
|
1
|
+
{"version":3,"file":"debug-logger.d.ts","sourceRoot":"","sources":["../../src/utils/debug-logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;AAErD;;GAEG;AACH,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAwBD;;GAEG;AACH,wBAAgB,e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