@moostjs/otel 0.6.47 → 0.6.49

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.cjs CHANGED
@@ -157,6 +157,33 @@ function _define_property(obj, key, value) {
157
157
  return obj;
158
158
  }
159
159
  const tracer = _opentelemetry_api.trace.getTracer("moost-tracer");
160
+ const NO_CONTROLLER_META = {};
161
+ /** Per (controller class, method) cache of {@link THandlerOtelMeta}: two metadata reads once, not per span. */ const handlerOtelMetaCache = /* @__PURE__ */ new WeakMap();
162
+ function readHandlerOtelMeta(controller, method) {
163
+ if (!controller) return NO_CONTROLLER_META;
164
+ const ctor = (0, moost.getConstructor)(controller);
165
+ let byMethod = handlerOtelMetaCache.get(ctor);
166
+ if (!byMethod) {
167
+ byMethod = /* @__PURE__ */ new Map();
168
+ handlerOtelMetaCache.set(ctor, byMethod);
169
+ }
170
+ let meta = byMethod.get(method);
171
+ if (!meta) {
172
+ const mate = (0, moost.getMoostMate)();
173
+ const cMeta = mate.read(controller);
174
+ const mMeta = mate.read(controller, method);
175
+ meta = {
176
+ ignoreSpan: cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
177
+ ignoreMeter: cMeta?.otelIgnoreMeter || mMeta?.otelIgnoreMeter,
178
+ controllerName: ctor.name,
179
+ description: mMeta?.description,
180
+ label: mMeta?.label,
181
+ id: mMeta?.id
182
+ };
183
+ byMethod.set(method, meta);
184
+ }
185
+ return meta;
186
+ }
160
187
  /** Context injector that wraps Moost lifecycle hooks with OpenTelemetry spans and records metrics. */ var SpanInjector = class extends moost.ContextInjector {
161
188
  with(name, attributes, cb) {
162
189
  const fn = typeof attributes === "function" ? attributes : cb;
@@ -211,27 +238,23 @@ const tracer = _opentelemetry_api.trace.getTracer("moost-tracer");
211
238
  return ctx.has(moost.eventTypeKey) ? ctx.get(moost.eventTypeKey) : void 0;
212
239
  }
213
240
  getIgnoreSpan() {
214
- const { getMethodMeta, getControllerMeta } = (0, moost.useControllerContext)();
215
- const cMeta = getControllerMeta();
216
- const mMeta = getMethodMeta();
217
- return cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan;
241
+ const { getController, getMethod } = (0, moost.useControllerContext)();
242
+ return readHandlerOtelMeta(getController(), getMethod()).ignoreSpan;
218
243
  }
219
244
  getControllerHandlerMeta() {
220
- const { getMethod, getMethodMeta, getController, getControllerMeta, getRoute } = (0, moost.useControllerContext)();
245
+ const { getMethod, getController, getRoute } = (0, moost.useControllerContext)();
221
246
  const methodName = getMethod();
222
- const controller = getController();
223
- const cMeta = controller ? getControllerMeta() : void 0;
224
- const mMeta = controller ? getMethodMeta() : void 0;
247
+ const meta = readHandlerOtelMeta(getController(), methodName);
225
248
  return {
226
- ignoreMeter: cMeta?.otelIgnoreMeter || mMeta?.otelIgnoreMeter,
227
- ignoreSpan: cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
249
+ ignoreMeter: meta.ignoreMeter,
250
+ ignoreSpan: meta.ignoreSpan,
228
251
  attrs: {
229
- "moost.controller": controller ? (0, moost.getConstructor)(controller).name : void 0,
252
+ "moost.controller": meta.controllerName,
230
253
  "moost.handler": methodName,
231
- "moost.handler_description": mMeta?.description,
232
- "moost.handler_label": mMeta?.label,
233
- "moost.handler_id": mMeta?.id,
234
- "moost.ignore": cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
254
+ "moost.handler_description": meta.description,
255
+ "moost.handler_label": meta.label,
256
+ "moost.handler_id": meta.id,
257
+ "moost.ignore": meta.ignoreSpan,
235
258
  "moost.route": getRoute(),
236
259
  "moost.event_type": this.getEventType()
237
260
  }
package/dist/index.mjs CHANGED
@@ -156,6 +156,33 @@ function _define_property(obj, key, value) {
156
156
  return obj;
157
157
  }
158
158
  const tracer = trace.getTracer("moost-tracer");
159
+ const NO_CONTROLLER_META = {};
160
+ /** Per (controller class, method) cache of {@link THandlerOtelMeta}: two metadata reads once, not per span. */ const handlerOtelMetaCache = /* @__PURE__ */ new WeakMap();
161
+ function readHandlerOtelMeta(controller, method) {
162
+ if (!controller) return NO_CONTROLLER_META;
163
+ const ctor = getConstructor(controller);
164
+ let byMethod = handlerOtelMetaCache.get(ctor);
165
+ if (!byMethod) {
166
+ byMethod = /* @__PURE__ */ new Map();
167
+ handlerOtelMetaCache.set(ctor, byMethod);
168
+ }
169
+ let meta = byMethod.get(method);
170
+ if (!meta) {
171
+ const mate = getMoostMate();
172
+ const cMeta = mate.read(controller);
173
+ const mMeta = mate.read(controller, method);
174
+ meta = {
175
+ ignoreSpan: cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
176
+ ignoreMeter: cMeta?.otelIgnoreMeter || mMeta?.otelIgnoreMeter,
177
+ controllerName: ctor.name,
178
+ description: mMeta?.description,
179
+ label: mMeta?.label,
180
+ id: mMeta?.id
181
+ };
182
+ byMethod.set(method, meta);
183
+ }
184
+ return meta;
185
+ }
159
186
  /** Context injector that wraps Moost lifecycle hooks with OpenTelemetry spans and records metrics. */ var SpanInjector = class extends ContextInjector {
160
187
  with(name, attributes, cb) {
161
188
  const fn = typeof attributes === "function" ? attributes : cb;
@@ -210,27 +237,23 @@ const tracer = trace.getTracer("moost-tracer");
210
237
  return ctx.has(eventTypeKey) ? ctx.get(eventTypeKey) : void 0;
211
238
  }
212
239
  getIgnoreSpan() {
213
- const { getMethodMeta, getControllerMeta } = useControllerContext();
214
- const cMeta = getControllerMeta();
215
- const mMeta = getMethodMeta();
216
- return cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan;
240
+ const { getController, getMethod } = useControllerContext();
241
+ return readHandlerOtelMeta(getController(), getMethod()).ignoreSpan;
217
242
  }
218
243
  getControllerHandlerMeta() {
219
- const { getMethod, getMethodMeta, getController, getControllerMeta, getRoute } = useControllerContext();
244
+ const { getMethod, getController, getRoute } = useControllerContext();
220
245
  const methodName = getMethod();
221
- const controller = getController();
222
- const cMeta = controller ? getControllerMeta() : void 0;
223
- const mMeta = controller ? getMethodMeta() : void 0;
246
+ const meta = readHandlerOtelMeta(getController(), methodName);
224
247
  return {
225
- ignoreMeter: cMeta?.otelIgnoreMeter || mMeta?.otelIgnoreMeter,
226
- ignoreSpan: cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
248
+ ignoreMeter: meta.ignoreMeter,
249
+ ignoreSpan: meta.ignoreSpan,
227
250
  attrs: {
228
- "moost.controller": controller ? getConstructor(controller).name : void 0,
251
+ "moost.controller": meta.controllerName,
229
252
  "moost.handler": methodName,
230
- "moost.handler_description": mMeta?.description,
231
- "moost.handler_label": mMeta?.label,
232
- "moost.handler_id": mMeta?.id,
233
- "moost.ignore": cMeta?.otelIgnoreSpan || mMeta?.otelIgnoreSpan,
253
+ "moost.handler_description": meta.description,
254
+ "moost.handler_label": meta.label,
255
+ "moost.handler_id": meta.id,
256
+ "moost.ignore": meta.ignoreSpan,
234
257
  "moost.route": getRoute(),
235
258
  "moost.event_type": this.getEventType()
236
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moostjs/otel",
3
- "version": "0.6.47",
3
+ "version": "0.6.49",
4
4
  "description": "@moostjs/otel",
5
5
  "keywords": [
6
6
  "composables",
@@ -45,9 +45,9 @@
45
45
  "vitest": "3.2.7"
46
46
  },
47
47
  "peerDependencies": {
48
- "@wooksjs/event-core": "^0.7.26",
49
- "@moostjs/event-http": "^0.6.47",
50
- "moost": "^0.6.47"
48
+ "@wooksjs/event-core": "^0.7.28",
49
+ "@moostjs/event-http": "^0.6.49",
50
+ "moost": "^0.6.49"
51
51
  },
52
52
  "scripts": {
53
53
  "pub": "pnpm publish --access public",