@vtvlive/interactive-apm 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { TracingModule, TracingModuleOptions, TracingModuleAsyncOptions, } from "./modules/tracing.module";
2
1
  export { TracingService } from "./services/tracing.service";
3
2
  export { TracingHelper } from "./utils/tracing.helper";
4
3
  export { ITracingProvider } from "./interfaces/tracing-provider.interface";
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,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"}
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
+ // Core exports — no NestJS dependency required
3
+ // For NestJS module integration, use: import { TracingModule } from '@vtvlive/interactive-apm/nestjs'
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldUseOpenTelemetry = exports.initOpenTelemetry = exports.shouldUseElasticApm = exports.getElasticApmAgent = exports.isElasticApmStarted = exports.initElasticApm = exports.TRACING_PROVIDER_TOKEN = exports.TracingProviderFactory = exports.createTracingProvider = exports.OpenTelemetryTracingProvider = exports.ElasticApmTracingProvider = exports.OtlpTransport = exports.SpanKind = exports.ApmProvider = exports.TracingHelper = exports.TracingService = exports.TracingModule = void 0;
4
- // Core exports - NestJS integration
5
- var tracing_module_1 = require("./modules/tracing.module");
6
- Object.defineProperty(exports, "TracingModule", { enumerable: true, get: function () { return tracing_module_1.TracingModule; } });
5
+ exports.shouldUseOpenTelemetry = exports.initOpenTelemetry = exports.shouldUseElasticApm = exports.getElasticApmAgent = exports.isElasticApmStarted = exports.initElasticApm = exports.TRACING_PROVIDER_TOKEN = exports.TracingProviderFactory = exports.createTracingProvider = exports.OpenTelemetryTracingProvider = exports.ElasticApmTracingProvider = exports.OtlpTransport = exports.SpanKind = exports.ApmProvider = exports.TracingHelper = exports.TracingService = void 0;
7
6
  // Services
8
7
  var tracing_service_1 = require("./services/tracing.service");
9
8
  Object.defineProperty(exports, "TracingService", { enumerable: true, get: function () { return tracing_service_1.TracingService; } });
@@ -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;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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C;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,CA+MD"}
@@ -55,13 +55,28 @@ const apm_provider_type_1 = require("../types/apm-provider.type");
55
55
  const otlp_transport_type_1 = require("../types/otlp-transport.type");
56
56
  const debug_logger_1 = require("../utils/debug-logger");
57
57
  const debug_exporter_wrapper_1 = require("../utils/debug-exporter-wrapper");
58
- // @ts-ignore - Optional peer dependency
59
- const api_1 = require("@opentelemetry/api");
60
58
  /**
61
59
  * Transaction Name Processor for OpenTelemetry
62
60
  * Sets transaction names to format: "GET /api/healthcheck/ping"
63
61
  */
64
62
  class TransactionNameProcessor {
63
+ constructor() {
64
+ this.cachedSpanKindServer = null;
65
+ }
66
+ getSpanKindServer() {
67
+ if (this.cachedSpanKindServer === null) {
68
+ try {
69
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
70
+ const { SpanKind } = require("@opentelemetry/api");
71
+ this.cachedSpanKindServer = SpanKind.SERVER;
72
+ }
73
+ catch {
74
+ // @opentelemetry/api not available
75
+ return null;
76
+ }
77
+ }
78
+ return this.cachedSpanKindServer;
79
+ }
65
80
  onStart(_span) {
66
81
  // No-op - moved to onEnd to read final http.route
67
82
  }
@@ -73,8 +88,9 @@ class TransactionNameProcessor {
73
88
  }
74
89
  onEnd(_span) {
75
90
  const span = _span;
76
- // Only process root spans (SERVER spans without parent)
77
- if (span.parent || span.kind !== api_1.SpanKind.SERVER) {
91
+ const serverKind = this.getSpanKindServer();
92
+ // Only process root SERVER spans without parent
93
+ if (serverKind === null || span.parent || span.kind !== serverKind) {
78
94
  return;
79
95
  }
80
96
  // Get HTTP attributes (http.route is often set after routing completes)
@@ -236,16 +252,16 @@ async function initOpenTelemetry(options = {}) {
236
252
  const { ExpressInstrumentation } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/instrumentation-express")));
237
253
  instrumentations.push(new ExpressInstrumentation());
238
254
  }
239
- console.log('[DEBUG] About to load Redis instrumentation...');
255
+ console.log("[DEBUG] About to load Redis instrumentation...");
240
256
  try {
241
257
  const { IORedisInstrumentation } = await Promise.resolve().then(() => __importStar(require("@opentelemetry/instrumentation-ioredis")));
242
- console.log('[DEBUG] Redis import successful');
258
+ console.log("[DEBUG] Redis import successful");
243
259
  instrumentations.push(new IORedisInstrumentation());
244
- console.log('[DEBUG] Redis instrumentation added');
260
+ console.log("[DEBUG] Redis instrumentation added");
245
261
  (0, debug_logger_1.infoLog)("[OpenTelemetry] Redis instrumentation enabled");
246
262
  }
247
263
  catch (err) {
248
- console.error('[DEBUG] Redis instrumentation failed:', err);
264
+ console.error("[DEBUG] Redis instrumentation failed:", err);
249
265
  (0, debug_logger_1.infoLog)("[OpenTelemetry] Redis instrumentation not available");
250
266
  }
251
267
  // Resource attributes
@@ -1,4 +1,4 @@
1
- import { DynamicModule, Type, ForwardReference } from "@nestjs/common";
1
+ import type { DynamicModule, Type, ForwardReference } from "@nestjs/common";
2
2
  import { ApmProvider } from "../types/apm-provider.type";
3
3
  /**
4
4
  * Options for configuring TracingModule
@@ -1 +1 @@
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,WAA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AC,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C"}
@@ -1,47 +1,6 @@
1
1
  "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
- if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
- };
40
2
  Object.defineProperty(exports, "__esModule", { value: true });
41
3
  exports.TracingModule = void 0;
42
- // @ts-ignore - Optional peer dependency
43
- // @ts-ignore - Optional peer dependency
44
- const common_1 = require("@nestjs/common");
45
4
  const tracing_service_1 = require("../services/tracing.service");
46
5
  const tracing_provider_factory_1 = require("../factories/tracing-provider.factory");
47
6
  /**
@@ -89,75 +48,72 @@ const tracing_provider_factory_1 = require("../factories/tracing-provider.factor
89
48
  * }
90
49
  * }
91
50
  */
92
- let TracingModule = (() => {
93
- let _classDecorators = [(0, common_1.Global)(), (0, common_1.Module)({})];
94
- let _classDescriptor;
95
- let _classExtraInitializers = [];
96
- let _classThis;
97
- var TracingModule = _classThis = class {
98
- /**
99
- * Register module with synchronous options
100
- */
101
- static register(options = {}) {
102
- const tracingProvider = (0, tracing_provider_factory_1.createTracingProvider)(options);
103
- return {
104
- module: TracingModule,
105
- providers: [
106
- {
107
- provide: tracing_provider_factory_1.TRACING_PROVIDER_TOKEN,
108
- useValue: tracingProvider,
109
- },
110
- {
111
- provide: tracing_service_1.TracingService,
112
- useFactory: (provider) => new tracing_service_1.TracingService(provider),
113
- inject: [tracing_provider_factory_1.TRACING_PROVIDER_TOKEN],
114
- },
115
- ],
116
- exports: [tracing_service_1.TracingService],
117
- };
118
- }
119
- /**
120
- * Register module with asynchronous options (using ConfigService)
121
- */
122
- static registerAsync(options = {}) {
123
- return {
124
- module: TracingModule,
125
- imports: options.imports || [],
126
- providers: [
127
- {
128
- provide: tracing_provider_factory_1.TRACING_PROVIDER_TOKEN,
129
- useFactory: async (...args) => {
130
- const config = options.useFactory ? await options.useFactory(...args) : {};
131
- const provider = (0, tracing_provider_factory_1.createTracingProvider)(config);
132
- // Auto-initialize if configured
133
- if (config.autoInit !== false) {
134
- // Check if provider has initialize method (not in interface)
135
- if ("initialize" in provider && typeof provider.initialize === "function") {
136
- await provider.initialize();
137
- }
51
+ class TracingModule {
52
+ /**
53
+ * Register module with synchronous options
54
+ */
55
+ static register(options = {}) {
56
+ const tracingProvider = (0, tracing_provider_factory_1.createTracingProvider)(options);
57
+ return {
58
+ module: TracingModule,
59
+ providers: [
60
+ {
61
+ provide: tracing_provider_factory_1.TRACING_PROVIDER_TOKEN,
62
+ useValue: tracingProvider,
63
+ },
64
+ {
65
+ provide: tracing_service_1.TracingService,
66
+ useFactory: (provider) => new tracing_service_1.TracingService(provider),
67
+ inject: [tracing_provider_factory_1.TRACING_PROVIDER_TOKEN],
68
+ },
69
+ ],
70
+ exports: [tracing_service_1.TracingService],
71
+ };
72
+ }
73
+ /**
74
+ * Register module with asynchronous options (using ConfigService)
75
+ */
76
+ static registerAsync(options = {}) {
77
+ return {
78
+ module: TracingModule,
79
+ imports: options.imports || [],
80
+ providers: [
81
+ {
82
+ provide: tracing_provider_factory_1.TRACING_PROVIDER_TOKEN,
83
+ useFactory: async (...args) => {
84
+ const config = options.useFactory ? await options.useFactory(...args) : {};
85
+ const provider = (0, tracing_provider_factory_1.createTracingProvider)(config);
86
+ // Auto-initialize if configured
87
+ if (config.autoInit !== false) {
88
+ // Check if provider has initialize method (not in interface)
89
+ if ("initialize" in provider && typeof provider.initialize === "function") {
90
+ await provider.initialize();
138
91
  }
139
- return provider;
140
- },
141
- inject: options.inject || [],
142
- },
143
- {
144
- provide: tracing_service_1.TracingService,
145
- useFactory: (provider) => new tracing_service_1.TracingService(provider),
146
- inject: [tracing_provider_factory_1.TRACING_PROVIDER_TOKEN],
92
+ }
93
+ return provider;
147
94
  },
148
- ],
149
- exports: [tracing_service_1.TracingService],
150
- };
151
- }
152
- };
153
- __setFunctionName(_classThis, "TracingModule");
154
- (() => {
155
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
156
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
157
- TracingModule = _classThis = _classDescriptor.value;
158
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
159
- __runInitializers(_classThis, _classExtraInitializers);
160
- })();
161
- return TracingModule = _classThis;
162
- })();
95
+ inject: options.inject || [],
96
+ },
97
+ {
98
+ provide: tracing_service_1.TracingService,
99
+ useFactory: (provider) => new tracing_service_1.TracingService(provider),
100
+ inject: [tracing_provider_factory_1.TRACING_PROVIDER_TOKEN],
101
+ },
102
+ ],
103
+ exports: [tracing_service_1.TracingService],
104
+ };
105
+ }
106
+ }
163
107
  exports.TracingModule = TracingModule;
108
+ // Apply NestJS module decorators at runtime when @nestjs/common is available.
109
+ // Safe no-op when running without NestJS — TracingModule then works as a plain class
110
+ // with static register() / registerAsync() factory methods only.
111
+ try {
112
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
113
+ const { Module, Global } = require("@nestjs/common");
114
+ Module({})(TracingModule);
115
+ Global()(TracingModule);
116
+ }
117
+ catch {
118
+ // @nestjs/common not installed — decorators skipped
119
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * NestJS integration entry point.
3
+ *
4
+ * Use this path when integrating with NestJS. Requires `@nestjs/common` to be installed.
5
+ *
6
+ * @example
7
+ * // app.module.ts
8
+ * import { TracingModule } from '@vtvlive/interactive-apm/nestjs';
9
+ *
10
+ * @Module({
11
+ * imports: [
12
+ * TracingModule.register({ provider: 'opentelemetry', serviceName: 'my-service' }),
13
+ * ],
14
+ * })
15
+ * export class AppModule {}
16
+ *
17
+ * @example
18
+ * // In a service or controller
19
+ * import { TracingService } from '@vtvlive/interactive-apm/nestjs';
20
+ *
21
+ * constructor(private readonly tracing: TracingService) {}
22
+ */
23
+ export * from "./index";
24
+ export { TracingModule } from "./modules/tracing.module";
25
+ export type { TracingModuleOptions, TracingModuleAsyncOptions } from "./modules/tracing.module";
26
+ //# sourceMappingURL=nestjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestjs.d.ts","sourceRoot":"","sources":["../src/nestjs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/nestjs.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * NestJS integration entry point.
4
+ *
5
+ * Use this path when integrating with NestJS. Requires `@nestjs/common` to be installed.
6
+ *
7
+ * @example
8
+ * // app.module.ts
9
+ * import { TracingModule } from '@vtvlive/interactive-apm/nestjs';
10
+ *
11
+ * @Module({
12
+ * imports: [
13
+ * TracingModule.register({ provider: 'opentelemetry', serviceName: 'my-service' }),
14
+ * ],
15
+ * })
16
+ * export class AppModule {}
17
+ *
18
+ * @example
19
+ * // In a service or controller
20
+ * import { TracingService } from '@vtvlive/interactive-apm/nestjs';
21
+ *
22
+ * constructor(private readonly tracing: TracingService) {}
23
+ */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.TracingModule = void 0;
40
+ // Re-export everything from the main (NestJS-free) entry point
41
+ __exportStar(require("./index"), exports);
42
+ // NestJS-specific exports — these require @nestjs/common to be installed
43
+ var tracing_module_1 = require("./modules/tracing.module");
44
+ Object.defineProperty(exports, "TracingModule", { enumerable: true, get: function () { return tracing_module_1.TracingModule; } });
@@ -148,7 +148,7 @@ class TracingHelper {
148
148
  const span = apmSpan;
149
149
  // Add OpenTelemetry-compatible methods to elastic-apm span
150
150
  // This allows code using TracingHelper to work with both providers
151
- if (span && typeof apmSpan.setLabel === 'function') {
151
+ if (span && typeof apmSpan.setLabel === "function") {
152
152
  const originalSetLabel = apmSpan.setLabel.bind(apmSpan);
153
153
  // Add setAttribute method that maps to setLabel
154
154
  span.setAttribute = (key, value) => {
package/package.json CHANGED
@@ -1,10 +1,24 @@
1
1
  {
2
2
  "name": "@vtvlive/interactive-apm",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "APM integration package supporting both Elastic APM and OpenTelemetry with NestJS integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "exports": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./nestjs": {
13
+ "types": "./dist/nestjs.d.ts",
14
+ "default": "./dist/nestjs.js"
15
+ }
16
+ },
17
+ "typesVersions": {
18
+ "*": {
19
+ "nestjs": ["dist/nestjs.d.ts"]
20
+ }
21
+ },
8
22
  "keywords": [
9
23
  "apm",
10
24
  "elastic-apm",
@@ -42,9 +56,9 @@
42
56
  "@opentelemetry/exporter-trace-otlp-http": ">=0.40.0",
43
57
  "@opentelemetry/exporter-trace-otlp-grpc": ">=0.40.0",
44
58
  "@opentelemetry/exporter-trace-otlp-proto": ">=0.40.0",
45
- "@opentelemetry/instrumentation-express": ">=0.40.0",
59
+ "@opentelemetry/instrumentation-express": ">=0.33.0",
46
60
  "@opentelemetry/instrumentation-http": ">=0.40.0",
47
- "@opentelemetry/instrumentation-ioredis": ">=0.50.0",
61
+ "@opentelemetry/instrumentation-ioredis": ">=0.35.0",
48
62
  "@opentelemetry/resources": ">=1.0.0",
49
63
  "@opentelemetry/sdk-node": ">=0.40.0",
50
64
  "@opentelemetry/sdk-trace-base": ">=1.0.0",
@@ -102,9 +116,9 @@
102
116
  "@opentelemetry/exporter-trace-otlp-http": "^0.56.0",
103
117
  "@opentelemetry/exporter-trace-otlp-grpc": "^0.56.0",
104
118
  "@opentelemetry/exporter-trace-otlp-proto": "^0.56.0",
105
- "@opentelemetry/instrumentation-express": "^0.56.0",
119
+ "@opentelemetry/instrumentation-express": "0.46.0",
106
120
  "@opentelemetry/instrumentation-http": "^0.56.0",
107
- "@opentelemetry/instrumentation-ioredis": "^0.56.0",
121
+ "@opentelemetry/instrumentation-ioredis": "0.46.0",
108
122
  "@opentelemetry/resources": "^1.30.0",
109
123
  "@opentelemetry/sdk-node": "^0.56.0",
110
124
  "@opentelemetry/sdk-trace-base": "^1.29.0",