@@ -30,36 +30,41 @@ const ArrayPrototypeSplice = makeCall(Array.prototype.splice)
3030
3131/**
3232 * @property {object } agent A New Relic Node.js agent instance.
33- * @property {object } logger An agent logger instance.
33+ * @property {TracingChannel } channel The tracing channel instance this subscriber will be monitoring.
34+ * @property {string } channelName A unique name for the diagnostics channel
35+ * that will be registered.
3436 * @property {object } config The agent configuration object.
37+ * @property {string } id A unique identifier for the subscriber, combining the prefix, package
38+ * name, and channel name.
39+ * @property {object } logger An agent logger instance.
3540 * @property {string } packageName The name of the module being instrumented.
3641 * This is the same string one would pass to the `require` function.
37- * @property {string } channelName A unique name for the diagnostics channel
38- * that will be registered.
42+ * @property {AsyncLocalStorage } store The async local storage instance used for context management.
43+ * @property {number } [callback=null] Position of callback if it needs to be wrapped for instrumentation.
44+ * -1 means last argument.
3945 * @property {string[] } [events=[]] Set of tracing channel event names to
4046 * register handlers for. For any name in the set, a corresponding method
4147 * must exist on the subscriber instance. The method will be passed the
4248 * event object. Possible event names are `start`, `end`, `asyncStart`,
4349 * `asyncEnd`, and `error`.
44- *
45- * See {@link https://nodejs.org/api/diagnostics_channel.html#class-tracingchannel}
46- * @property {boolean } [opaque=false] If true, any children segments will not be created.
50+ * See {@link https://nodejs.org/api/diagnostics_channel.html#class-tracingchannel}
4751 * @property {boolean } [internal=false] If true, any children segments from the same library
4852 * will not be created.
53+ * @property {boolean } [opaque=false] If true, any children segments will not be created.
4954 * @property {string } [prefix='orchestrion:'] String to prepend to diagnostics
5055 * channel event names. This provides a namespace for the events we are
5156 * injecting into a module.
52- * @property {boolean } [requireActiveTx=true] If true, the subscriber will only handle events
53- * when there is an active transaction.
5457 * @property {boolean } [propagateContext=false] If true, it will bind `asyncStart` to the store
5558 * and re-propagate the active context. It will also attach the `transaction` to the event in
5659 * `start.bindStore`. This is used for functions that queue async code and context is lost.
57- * @property {string } id A unique identifier for the subscriber, combining the prefix, package
58- * name, and channel name.
59- * @property {TracingChannel } channel The tracing channel instance this subscriber will be monitoring.
60- * @property {AsyncLocalStorage } store The async local storage instance used for context management.
61- * @property {number } [callback=null] Position of callback if it needs to be wrapped for instrumentation.
62- * -1 means last argument.
60+ * @property {boolean } [requireActiveTx=true] If true, the subscriber will only handle events
61+ * when there is an active transaction.
62+ * @property {object } [targetModuleMeta] Defines the target module's name and
63+ * version string, i.e. is an object `{ name, version }`. This is only necessary
64+ * when target instrumentation can surface an unexpected name for the
65+ * `packageName` property. For example, `express` uses multiple modules to
66+ * compose its core functionality. We want to track things under the `express`
67+ * name, but `packageName` will be set to `router` is most cases.
6368 */
6469class Subscriber {
6570 #usageMetricRecorded = false
@@ -239,10 +244,11 @@ class Subscriber {
239244 */
240245 const handler = ( data ) => {
241246 if ( this . #usageMetricRecorded === false ) {
247+ const meta = this . targetModuleMeta
242248 recordSupportabilityMetric ( {
243249 agent : this . agent ,
244- moduleName : this . packageName ,
245- moduleVersion : data . moduleVersion
250+ moduleName : meta ?. name || this . packageName ,
251+ moduleVersion : meta ?. version || data . moduleVersion
246252 } )
247253 this . #usageMetricRecorded = true
248254 }
0 commit comments