@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ITracingProvider } from
|
|
2
|
-
import { ApmProvider } from
|
|
3
|
-
import { OtlpTransport } from
|
|
1
|
+
import { ITracingProvider } from "../interfaces/tracing-provider.interface";
|
|
2
|
+
import { ApmProvider } from "../types/apm-provider.type";
|
|
3
|
+
import { OtlpTransport } from "../types/otlp-transport.type";
|
|
4
4
|
/**
|
|
5
5
|
* Configuration options for creating a tracing provider
|
|
6
6
|
*/
|
|
@@ -78,7 +78,9 @@ export declare const TRACING_PROVIDER_TOKEN = "ITracingProvider";
|
|
|
78
78
|
*/
|
|
79
79
|
export declare const TracingProviderFactory: {
|
|
80
80
|
provide: string;
|
|
81
|
-
useFactory: (configService?:
|
|
81
|
+
useFactory: (configService?: {
|
|
82
|
+
get?(key: string, defaultValue?: unknown): unknown;
|
|
83
|
+
}) => ITracingProvider;
|
|
82
84
|
inject: string[];
|
|
83
85
|
};
|
|
84
86
|
//# sourceMappingURL=tracing-provider.factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing-provider.factory.d.ts","sourceRoot":"","sources":["../../src/factories/tracing-provider.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mHAAmH;IACnH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IACvC,6DAA6D;IAC7D,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,qBAA0B,GAAG,gBAAgB,CAQ1F;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB;;iCAEJ,GAAG
|
|
1
|
+
{"version":3,"file":"tracing-provider.factory.d.ts","sourceRoot":"","sources":["../../src/factories/tracing-provider.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mHAAmH;IACnH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IACvC,6DAA6D;IAC7D,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,qBAA0B,GAAG,gBAAgB,CAQ1F;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB;;iCAEJ;QAAE,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;KAAE;YAoCrE,MAAM,EAAE;CACvB,CAAC"}
|
|
@@ -25,7 +25,7 @@ const apm_provider_type_1 = require("../types/apm-provider.type");
|
|
|
25
25
|
*/
|
|
26
26
|
function createTracingProvider(config = {}) {
|
|
27
27
|
const provider = config.provider || process.env.APM_PROVIDER || apm_provider_type_1.ApmProvider.OPENTELEMETRY;
|
|
28
|
-
if (provider === apm_provider_type_1.ApmProvider.ELASTIC_APM || provider ===
|
|
28
|
+
if (provider === apm_provider_type_1.ApmProvider.ELASTIC_APM || provider === "elastic-apm") {
|
|
29
29
|
return new elastic_apm_tracing_provider_1.ElasticApmTracingProvider(config);
|
|
30
30
|
}
|
|
31
31
|
return new opentelemetry_tracing_provider_1.OpenTelemetryTracingProvider(config);
|
|
@@ -34,7 +34,7 @@ function createTracingProvider(config = {}) {
|
|
|
34
34
|
* NestJS Provider token for dependency injection
|
|
35
35
|
* Use this when integrating with NestJS
|
|
36
36
|
*/
|
|
37
|
-
exports.TRACING_PROVIDER_TOKEN =
|
|
37
|
+
exports.TRACING_PROVIDER_TOKEN = "ITracingProvider";
|
|
38
38
|
/**
|
|
39
39
|
* NestJS factory provider for use with NestJS dependency injection
|
|
40
40
|
*
|
|
@@ -64,31 +64,34 @@ exports.TracingProviderFactory = {
|
|
|
64
64
|
useFactory: (configService) => {
|
|
65
65
|
// Support both standalone and NestJS usage
|
|
66
66
|
const get = (key, defaultValue) => {
|
|
67
|
-
if (configService && typeof configService.get ===
|
|
67
|
+
if (configService && typeof configService.get === "function") {
|
|
68
68
|
return configService.get(key, defaultValue);
|
|
69
69
|
}
|
|
70
70
|
return process.env[key] || defaultValue;
|
|
71
71
|
};
|
|
72
|
-
const otlpAuthToken = get(
|
|
73
|
-
const secretToken = get(
|
|
72
|
+
const otlpAuthToken = get("ELASTIC_OTLP_AUTH_TOKEN", "");
|
|
73
|
+
const secretToken = get("ELASTIC_APM_SECRET_TOKEN", "");
|
|
74
74
|
// Build Authorization header if token is provided
|
|
75
75
|
const headers = {};
|
|
76
76
|
const token = otlpAuthToken || secretToken;
|
|
77
77
|
if (token) {
|
|
78
|
-
headers[
|
|
78
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
79
79
|
}
|
|
80
80
|
return createTracingProvider({
|
|
81
|
-
provider: get(
|
|
82
|
-
serviceName: get(
|
|
83
|
-
environment: get(
|
|
84
|
-
serverUrl: get(
|
|
81
|
+
provider: get("APM_PROVIDER", "opentelemetry"),
|
|
82
|
+
serviceName: get("ELASTIC_APM_SERVICE_NAME", "interactive-backend"),
|
|
83
|
+
environment: get("ELASTIC_APM_ENVIRONMENT", "development"),
|
|
84
|
+
serverUrl: get("ELASTIC_APM_SERVER_URL", "http://localhost:8200"),
|
|
85
85
|
secretToken,
|
|
86
|
-
otlpEndpoint: get(
|
|
86
|
+
otlpEndpoint: get("ELASTIC_OTLP_ENDPOINT", "http://localhost:8200/v1/traces"),
|
|
87
87
|
otlpAuthToken,
|
|
88
88
|
otlpHeaders: Object.keys(headers).length > 0 ? headers : undefined,
|
|
89
|
-
otlpTransport: get(
|
|
90
|
-
enableConsoleExporter: get(
|
|
89
|
+
otlpTransport: get("ELASTIC_OTLP_TRANSPORT", "http"),
|
|
90
|
+
enableConsoleExporter: get("ELASTIC_OTLP_ENABLE_CONSOLE_EXPORTER", false) === true ||
|
|
91
|
+
get("ELASTIC_OTLP_ENABLE_CONSOLE_EXPORTER", "false") === "true",
|
|
91
92
|
});
|
|
92
93
|
},
|
|
93
|
-
|
|
94
|
+
// Note: Users should compose their own factory with proper injection.
|
|
95
|
+
// See the @Module example above for the recommended pattern.
|
|
96
|
+
inject: [],
|
|
94
97
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export { TracingModule, TracingModuleOptions, TracingModuleAsyncOptions } from
|
|
2
|
-
export { TracingService } from
|
|
3
|
-
export { TracingHelper } from
|
|
4
|
-
export { ITracingProvider } from
|
|
5
|
-
export { ApmProvider, SpanKind } from
|
|
6
|
-
export { OtlpTransport } from
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
1
|
+
export { TracingModule, TracingModuleOptions, TracingModuleAsyncOptions, } from "./modules/tracing.module";
|
|
2
|
+
export { TracingService } from "./services/tracing.service";
|
|
3
|
+
export { TracingHelper } from "./utils/tracing.helper";
|
|
4
|
+
export { ITracingProvider } from "./interfaces/tracing-provider.interface";
|
|
5
|
+
export { ApmProvider, SpanKind } from "./types/apm-provider.type";
|
|
6
|
+
export { OtlpTransport } from "./types/otlp-transport.type";
|
|
7
|
+
export { ISpan, ITracer, SpanOptions, SpanStatus, IApmProviderConfig, IElasticApmConfig, IOpenTelemetryConfig, IExportResult, ISpanProcessor, ISpanExporter, type OtlpTransportType, type ApmProviderType, } from "./types/apm.types";
|
|
8
|
+
export { ElasticApmTracingProvider } from "./providers/elastic-apm.tracing-provider";
|
|
9
|
+
export { OpenTelemetryTracingProvider } from "./providers/opentelemetry.tracing-provider";
|
|
10
|
+
export { createTracingProvider, TracingProviderFactory, TRACING_PROVIDER_TOKEN, TracingProviderConfig, } from "./factories/tracing-provider.factory";
|
|
11
|
+
export { initElasticApm, isElasticApmStarted, getElasticApmAgent, shouldUseElasticApm, ElasticApmInitOptions, } from "./init/elastic-apm-init";
|
|
12
|
+
export { initOpenTelemetry, shouldUseOpenTelemetry, OpenTelemetryInitOptions, } from "./init/opentelemetry-init";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAG1F,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,2BAA2B,CAAC"}
|
|
@@ -26,7 +26,7 @@ export interface ElasticApmInitOptions {
|
|
|
26
26
|
/** Deployment environment */
|
|
27
27
|
environment?: string;
|
|
28
28
|
/** APM log level */
|
|
29
|
-
logLevel?:
|
|
29
|
+
logLevel?: "trace" | "debug" | "info" | "warn" | "error" | "off";
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Check if APM should use Elastic APM provider based on configuration
|
|
@@ -39,7 +39,18 @@ export declare function shouldUseElasticApm(): boolean;
|
|
|
39
39
|
* @param options Configuration options
|
|
40
40
|
* @returns The APM agent instance
|
|
41
41
|
*/
|
|
42
|
-
export declare function initElasticApm(options?: ElasticApmInitOptions):
|
|
42
|
+
export declare function initElasticApm(options?: ElasticApmInitOptions): {
|
|
43
|
+
isStarted(): boolean;
|
|
44
|
+
startTransaction(name: string, type: string): {
|
|
45
|
+
end(): void;
|
|
46
|
+
} | null;
|
|
47
|
+
startSpan(name: string, type: string): {
|
|
48
|
+
end(): void;
|
|
49
|
+
} | null;
|
|
50
|
+
captureError(error: Error): void;
|
|
51
|
+
setTransactionName(name: string): void;
|
|
52
|
+
flush(): Promise<void>;
|
|
53
|
+
} | null;
|
|
43
54
|
/**
|
|
44
55
|
* Check if Elastic APM agent is started
|
|
45
56
|
*/
|
|
@@ -47,5 +58,16 @@ export declare function isElasticApmStarted(): boolean;
|
|
|
47
58
|
/**
|
|
48
59
|
* Get the Elastic APM agent instance
|
|
49
60
|
*/
|
|
50
|
-
export declare function getElasticApmAgent():
|
|
61
|
+
export declare function getElasticApmAgent(): {
|
|
62
|
+
isStarted(): boolean;
|
|
63
|
+
startTransaction(name: string, type: string): {
|
|
64
|
+
end(): void;
|
|
65
|
+
} | null;
|
|
66
|
+
startSpan(name: string, type: string): {
|
|
67
|
+
end(): void;
|
|
68
|
+
} | null;
|
|
69
|
+
captureError(error: Error): void;
|
|
70
|
+
setTransactionName(name: string): void;
|
|
71
|
+
flush(): Promise<void>;
|
|
72
|
+
} | null;
|
|
51
73
|
//# sourceMappingURL=elastic-apm-init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elastic-apm-init.d.ts","sourceRoot":"","sources":["../../src/init/elastic-apm-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,WAAW,qBAAqB;IACpC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;CAClE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAG7C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"elastic-apm-init.d.ts","sourceRoot":"","sources":["../../src/init/elastic-apm-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,WAAW,qBAAqB;IACpC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;CAClE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAG7C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG;IACnE,SAAS,IAAI,OAAO,CAAC;IACrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,GAAG,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACrE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,GAAG,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9D,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACjC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,GAAG,IAAI,CA6CP;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAQ7C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI;IACpC,SAAS,IAAI,OAAO,CAAC;IACrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,GAAG,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACrE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,GAAG,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9D,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACjC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,GAAG,IAAI,CAWP"}
|
|
@@ -28,7 +28,7 @@ const debug_logger_1 = require("../utils/debug-logger");
|
|
|
28
28
|
*/
|
|
29
29
|
function shouldUseElasticApm() {
|
|
30
30
|
const provider = process.env.APM_PROVIDER || apm_provider_type_1.ApmProvider.OPENTELEMETRY;
|
|
31
|
-
return provider === apm_provider_type_1.ApmProvider.ELASTIC_APM || provider ===
|
|
31
|
+
return provider === apm_provider_type_1.ApmProvider.ELASTIC_APM || provider === "elastic-apm";
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Initialize Elastic APM agent for standalone usage
|
|
@@ -38,24 +38,24 @@ function shouldUseElasticApm() {
|
|
|
38
38
|
*/
|
|
39
39
|
function initElasticApm(options = {}) {
|
|
40
40
|
// @ts-ignore - Optional peer dependency
|
|
41
|
-
const apm = require(
|
|
41
|
+
const apm = require("elastic-apm-node");
|
|
42
42
|
// If already started, return the instance
|
|
43
43
|
if (apm.isStarted()) {
|
|
44
44
|
return apm;
|
|
45
45
|
}
|
|
46
|
-
const serviceName = options.serviceName || process.env.ELASTIC_APM_SERVICE_NAME ||
|
|
47
|
-
const serverUrl = options.serverUrl || process.env.ELASTIC_APM_SERVER_URL ||
|
|
46
|
+
const serviceName = options.serviceName || process.env.ELASTIC_APM_SERVICE_NAME || "interactive-backend";
|
|
47
|
+
const serverUrl = options.serverUrl || process.env.ELASTIC_APM_SERVER_URL || "http://localhost:8200";
|
|
48
48
|
const secretToken = options.secretToken || process.env.ELASTIC_APM_SECRET_TOKEN;
|
|
49
|
-
const serviceVersion = options.serviceVersion || process.env.npm_package_version ||
|
|
50
|
-
const environment = options.environment || process.env.ELASTIC_APM_ENVIRONMENT ||
|
|
49
|
+
const serviceVersion = options.serviceVersion || process.env.npm_package_version || "1.0.0";
|
|
50
|
+
const environment = options.environment || process.env.ELASTIC_APM_ENVIRONMENT || "development";
|
|
51
51
|
// Log initialization details when debug mode is on
|
|
52
|
-
(0, debug_logger_1.logInitialization)(
|
|
52
|
+
(0, debug_logger_1.logInitialization)("ElasticAPM", {
|
|
53
53
|
serviceName,
|
|
54
54
|
serverUrl,
|
|
55
55
|
hasSecretToken: !!secretToken,
|
|
56
56
|
serviceVersion,
|
|
57
57
|
environment,
|
|
58
|
-
logLevel: options.logLevel ||
|
|
58
|
+
logLevel: options.logLevel || "error",
|
|
59
59
|
});
|
|
60
60
|
// Start the agent
|
|
61
61
|
const agent = apm.start({
|
|
@@ -64,11 +64,11 @@ function initElasticApm(options = {}) {
|
|
|
64
64
|
secretToken,
|
|
65
65
|
serviceVersion,
|
|
66
66
|
environment,
|
|
67
|
-
logLevel: options.logLevel ||
|
|
67
|
+
logLevel: options.logLevel || "error",
|
|
68
68
|
});
|
|
69
69
|
if ((0, debug_logger_1.isDebugEnabled)()) {
|
|
70
70
|
(0, debug_logger_1.infoLog)(`[ElasticAPM] Service: ${agent.getServiceName()}, Environment: ${agent.conf.environment}`);
|
|
71
|
-
(0, debug_logger_1.infoLog)(
|
|
71
|
+
(0, debug_logger_1.infoLog)("[ElasticAPM] Initialized");
|
|
72
72
|
}
|
|
73
73
|
return agent;
|
|
74
74
|
}
|
|
@@ -78,7 +78,7 @@ function initElasticApm(options = {}) {
|
|
|
78
78
|
function isElasticApmStarted() {
|
|
79
79
|
try {
|
|
80
80
|
// @ts-ignore - Optional peer dependency
|
|
81
|
-
const apm = require(
|
|
81
|
+
const apm = require("elastic-apm-node");
|
|
82
82
|
return apm.isStarted();
|
|
83
83
|
}
|
|
84
84
|
catch {
|
|
@@ -91,7 +91,7 @@ function isElasticApmStarted() {
|
|
|
91
91
|
function getElasticApmAgent() {
|
|
92
92
|
try {
|
|
93
93
|
// @ts-ignore - Optional peer dependency
|
|
94
|
-
const apm = require(
|
|
94
|
+
const apm = require("elastic-apm-node");
|
|
95
95
|
if (apm.isStarted()) {
|
|
96
96
|
return apm;
|
|
97
97
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* environment: 'production',
|
|
15
15
|
* });
|
|
16
16
|
*/
|
|
17
|
-
import { OtlpTransport } from
|
|
17
|
+
import { OtlpTransport } from "../types/otlp-transport.type";
|
|
18
18
|
export interface OpenTelemetryInitOptions {
|
|
19
19
|
/** Service name for APM */
|
|
20
20
|
serviceName?: string;
|
|
@@ -50,5 +50,9 @@ export declare function shouldUseOpenTelemetry(): boolean;
|
|
|
50
50
|
* @param options Configuration options
|
|
51
51
|
* @returns The NodeSDK instance
|
|
52
52
|
*/
|
|
53
|
-
export declare function initOpenTelemetry(options?: OpenTelemetryInitOptions): Promise<
|
|
53
|
+
export declare function initOpenTelemetry(options?: OpenTelemetryInitOptions): Promise<{
|
|
54
|
+
start(): void;
|
|
55
|
+
shutdown(): Promise<void>;
|
|
56
|
+
flush?(): Promise<void>;
|
|
57
|
+
}>;
|
|
54
58
|
//# sourceMappingURL=opentelemetry-init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opentelemetry-init.d.ts","sourceRoot":"","sources":["../../src/init/opentelemetry-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"opentelemetry-init.d.ts","sourceRoot":"","sources":["../../src/init/opentelemetry-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAgD7D,MAAM,WAAW,wBAAwB;IACvC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mHAAmH;IACnH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,kCAAkC;IAClC,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,qCAAqC;IACrC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAGhD;AAwCD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;IACd,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC,CAwJD"}
|
|
@@ -72,18 +72,19 @@ class TransactionNameProcessor {
|
|
|
72
72
|
return Promise.resolve();
|
|
73
73
|
}
|
|
74
74
|
onEnd(_span) {
|
|
75
|
+
const span = _span;
|
|
75
76
|
// Only process root spans (SERVER spans without parent)
|
|
76
|
-
if (
|
|
77
|
+
if (span.parent || span.kind !== api_1.SpanKind.SERVER) {
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
80
|
// Get HTTP attributes (http.route is often set after routing completes)
|
|
80
|
-
const method =
|
|
81
|
-
const route =
|
|
82
|
-
const target =
|
|
81
|
+
const method = span.attributes?.["http.method"];
|
|
82
|
+
const route = span.attributes?.["http.route"]; // /api/healthcheck/ping
|
|
83
|
+
const target = span.attributes?.["http.target"]; // fallback
|
|
83
84
|
if (method && (route || target)) {
|
|
84
85
|
// Format: GET /api/healthcheck/ping
|
|
85
86
|
const fullName = `${method} ${route || target}`;
|
|
86
|
-
|
|
87
|
+
span.updateName?.(fullName);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -93,7 +94,7 @@ class TransactionNameProcessor {
|
|
|
93
94
|
*/
|
|
94
95
|
function shouldUseOpenTelemetry() {
|
|
95
96
|
const provider = process.env.APM_PROVIDER || apm_provider_type_1.ApmProvider.OPENTELEMETRY;
|
|
96
|
-
return provider !== apm_provider_type_1.ApmProvider.ELASTIC_APM && provider !==
|
|
97
|
+
return provider !== apm_provider_type_1.ApmProvider.ELASTIC_APM && provider !== "elastic-apm";
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
* Normalize OTLP endpoint URL to ensure consistent format
|
|
@@ -106,23 +107,23 @@ function normalizeEndpoint(endpoint, isGrpc) {
|
|
|
106
107
|
const url = new URL(endpoint);
|
|
107
108
|
// Ensure port is specified
|
|
108
109
|
if (!url.port) {
|
|
109
|
-
const defaultPort = url.protocol ===
|
|
110
|
+
const defaultPort = url.protocol === "https:" ? "443" : "80";
|
|
110
111
|
url.port = defaultPort;
|
|
111
112
|
}
|
|
112
113
|
// Remove trailing slash
|
|
113
|
-
let pathname = url.pathname.replace(/\/+$/,
|
|
114
|
+
let pathname = url.pathname.replace(/\/+$/, "");
|
|
114
115
|
// For gRPC, remove /v1/traces as it uses different path
|
|
115
|
-
if (isGrpc && pathname.endsWith(
|
|
116
|
-
pathname = pathname.replace(
|
|
116
|
+
if (isGrpc && pathname.endsWith("/v1/traces")) {
|
|
117
|
+
pathname = pathname.replace("/v1/traces", "");
|
|
117
118
|
}
|
|
118
119
|
// For HTTP/PROTO, ensure /v1/traces path exists
|
|
119
|
-
if (!isGrpc && !pathname.endsWith(
|
|
120
|
-
pathname = pathname.endsWith(
|
|
120
|
+
if (!isGrpc && !pathname.endsWith("/v1/traces")) {
|
|
121
|
+
pathname = pathname.endsWith("/") ? pathname + "v1/traces" : pathname + "/v1/traces";
|
|
121
122
|
}
|
|
122
123
|
url.pathname = pathname;
|
|
123
124
|
return url.toString();
|
|
124
125
|
}
|
|
125
|
-
catch
|
|
126
|
+
catch {
|
|
126
127
|
// If URL parsing fails, return as-is
|
|
127
128
|
return endpoint;
|
|
128
129
|
}
|
|
@@ -135,17 +136,19 @@ function normalizeEndpoint(endpoint, isGrpc) {
|
|
|
135
136
|
*/
|
|
136
137
|
async function initOpenTelemetry(options = {}) {
|
|
137
138
|
// @ts-ignore - Optional peer dependency
|
|
138
|
-
const { NodeSDK } = await Promise.resolve().then(() => __importStar(require(
|
|
139
|
+
const { NodeSDK } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/sdk-node")));
|
|
139
140
|
// @ts-ignore - Optional peer dependency
|
|
140
|
-
const { resourceFromAttributes } = await Promise.resolve().then(() => __importStar(require(
|
|
141
|
-
const serviceName = options.serviceName || process.env.ELASTIC_APM_SERVICE_NAME ||
|
|
142
|
-
const environment = options.environment || process.env.ELASTIC_APM_ENVIRONMENT ||
|
|
141
|
+
const { resourceFromAttributes } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/resources")));
|
|
142
|
+
const serviceName = options.serviceName || process.env.ELASTIC_APM_SERVICE_NAME || "interactive-backend";
|
|
143
|
+
const environment = options.environment || process.env.ELASTIC_APM_ENVIRONMENT || "development";
|
|
143
144
|
// Determine transport type (HTTP, gRPC, or PROTO)
|
|
144
|
-
const transportType = (options.otlpTransport ||
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
const transportType = (options.otlpTransport ||
|
|
146
|
+
process.env.ELASTIC_OTLP_TRANSPORT ||
|
|
147
|
+
otlp_transport_type_1.OtlpTransport.HTTP).toLowerCase();
|
|
148
|
+
const isGrpc = transportType === otlp_transport_type_1.OtlpTransport.GRPC || transportType === "grpc";
|
|
149
|
+
const isProto = transportType === otlp_transport_type_1.OtlpTransport.PROTO || transportType === "proto";
|
|
147
150
|
// Get endpoint from config or env (same endpoint for both transports)
|
|
148
|
-
const otlpEndpoint = options.otlpEndpoint || process.env.ELASTIC_OTLP_ENDPOINT ||
|
|
151
|
+
const otlpEndpoint = options.otlpEndpoint || process.env.ELASTIC_OTLP_ENDPOINT || "http://localhost:8200/v1/traces";
|
|
149
152
|
// Validate and normalize endpoint
|
|
150
153
|
const normalizedEndpoint = normalizeEndpoint(otlpEndpoint, isGrpc);
|
|
151
154
|
const secretToken = options.secretToken || process.env.ELASTIC_APM_SECRET_TOKEN;
|
|
@@ -154,20 +157,20 @@ async function initOpenTelemetry(options = {}) {
|
|
|
154
157
|
const headers = { ...options.otlpHeaders };
|
|
155
158
|
const token = otlpAuthToken || secretToken;
|
|
156
159
|
if (token) {
|
|
157
|
-
headers[
|
|
160
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
158
161
|
}
|
|
159
162
|
// Log initialization details when debug mode is on
|
|
160
|
-
(0, debug_logger_1.logInitialization)(
|
|
163
|
+
(0, debug_logger_1.logInitialization)("OpenTelemetry", {
|
|
161
164
|
serviceName,
|
|
162
165
|
environment,
|
|
163
166
|
otlpEndpoint: normalizedEndpoint,
|
|
164
|
-
transport: isGrpc ?
|
|
167
|
+
transport: isGrpc ? "gRPC" : isProto ? "PROTO (protobuf over HTTP)" : "HTTP",
|
|
165
168
|
hasToken: !!token,
|
|
166
|
-
enableConsoleExporter: options.enableConsoleExporter ?? process.env.ELASTIC_OTLP_ENABLE_CONSOLE_EXPORTER ===
|
|
169
|
+
enableConsoleExporter: options.enableConsoleExporter ?? process.env.ELASTIC_OTLP_ENABLE_CONSOLE_EXPORTER === "true",
|
|
167
170
|
enableHttpInstrumentation: options.enableHttpInstrumentation !== false,
|
|
168
171
|
enableExpressInstrumentation: options.enableExpressInstrumentation !== false,
|
|
169
172
|
});
|
|
170
|
-
const transportLabel = isGrpc ?
|
|
173
|
+
const transportLabel = isGrpc ? "gRPC" : isProto ? "PROTO" : "HTTP";
|
|
171
174
|
(0, debug_logger_1.infoLog)(`[OpenTelemetry] Initializing with ${transportLabel} transport...`);
|
|
172
175
|
// Build exporters array
|
|
173
176
|
const exporters = [];
|
|
@@ -175,7 +178,7 @@ async function initOpenTelemetry(options = {}) {
|
|
|
175
178
|
let otlpExporterBase;
|
|
176
179
|
if (isGrpc) {
|
|
177
180
|
// @ts-ignore - Optional peer dependency
|
|
178
|
-
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require(
|
|
181
|
+
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/exporter-trace-otlp-grpc")));
|
|
179
182
|
otlpExporterBase = new OTLPTraceExporter({
|
|
180
183
|
url: normalizedEndpoint,
|
|
181
184
|
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
@@ -183,7 +186,7 @@ async function initOpenTelemetry(options = {}) {
|
|
|
183
186
|
}
|
|
184
187
|
else if (isProto) {
|
|
185
188
|
// @ts-ignore - Optional peer dependency
|
|
186
|
-
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require(
|
|
189
|
+
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/exporter-trace-otlp-proto")));
|
|
187
190
|
otlpExporterBase = new OTLPTraceExporter({
|
|
188
191
|
url: normalizedEndpoint,
|
|
189
192
|
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
@@ -191,7 +194,7 @@ async function initOpenTelemetry(options = {}) {
|
|
|
191
194
|
}
|
|
192
195
|
else {
|
|
193
196
|
// @ts-ignore - Optional peer dependency
|
|
194
|
-
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require(
|
|
197
|
+
const { OTLPTraceExporter } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/exporter-trace-otlp-http")));
|
|
195
198
|
otlpExporterBase = new OTLPTraceExporter({
|
|
196
199
|
url: normalizedEndpoint,
|
|
197
200
|
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
@@ -201,36 +204,37 @@ async function initOpenTelemetry(options = {}) {
|
|
|
201
204
|
const otlpExporter = (0, debug_exporter_wrapper_1.createDebugExporter)(otlpExporterBase, normalizedEndpoint);
|
|
202
205
|
exporters.push(otlpExporter);
|
|
203
206
|
// Console Exporter for debugging
|
|
204
|
-
if (options.enableConsoleExporter ??
|
|
207
|
+
if (options.enableConsoleExporter ??
|
|
208
|
+
process.env.ELASTIC_OTLP_ENABLE_CONSOLE_EXPORTER === "true") {
|
|
205
209
|
// @ts-ignore - Optional peer dependency
|
|
206
|
-
const { ConsoleSpanExporter } = await Promise.resolve().then(() => __importStar(require(
|
|
210
|
+
const { ConsoleSpanExporter } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/sdk-trace-base")));
|
|
207
211
|
exporters.push(new ConsoleSpanExporter());
|
|
208
212
|
}
|
|
209
213
|
// Build instrumentations array
|
|
210
214
|
const instrumentations = [];
|
|
211
215
|
if (options.enableHttpInstrumentation !== false) {
|
|
212
216
|
// @ts-ignore - Optional peer dependency
|
|
213
|
-
const { HttpInstrumentation } = await Promise.resolve().then(() => __importStar(require(
|
|
217
|
+
const { HttpInstrumentation } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/instrumentation-http")));
|
|
214
218
|
instrumentations.push(new HttpInstrumentation());
|
|
215
219
|
}
|
|
216
220
|
if (options.enableExpressInstrumentation !== false) {
|
|
217
221
|
// @ts-ignore - Optional peer dependency
|
|
218
|
-
const { ExpressInstrumentation } = await Promise.resolve().then(() => __importStar(require(
|
|
222
|
+
const { ExpressInstrumentation } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/instrumentation-express")));
|
|
219
223
|
instrumentations.push(new ExpressInstrumentation());
|
|
220
224
|
}
|
|
221
225
|
// Resource attributes
|
|
222
226
|
const sdkResource = resourceFromAttributes({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
"service.name": serviceName,
|
|
228
|
+
"deployment.environment": environment,
|
|
229
|
+
"service.version": options.serviceVersion || process.env.npm_package_version || "1.0.0",
|
|
230
|
+
"service.instance.id": `${process.pid}`,
|
|
231
|
+
"host.name": require("os").hostname(),
|
|
228
232
|
});
|
|
229
233
|
// Initialize SDK
|
|
230
234
|
const sdk = new NodeSDK({
|
|
231
235
|
serviceName,
|
|
232
236
|
traceExporter: exporters.length === 1 ? exporters[0] : exporters, // Handle single/multiple exporters
|
|
233
|
-
instrumentations,
|
|
237
|
+
instrumentations: instrumentations,
|
|
234
238
|
resource: sdkResource,
|
|
235
239
|
spanProcessor: new TransactionNameProcessor(),
|
|
236
240
|
});
|
|
@@ -241,13 +245,13 @@ async function initOpenTelemetry(options = {}) {
|
|
|
241
245
|
if (interceptor) {
|
|
242
246
|
interceptor.install();
|
|
243
247
|
}
|
|
244
|
-
(0, debug_logger_1.infoLog)(
|
|
248
|
+
(0, debug_logger_1.infoLog)("[OpenTelemetry] Initialized");
|
|
245
249
|
// Setup graceful shutdown handlers
|
|
246
250
|
const shutdown = async () => {
|
|
247
251
|
await sdk.shutdown();
|
|
248
252
|
process.exit(0);
|
|
249
253
|
};
|
|
250
|
-
process.on(
|
|
251
|
-
process.on(
|
|
254
|
+
process.on("SIGTERM", shutdown);
|
|
255
|
+
process.on("SIGINT", shutdown);
|
|
252
256
|
return sdk;
|
|
253
257
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { ISpan } from "../types/apm.types";
|
|
1
2
|
/**
|
|
2
3
|
* Interface chung cho APM Tracing Provider
|
|
3
4
|
* Cho phép switch giữa OpenTelemetry và Elastic APM thông qua DI
|
|
4
5
|
*/
|
|
5
6
|
export interface ITracingProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the provider
|
|
9
|
+
* @param config Optional configuration
|
|
10
|
+
*/
|
|
11
|
+
initialize?(config?: unknown): Promise<void>;
|
|
6
12
|
/**
|
|
7
13
|
* Bắt đầu một span mới để trace operation
|
|
8
14
|
* @param name Tên của span
|
|
@@ -10,7 +16,7 @@ export interface ITracingProvider {
|
|
|
10
16
|
* @param spanKind Loại span (INTERNAL, SERVER, CLIENT, PRODUCER, CONSUMER)
|
|
11
17
|
* @returns Span object - cần gọi end() khi hoàn thành
|
|
12
18
|
*/
|
|
13
|
-
startSpan(name: string, attributes?: Record<string, string | number>, spanKind?: string):
|
|
19
|
+
startSpan(name: string, attributes?: Record<string, string | number>, spanKind?: string): ISpan | null;
|
|
14
20
|
/**
|
|
15
21
|
* Thực thi function với context tracing (auto-close span)
|
|
16
22
|
* @param name Tên của span
|
|
@@ -18,7 +24,7 @@ export interface ITracingProvider {
|
|
|
18
24
|
* @param attributes Các attributes metadata
|
|
19
25
|
* @returns Kết quả của function
|
|
20
26
|
*/
|
|
21
|
-
startSpanWithParent<T>(name: string, fn: (span:
|
|
27
|
+
startSpanWithParent<T>(name: string, fn: (span: ISpan | null) => Promise<T>, attributes?: Record<string, string | number>): Promise<T>;
|
|
22
28
|
/**
|
|
23
29
|
* Capture error vào active span hiện tại
|
|
24
30
|
* @param error Error object
|
|
@@ -30,11 +36,15 @@ export interface ITracingProvider {
|
|
|
30
36
|
* @param value Giá trị attribute
|
|
31
37
|
*/
|
|
32
38
|
setAttribute(key: string, value: string | number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Force flush all pending spans
|
|
41
|
+
*/
|
|
42
|
+
forceFlush?(): Promise<void>;
|
|
33
43
|
/**
|
|
34
44
|
* Kết thúc span manually
|
|
35
45
|
* @param span Span cần end (nếu không truyền, sẽ end active span)
|
|
36
46
|
*/
|
|
37
|
-
endSpan(span?:
|
|
47
|
+
endSpan(span?: ISpan | null): void;
|
|
38
48
|
/**
|
|
39
49
|
* Flush và shutdown provider (cho graceful shutdown)
|
|
40
50
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing-provider.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/tracing-provider.interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,SAAS,
|
|
1
|
+
{"version":3,"file":"tracing-provider.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/tracing-provider.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;;;;OAMG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC5C,QAAQ,CAAC,EAAE,MAAM,GAChB,KAAK,GAAG,IAAI,CAAC;IAEhB;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EACtC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC3C,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEjC;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAExD;;OAEG;IACH,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B;;;OAGG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IAEnC;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicModule } from
|
|
2
|
-
import { ApmProvider } from
|
|
1
|
+
import { DynamicModule, Type, ForwardReference } from "@nestjs/common";
|
|
2
|
+
import { ApmProvider } from "../types/apm-provider.type";
|
|
3
3
|
/**
|
|
4
4
|
* Options for configuring TracingModule
|
|
5
5
|
*/
|
|
@@ -83,14 +83,14 @@ export interface TracingModuleAsyncOptions {
|
|
|
83
83
|
/**
|
|
84
84
|
* Optional list of modules to import for the factory to use
|
|
85
85
|
*/
|
|
86
|
-
imports?:
|
|
86
|
+
imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference<unknown>>;
|
|
87
87
|
/**
|
|
88
88
|
* Factory function that returns the module options
|
|
89
89
|
*/
|
|
90
|
-
useFactory?: (...args:
|
|
90
|
+
useFactory?: (...args: unknown[]) => Promise<TracingModuleOptions> | TracingModuleOptions;
|
|
91
91
|
/**
|
|
92
92
|
* Optional list of providers to inject into the factory
|
|
93
93
|
*/
|
|
94
|
-
inject?:
|
|
94
|
+
inject?: (Type<object> | string | symbol)[];
|
|
95
95
|
}
|
|
96
96
|
//# sourceMappingURL=tracing.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.module.d.ts","sourceRoot":"","sources":["../../src/modules/tracing.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tracing.module.d.ts","sourceRoot":"","sources":["../../src/modules/tracing.module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMvF,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAGzD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6FAA6F;IAC7F,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBAEa,aAAa;IACxB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa;IAoBlE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,GAAE,yBAA8B,GAAG,aAAa;CAgC7E;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CACb,IAAI,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CACnF,CAAC;IAEF;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;IAE1F;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C"}
|
|
@@ -40,6 +40,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.TracingModule = void 0;
|
|
42
42
|
// @ts-ignore - Optional peer dependency
|
|
43
|
+
// @ts-ignore - Optional peer dependency
|
|
43
44
|
const common_1 = require("@nestjs/common");
|
|
44
45
|
const tracing_service_1 = require("../services/tracing.service");
|
|
45
46
|
const tracing_provider_factory_1 = require("../factories/tracing-provider.factory");
|
|
@@ -131,7 +132,7 @@ let TracingModule = (() => {
|
|
|
131
132
|
// Auto-initialize if configured
|
|
132
133
|
if (config.autoInit !== false) {
|
|
133
134
|
// Check if provider has initialize method (not in interface)
|
|
134
|
-
if (
|
|
135
|
+
if ("initialize" in provider && typeof provider.initialize === "function") {
|
|
135
136
|
await provider.initialize();
|
|
136
137
|
}
|
|
137
138
|
}
|