@opentelemetry/instrumentation-hapi 0.37.0 → 0.38.0

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/README.md CHANGED
@@ -21,7 +21,7 @@ npm install --save @opentelemetry/instrumentation-hapi
21
21
 
22
22
  ### Supported Versions
23
23
 
24
- - `>=17.0.0 <21`
24
+ - `>=17.0.0 <22`
25
25
 
26
26
  ## Usage
27
27
 
@@ -24,23 +24,16 @@ const internal_types_1 = require("./internal-types");
24
24
  const utils_1 = require("./utils");
25
25
  /** Hapi instrumentation for OpenTelemetry */
26
26
  class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
27
- constructor(config) {
27
+ constructor(config = {}) {
28
28
  super('@opentelemetry/instrumentation-hapi', version_1.VERSION, config);
29
29
  }
30
30
  init() {
31
- return new instrumentation_1.InstrumentationNodeModuleDefinition(internal_types_1.HapiComponentName, ['>=17 <21'], (moduleExports) => {
31
+ return new instrumentation_1.InstrumentationNodeModuleDefinition(internal_types_1.HapiComponentName, ['>=17 <22'], (moduleExports) => {
32
32
  if (!(0, instrumentation_1.isWrapped)(moduleExports.server)) {
33
33
  this._wrap(moduleExports, 'server', this._getServerPatch.bind(this));
34
34
  }
35
- // Casting as any is necessary here due to an issue with the @types/hapi__hapi
36
- // type definition for Hapi.Server. Hapi.Server (note the uppercase) can also function
37
- // as a factory function, similarly to Hapi.server (lowercase), and so should
38
- // also be supported and instrumented. This is an issue with the DefinitelyTyped repo.
39
- // Function is defined at: https://github.com/hapijs/hapi/blob/main/lib/index.js#L9
40
35
  if (!(0, instrumentation_1.isWrapped)(moduleExports.Server)) {
41
- this._wrap(
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- moduleExports, 'Server', this._getServerPatch.bind(this));
36
+ this._wrap(moduleExports, 'Server', this._getServerPatch.bind(this));
44
37
  }
45
38
  return moduleExports;
46
39
  }, (moduleExports) => {
@@ -87,16 +80,16 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
87
80
  */
88
81
  _getServerRegisterPatch(original) {
89
82
  const instrumentation = this;
90
- api.diag.debug('Patching Hapi.Server register function');
91
83
  return function register(pluginInput, options) {
92
- var _a, _b, _c, _d, _e, _f;
93
84
  if (Array.isArray(pluginInput)) {
94
85
  for (const pluginObj of pluginInput) {
95
- instrumentation._wrapRegisterHandler((_c = (_b = (_a = pluginObj.plugin) === null || _a === void 0 ? void 0 : _a.plugin) !== null && _b !== void 0 ? _b : pluginObj.plugin) !== null && _c !== void 0 ? _c : pluginObj);
86
+ const plugin = (0, utils_1.getPluginFromInput)(pluginObj);
87
+ instrumentation._wrapRegisterHandler(plugin);
96
88
  }
97
89
  }
98
90
  else {
99
- instrumentation._wrapRegisterHandler((_f = (_e = (_d = pluginInput.plugin) === null || _d === void 0 ? void 0 : _d.plugin) !== null && _e !== void 0 ? _e : pluginInput.plugin) !== null && _f !== void 0 ? _f : pluginInput);
91
+ const plugin = (0, utils_1.getPluginFromInput)(pluginInput);
92
+ instrumentation._wrapRegisterHandler(plugin);
100
93
  }
101
94
  return original.apply(this, [pluginInput, options]);
102
95
  };
@@ -113,7 +106,6 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
113
106
  */
114
107
  _getServerExtPatch(original, pluginName) {
115
108
  const instrumentation = this;
116
- api.diag.debug('Patching Hapi.Server ext function');
117
109
  return function ext(...args) {
118
110
  if (Array.isArray(args[0])) {
119
111
  const eventsList = args[0];
@@ -154,7 +146,6 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
154
146
  */
155
147
  _getServerRoutePatch(original, pluginName) {
156
148
  const instrumentation = this;
157
- api.diag.debug('Patching Hapi.Server route function');
158
149
  return function route(route) {
159
150
  if (Array.isArray(route)) {
160
151
  for (let i = 0; i < route.length; i++) {
@@ -180,7 +171,6 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
180
171
  const oldHandler = plugin.register;
181
172
  const self = this;
182
173
  const newRegisterHandler = function (server, options) {
183
- server.route;
184
174
  self._wrap(server, 'route', original => {
185
175
  return instrumentation._getServerRoutePatch.bind(instrumentation)(original, pluginName);
186
176
  });
@@ -254,16 +244,15 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
254
244
  * for adding this server route. Else, signifies that the route was added directly
255
245
  */
256
246
  _wrapRouteHandler(route, pluginName) {
257
- var _a, _b, _c;
247
+ var _a;
258
248
  const instrumentation = this;
259
249
  if (route[internal_types_1.handlerPatched] === true)
260
250
  return route;
261
251
  route[internal_types_1.handlerPatched] = true;
262
- const oldHandler = (_b = (_a = route.options) === null || _a === void 0 ? void 0 : _a.handler) !== null && _b !== void 0 ? _b : route.handler;
263
- if (typeof oldHandler === 'function') {
264
- const newHandler = async function (...params) {
252
+ const wrapHandler = oldHandler => {
253
+ return async function (...params) {
265
254
  if (api.trace.getSpan(api.context.active()) === undefined) {
266
- return await oldHandler(...params);
255
+ return await oldHandler.call(this, ...params);
267
256
  }
268
257
  const rpcMetadata = (0, core_1.getRPCMetadata)(api.context.active());
269
258
  if ((rpcMetadata === null || rpcMetadata === void 0 ? void 0 : rpcMetadata.type) === core_1.RPCType.HTTP) {
@@ -274,7 +263,7 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
274
263
  attributes: metadata.attributes,
275
264
  });
276
265
  try {
277
- return await api.context.with(api.trace.setSpan(api.context.active(), span), () => oldHandler(...params));
266
+ return await api.context.with(api.trace.setSpan(api.context.active(), span), () => oldHandler.call(this, ...params));
278
267
  }
279
268
  catch (err) {
280
269
  span.recordException(err);
@@ -288,12 +277,22 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
288
277
  span.end();
289
278
  }
290
279
  };
291
- if ((_c = route.options) === null || _c === void 0 ? void 0 : _c.handler) {
292
- route.options.handler = newHandler;
293
- }
294
- else {
295
- route.handler = newHandler;
296
- }
280
+ };
281
+ if (typeof route.handler === 'function') {
282
+ route.handler = wrapHandler(route.handler);
283
+ }
284
+ else if (typeof route.options === 'function') {
285
+ const oldOptions = route.options;
286
+ route.options = function (server) {
287
+ const options = oldOptions(server);
288
+ if (typeof options.handler === 'function') {
289
+ options.handler = wrapHandler(options.handler);
290
+ }
291
+ return options;
292
+ };
293
+ }
294
+ else if (typeof ((_a = route.options) === null || _a === void 0 ? void 0 : _a.handler) === 'function') {
295
+ route.options.handler = wrapHandler(route.options.handler);
297
296
  }
298
297
  return route;
299
298
  }
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,8CAA8D;AAC9D,oEAKwC;AAIxC,uCAAoC;AACpC,qDAU0B;AAC1B,mCAQiB;AAEjB,6CAA6C;AAC7C,MAAa,mBAAoB,SAAQ,qCAAmB;IAC1D,YAAY,MAA8B;QACxC,KAAK,CAAC,qCAAqC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAES,IAAI;QACZ,OAAO,IAAI,qDAAmC,CAC5C,kCAAiB,EACjB,CAAC,UAAU,CAAC,EACZ,CAAC,aAA0B,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAA,2BAAS,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBACpC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACtE;YAED,8EAA8E;YAC9E,sFAAsF;YACtF,6EAA6E;YAC7E,sFAAsF;YACtF,mFAAmF;YACnF,IAAI,CAAC,IAAA,2BAAS,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBACpC,IAAI,CAAC,KAAK;gBACR,8DAA8D;gBAC9D,aAAoB,EACpB,QAAQ,EACR,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC,CAAC;aACH;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,EACD,C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;AA/WD,kDA+WC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\n\n// types for @hapi/hapi are published under @types/hapi__hapi\nimport type * as Hapi from 'hapi__hapi';\nimport { VERSION } from './version';\nimport {\n HapiComponentName,\n HapiServerRouteInput,\n handlerPatched,\n PatchableServerRoute,\n HapiServerRouteInputMethod,\n HapiPluginInput,\n RegisterFunction,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport {\n getRouteMetadata,\n getPluginName,\n isLifecycleExtType,\n isLifecycleExtEventObj,\n getExtMetadata,\n isDirectExtInput,\n isPatchableExtMethod,\n} from './utils';\n\n/** Hapi instrumentation for OpenTelemetry */\nexport class HapiInstrumentation extends InstrumentationBase {\n constructor(config?: InstrumentationConfig) {\n super('@opentelemetry/instrumentation-hapi', VERSION, config);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17 <21'],\n (moduleExports: typeof Hapi) => {\n if (!isWrapped(moduleExports.server)) {\n this._wrap(moduleExports, 'server', this._getServerPatch.bind(this));\n }\n\n // Casting as any is necessary here due to an issue with the @types/hapi__hapi\n // type definition for Hapi.Server. Hapi.Server (note the uppercase) can also function\n // as a factory function, similarly to Hapi.server (lowercase), and so should\n // also be supported and instrumented. This is an issue with the DefinitelyTyped repo.\n // Function is defined at: https://github.com/hapijs/hapi/blob/main/lib/index.js#L9\n if (!isWrapped(moduleExports.Server)) {\n this._wrap(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports as any,\n 'Server',\n this._getServerPatch.bind(this)\n );\n }\n return moduleExports;\n },\n (moduleExports: typeof Hapi) => {\n this._massUnwrap([moduleExports], ['server', 'Server']);\n }\n );\n }\n\n /**\n * Patches the Hapi.server and Hapi.Server functions in order to instrument\n * the server.route, server.ext, and server.register functions via calls to the\n * @function _getServerRoutePatch, @function _getServerExtPatch, and\n * @function _getServerRegisterPatch functions\n * @param original - the original Hapi Server creation function\n */\n private _getServerPatch(\n original: (options?: Hapi.ServerOptions) => Hapi.Server\n ) {\n const instrumentation: HapiInstrumentation = this;\n const self = this;\n return function server(this: Hapi.Server, opts?: Hapi.ServerOptions) {\n const newServer: Hapi.Server = original.apply(this, [opts]);\n\n self._wrap(newServer, 'route', originalRouter => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(\n originalRouter\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(newServer, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalExtHandler as any\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.Server.register\n // function, which requires supporting a variety of different types of Plugin inputs\n self._wrap(\n newServer,\n 'register',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n instrumentation._getServerRegisterPatch.bind(instrumentation) as any\n );\n return newServer;\n };\n }\n\n /**\n * Patches the plugin register function used by the Hapi Server. This function\n * goes through each plugin that is being registered and adds instrumentation\n * via a call to the @function _wrapRegisterHandler function.\n * @param {RegisterFunction<T>} original - the original register function which\n * registers each plugin on the server\n */\n private _getServerRegisterPatch<T>(\n original: RegisterFunction<T>\n ): RegisterFunction<T> {\n const instrumentation: HapiInstrumentation = this;\n api.diag.debug('Patching Hapi.Server register function');\n return function register(\n this: Hapi.Server,\n pluginInput: HapiPluginInput<T>,\n options?: Hapi.ServerRegisterOptions\n ) {\n if (Array.isArray(pluginInput)) {\n for (const pluginObj of pluginInput) {\n instrumentation._wrapRegisterHandler(\n pluginObj.plugin?.plugin ?? pluginObj.plugin ?? pluginObj\n );\n }\n } else {\n instrumentation._wrapRegisterHandler(\n pluginInput.plugin?.plugin ?? pluginInput.plugin ?? pluginInput\n );\n }\n return original.apply(this, [pluginInput, options]);\n };\n }\n\n /**\n * Patches the Server.ext function which adds extension methods to the specified\n * point along the request lifecycle. This function accepts the full range of\n * accepted input into the standard Hapi `server.ext` function. For each extension,\n * it adds instrumentation to the handler via a call to the @function _wrapExtMethods\n * function.\n * @param original - the original ext function which adds the extension method to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server extension. Else, signifies that the extension was added directly\n */\n private _getServerExtPatch(\n original: (...args: unknown[]) => unknown,\n pluginName?: string\n ) {\n const instrumentation: HapiInstrumentation = this;\n api.diag.debug('Patching Hapi.Server ext function');\n\n return function ext(\n this: ThisParameterType<typeof original>,\n ...args: Parameters<typeof original>\n ) {\n if (Array.isArray(args[0])) {\n const eventsList:\n | Hapi.ServerExtEventsObject[]\n | Hapi.ServerExtEventsRequestObject[] = args[0];\n for (let i = 0; i < eventsList.length; i++) {\n const eventObj = eventsList[i];\n if (isLifecycleExtType(eventObj.type)) {\n const lifecycleEventObj =\n eventObj as Hapi.ServerExtEventsRequestObject;\n const handler = instrumentation._wrapExtMethods(\n lifecycleEventObj.method,\n eventObj.type,\n pluginName\n );\n lifecycleEventObj.method = handler;\n eventsList[i] = lifecycleEventObj;\n }\n }\n return original.apply(this, args);\n } else if (isDirectExtInput(args)) {\n const extInput: ServerExtDirectInput = args;\n const method: PatchableExtMethod = extInput[1];\n const handler = instrumentation._wrapExtMethods(\n method,\n extInput[0],\n pluginName\n );\n return original.apply(this, [extInput[0], handler, extInput[2]]);\n } else if (isLifecycleExtEventObj(args[0])) {\n const lifecycleEventObj = args[0];\n const handler = instrumentation._wrapExtMethods(\n lifecycleEventObj.method,\n lifecycleEventObj.type,\n pluginName\n );\n lifecycleEventObj.method = handler;\n return original.call(this, lifecycleEventObj);\n }\n return original.apply(this, args);\n };\n }\n\n /**\n * Patches the Server.route function. This function accepts either one or an array\n * of Hapi.ServerRoute objects and adds instrumentation on each route via a call to\n * the @function _wrapRouteHandler function.\n * @param {HapiServerRouteInputMethod} original - the original route function which adds\n * the route to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _getServerRoutePatch(\n original: HapiServerRouteInputMethod,\n pluginName?: string\n ) {\n const instrumentation: HapiInstrumentation = this;\n api.diag.debug('Patching Hapi.Server route function');\n return function route(\n this: Hapi.Server,\n route: HapiServerRouteInput\n ): void {\n if (Array.isArray(route)) {\n for (let i = 0; i < route.length; i++) {\n const newRoute = instrumentation._wrapRouteHandler.call(\n instrumentation,\n route[i],\n pluginName\n );\n route[i] = newRoute;\n }\n } else {\n route = instrumentation._wrapRouteHandler.call(\n instrumentation,\n route,\n pluginName\n );\n }\n return original.apply(this, [route]);\n };\n }\n\n /**\n * Wraps newly registered plugins to add instrumentation to the plugin's clone of\n * the original server. Specifically, wraps the server.route and server.ext functions\n * via calls to @function _getServerRoutePatch and @function _getServerExtPatch\n * @param {Hapi.Plugin<T>} plugin - the new plugin which is being instrumented\n */\n private _wrapRegisterHandler<T>(plugin: Hapi.Plugin<T>): void {\n const instrumentation: HapiInstrumentation = this;\n const pluginName = getPluginName(plugin);\n const oldHandler = plugin.register;\n const self = this;\n const newRegisterHandler = function (server: Hapi.Server, options: T) {\n server.route;\n self._wrap(server, 'route', original => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(\n original,\n pluginName\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(server, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalExtHandler as any,\n pluginName\n );\n });\n return oldHandler(server, options);\n };\n plugin.register = newRegisterHandler;\n }\n\n /**\n * Wraps request extension methods to add instrumentation to each new extension handler.\n * Patches each individual extension in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableExtMethod | PatchableExtMethod[]} method - the request extension\n * handler which is being instrumented\n * @param {Hapi.ServerRequestExtType} extPoint - the point in the Hapi request lifecycle\n * which this extension targets\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapExtMethods<T extends PatchableExtMethod | PatchableExtMethod[]>(\n method: T,\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string\n ): T {\n const instrumentation: HapiInstrumentation = this;\n\n if (method instanceof Array) {\n for (let i = 0; i < method.length; i++) {\n method[i] = instrumentation._wrapExtMethods(\n method[i],\n extPoint\n ) as PatchableExtMethod;\n }\n return method;\n } else if (isPatchableExtMethod(method)) {\n if (method[handlerPatched] === true) return method;\n method[handlerPatched] = true;\n\n const newHandler: PatchableExtMethod = async function (\n ...params: Parameters<Hapi.Lifecycle.Method>\n ) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await method.apply(this, params);\n }\n const metadata = getExtMetadata(extPoint, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with<\n Parameters<Hapi.Lifecycle.Method>,\n Hapi.Lifecycle.Method\n >(\n api.trace.setSpan(api.context.active(), span),\n method,\n undefined,\n ...params\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n return newHandler as T;\n }\n return method;\n }\n\n /**\n * Patches each individual route handler method in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableServerRoute} route - the route handler which is being instrumented\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapRouteHandler(\n route: PatchableServerRoute,\n pluginName?: string\n ): PatchableServerRoute {\n const instrumentation: HapiInstrumentation = this;\n if (route[handlerPatched] === true) return route;\n route[handlerPatched] = true;\n const oldHandler = route.options?.handler ?? route.handler;\n if (typeof oldHandler === 'function') {\n const newHandler: Hapi.Lifecycle.Method = async function (\n ...params: Parameters<Hapi.Lifecycle.Method>\n ) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await oldHandler(...params);\n }\n const rpcMetadata = getRPCMetadata(api.context.active());\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = route.path;\n }\n const metadata = getRouteMetadata(route, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with(\n api.trace.setSpan(api.context.active(), span),\n () => oldHandler(...params)\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n if (route.options?.handler) {\n route.options.handler = newHandler;\n } else {\n route.handler = newHandler;\n }\n }\n return route;\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,8CAA8D;AAC9D,oEAKwC;AAGxC,uCAAoC;AACpC,qDAU0B;AAC1B,mCASiB;AAEjB,6CAA6C;AAC7C,MAAa,mBAAoB,SAAQ,qCAAmB;IAC1D,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,qCAAqC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAES,IAAI;QACZ,OAAO,IAAI,qDAAmC,CAC5C,kCAAiB,EACjB,CAAC,UAAU,CAAC,EACZ,CAAC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AAG,WAAW,CAAC,KAAK,CAAC,OAAgC,CAAC,CAAC;SACrE;aAAM,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,EAAE;YAC9C,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC;YACjC,KAAK,CAAC,OAAO,GAAG,UAAU,MAAM;gBAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;gBACnC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE;oBACzC,OAAO,CAAC,OAAO,GAAG,WAAW,CAC3B,OAAO,CAAC,OAAgC,CACzC,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;SACH;aAAM,IAAI,OAAO,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,OAAO,CAAA,KAAK,UAAU,EAAE;YACvD,KAAK,CAAC,OAAO,CAAC,OAAO,GAAG,WAAW,CACjC,KAAK,CAAC,OAAO,CAAC,OAAgC,CAC/C,CAAC;SACH;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AApXD,kDAoXC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\n\nimport type * as Hapi from '@hapi/hapi';\nimport { VERSION } from './version';\nimport {\n HapiComponentName,\n HapiServerRouteInput,\n handlerPatched,\n PatchableServerRoute,\n HapiServerRouteInputMethod,\n HapiPluginInput,\n RegisterFunction,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport {\n getRouteMetadata,\n getPluginName,\n isLifecycleExtType,\n isLifecycleExtEventObj,\n getExtMetadata,\n isDirectExtInput,\n isPatchableExtMethod,\n getPluginFromInput,\n} from './utils';\n\n/** Hapi instrumentation for OpenTelemetry */\nexport class HapiInstrumentation extends InstrumentationBase {\n constructor(config: InstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-hapi', VERSION, config);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17 <22'],\n (moduleExports: typeof Hapi) => {\n if (!isWrapped(moduleExports.server)) {\n this._wrap(\n moduleExports,\n 'server',\n this._getServerPatch.bind(this) as any\n );\n }\n\n if (!isWrapped(moduleExports.Server)) {\n this._wrap(\n moduleExports,\n 'Server',\n this._getServerPatch.bind(this) as any\n );\n }\n return moduleExports;\n },\n (moduleExports: typeof Hapi) => {\n this._massUnwrap([moduleExports], ['server', 'Server']);\n }\n );\n }\n\n /**\n * Patches the Hapi.server and Hapi.Server functions in order to instrument\n * the server.route, server.ext, and server.register functions via calls to the\n * @function _getServerRoutePatch, @function _getServerExtPatch, and\n * @function _getServerRegisterPatch functions\n * @param original - the original Hapi Server creation function\n */\n private _getServerPatch(\n original: (options?: Hapi.ServerOptions) => Hapi.Server\n ) {\n const instrumentation: HapiInstrumentation = this;\n const self = this;\n return function server(this: Hapi.Server, opts?: Hapi.ServerOptions) {\n const newServer: Hapi.Server = original.apply(this, [opts]);\n\n self._wrap(newServer, 'route', originalRouter => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(\n originalRouter\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(newServer, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalExtHandler as any\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.Server.register\n // function, which requires supporting a variety of different types of Plugin inputs\n self._wrap(\n newServer,\n 'register',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n instrumentation._getServerRegisterPatch.bind(instrumentation) as any\n );\n return newServer;\n };\n }\n\n /**\n * Patches the plugin register function used by the Hapi Server. This function\n * goes through each plugin that is being registered and adds instrumentation\n * via a call to the @function _wrapRegisterHandler function.\n * @param {RegisterFunction<T>} original - the original register function which\n * registers each plugin on the server\n */\n private _getServerRegisterPatch<T>(\n original: RegisterFunction<T>\n ): RegisterFunction<T> {\n const instrumentation: HapiInstrumentation = this;\n return function register(\n this: Hapi.Server,\n pluginInput: HapiPluginInput<T>,\n options?: Hapi.ServerRegisterOptions\n ) {\n if (Array.isArray(pluginInput)) {\n for (const pluginObj of pluginInput) {\n const plugin = getPluginFromInput(pluginObj);\n instrumentation._wrapRegisterHandler(plugin);\n }\n } else {\n const plugin = getPluginFromInput(pluginInput);\n instrumentation._wrapRegisterHandler(plugin);\n }\n return original.apply(this, [pluginInput, options]);\n };\n }\n\n /**\n * Patches the Server.ext function which adds extension methods to the specified\n * point along the request lifecycle. This function accepts the full range of\n * accepted input into the standard Hapi `server.ext` function. For each extension,\n * it adds instrumentation to the handler via a call to the @function _wrapExtMethods\n * function.\n * @param original - the original ext function which adds the extension method to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server extension. Else, signifies that the extension was added directly\n */\n private _getServerExtPatch(\n original: (...args: unknown[]) => unknown,\n pluginName?: string\n ) {\n const instrumentation: HapiInstrumentation = this;\n\n return function ext(\n this: ThisParameterType<typeof original>,\n ...args: Parameters<typeof original>\n ) {\n if (Array.isArray(args[0])) {\n const eventsList:\n | Hapi.ServerExtEventsObject[]\n | Hapi.ServerExtEventsRequestObject[] = args[0];\n for (let i = 0; i < eventsList.length; i++) {\n const eventObj = eventsList[i];\n if (isLifecycleExtType(eventObj.type)) {\n const lifecycleEventObj =\n eventObj as Hapi.ServerExtEventsRequestObject;\n const handler = instrumentation._wrapExtMethods(\n lifecycleEventObj.method,\n eventObj.type,\n pluginName\n );\n lifecycleEventObj.method = handler;\n eventsList[i] = lifecycleEventObj;\n }\n }\n return original.apply(this, args);\n } else if (isDirectExtInput(args)) {\n const extInput: ServerExtDirectInput = args;\n const method: PatchableExtMethod = extInput[1];\n const handler = instrumentation._wrapExtMethods(\n method,\n extInput[0],\n pluginName\n );\n return original.apply(this, [extInput[0], handler, extInput[2]]);\n } else if (isLifecycleExtEventObj(args[0])) {\n const lifecycleEventObj = args[0];\n const handler = instrumentation._wrapExtMethods(\n lifecycleEventObj.method,\n lifecycleEventObj.type,\n pluginName\n );\n lifecycleEventObj.method = handler;\n return original.call(this, lifecycleEventObj);\n }\n return original.apply(this, args);\n };\n }\n\n /**\n * Patches the Server.route function. This function accepts either one or an array\n * of Hapi.ServerRoute objects and adds instrumentation on each route via a call to\n * the @function _wrapRouteHandler function.\n * @param {HapiServerRouteInputMethod} original - the original route function which adds\n * the route to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _getServerRoutePatch(\n original: HapiServerRouteInputMethod,\n pluginName?: string\n ) {\n const instrumentation: HapiInstrumentation = this;\n return function route(\n this: Hapi.Server,\n route: HapiServerRouteInput\n ): void {\n if (Array.isArray(route)) {\n for (let i = 0; i < route.length; i++) {\n const newRoute = instrumentation._wrapRouteHandler.call(\n instrumentation,\n route[i],\n pluginName\n );\n route[i] = newRoute;\n }\n } else {\n route = instrumentation._wrapRouteHandler.call(\n instrumentation,\n route,\n pluginName\n );\n }\n return original.apply(this, [route]);\n };\n }\n\n /**\n * Wraps newly registered plugins to add instrumentation to the plugin's clone of\n * the original server. Specifically, wraps the server.route and server.ext functions\n * via calls to @function _getServerRoutePatch and @function _getServerExtPatch\n * @param {Hapi.Plugin<T>} plugin - the new plugin which is being instrumented\n */\n private _wrapRegisterHandler<T>(plugin: Hapi.Plugin<T>): void {\n const instrumentation: HapiInstrumentation = this;\n const pluginName = getPluginName(plugin);\n const oldHandler = plugin.register;\n const self = this;\n const newRegisterHandler = function (server: Hapi.Server, options: T) {\n self._wrap(server, 'route', original => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(\n original,\n pluginName\n );\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(server, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalExtHandler as any,\n pluginName\n );\n });\n return oldHandler(server, options);\n };\n plugin.register = newRegisterHandler;\n }\n\n /**\n * Wraps request extension methods to add instrumentation to each new extension handler.\n * Patches each individual extension in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableExtMethod | PatchableExtMethod[]} method - the request extension\n * handler which is being instrumented\n * @param {Hapi.ServerRequestExtType} extPoint - the point in the Hapi request lifecycle\n * which this extension targets\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapExtMethods<T extends PatchableExtMethod | PatchableExtMethod[]>(\n method: T,\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string\n ): T {\n const instrumentation: HapiInstrumentation = this;\n if (method instanceof Array) {\n for (let i = 0; i < method.length; i++) {\n method[i] = instrumentation._wrapExtMethods(\n method[i],\n extPoint\n ) as PatchableExtMethod;\n }\n return method;\n } else if (isPatchableExtMethod(method)) {\n if (method[handlerPatched] === true) return method;\n method[handlerPatched] = true;\n\n const newHandler: PatchableExtMethod = async function (\n ...params: Parameters<Hapi.Lifecycle.Method>\n ) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await method.apply(this, params);\n }\n const metadata = getExtMetadata(extPoint, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with<\n Parameters<Hapi.Lifecycle.Method>,\n Hapi.Lifecycle.Method\n >(\n api.trace.setSpan(api.context.active(), span),\n method,\n undefined,\n ...params\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n return newHandler as T;\n }\n return method;\n }\n\n /**\n * Patches each individual route handler method in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableServerRoute} route - the route handler which is being instrumented\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapRouteHandler(\n route: PatchableServerRoute,\n pluginName?: string\n ): PatchableServerRoute {\n const instrumentation: HapiInstrumentation = this;\n if (route[handlerPatched] === true) return route;\n route[handlerPatched] = true;\n\n const wrapHandler: (\n oldHandler: Hapi.Lifecycle.Method\n ) => Hapi.Lifecycle.Method = oldHandler => {\n return async function (...params: Parameters<Hapi.Lifecycle.Method>) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await oldHandler.call(this, ...params);\n }\n const rpcMetadata = getRPCMetadata(api.context.active());\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = route.path;\n }\n const metadata = getRouteMetadata(route, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with(\n api.trace.setSpan(api.context.active(), span),\n () => oldHandler.call(this, ...params)\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n };\n\n if (typeof route.handler === 'function') {\n route.handler = wrapHandler(route.handler as Hapi.Lifecycle.Method);\n } else if (typeof route.options === 'function') {\n const oldOptions = route.options;\n route.options = function (server) {\n const options = oldOptions(server);\n if (typeof options.handler === 'function') {\n options.handler = wrapHandler(\n options.handler as Hapi.Lifecycle.Method\n );\n }\n return options;\n };\n } else if (typeof route.options?.handler === 'function') {\n route.options.handler = wrapHandler(\n route.options.handler as Hapi.Lifecycle.Method\n );\n }\n return route;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type * as Hapi from 'hapi__hapi';
1
+ import type * as Hapi from '@hapi/hapi';
2
2
  export declare const HapiComponentName = "@hapi/hapi";
3
3
  /**
4
4
  * This symbol is used to mark a Hapi route handler or server extension handler as
@@ -11,13 +11,8 @@ export declare type HapiServerRouteInputMethod = (route: HapiServerRouteInput) =
11
11
  export declare type HapiServerRouteInput = PatchableServerRoute | PatchableServerRoute[];
12
12
  export declare type PatchableServerRoute = Hapi.ServerRoute<any> & {
13
13
  [handlerPatched]?: boolean;
14
- options?: {
15
- handler?: Hapi.Lifecycle.Method;
16
- };
17
- };
18
- export declare type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T> & {
19
- plugin: Hapi.ServerRegisterPluginObject<T>;
20
14
  };
15
+ export declare type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T>;
21
16
  export declare type HapiPluginInput<T> = HapiPluginObject<T> | Array<HapiPluginObject<T>>;
22
17
  export declare type RegisterFunction<T> = (plugin: HapiPluginInput<T>, options?: Hapi.ServerRegisterOptions) => Promise<void>;
23
18
  export declare type PatchableExtMethod = Hapi.Lifecycle.Method & {
@@ -1 +1 @@
1
- {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../src/internal-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKU,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;;GAKG;AACU,QAAA,cAAc,GAAkB,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAsC/D,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,YAAY;CAClB,CAAC;AAEW,QAAA,wBAAwB,GAAG,IAAI,GAAG,CAAC;IAC9C,WAAW;IACX,eAAe;IACf,YAAY;IACZ,cAAc;IACd,eAAe;IACf,eAAe;IACf,WAAW;CACZ,CAAC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// types for @hapi/hapi are published under @types/hapi__hapi\nimport type * as Hapi from 'hapi__hapi';\n\nexport const HapiComponentName = '@hapi/hapi';\n\n/**\n * This symbol is used to mark a Hapi route handler or server extension handler as\n * already patched, since its possible to use these handlers multiple times\n * i.e. when allowing multiple versions of one plugin, or when registering a plugin\n * multiple times on different servers.\n */\nexport const handlerPatched: unique symbol = Symbol('hapi-handler-patched');\n\nexport type HapiServerRouteInputMethod = (route: HapiServerRouteInput) => void;\n\nexport type HapiServerRouteInput =\n | PatchableServerRoute\n | PatchableServerRoute[];\n\nexport type PatchableServerRoute = Hapi.ServerRoute<any> & {\n [handlerPatched]?: boolean;\n options?: {\n handler?: Hapi.Lifecycle.Method;\n };\n};\n\nexport type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T> & {\n plugin: Hapi.ServerRegisterPluginObject<T>;\n};\n\nexport type HapiPluginInput<T> =\n | HapiPluginObject<T>\n | Array<HapiPluginObject<T>>;\n\nexport type RegisterFunction<T> = (\n plugin: HapiPluginInput<T>,\n options?: Hapi.ServerRegisterOptions\n) => Promise<void>;\n\nexport type PatchableExtMethod = Hapi.Lifecycle.Method & {\n [handlerPatched]?: boolean;\n};\n\nexport type ServerExtDirectInput = [\n Hapi.ServerRequestExtType,\n Hapi.Lifecycle.Method,\n (Hapi.ServerExtOptions | undefined)?\n];\n\nexport const HapiLayerType = {\n ROUTER: 'router',\n PLUGIN: 'plugin',\n EXT: 'server.ext',\n};\n\nexport const HapiLifecycleMethodNames = new Set([\n 'onPreAuth',\n 'onCredentials',\n 'onPostAuth',\n 'onPreHandler',\n 'onPostHandler',\n 'onPreResponse',\n 'onRequest',\n]);\n"]}
1
+ {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../src/internal-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIU,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;;GAKG;AACU,QAAA,cAAc,GAAkB,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAiC/D,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,YAAY;CAClB,CAAC;AAEW,QAAA,wBAAwB,GAAG,IAAI,GAAG,CAAC;IAC9C,WAAW;IACX,eAAe;IACf,YAAY;IACZ,cAAc;IACd,eAAe;IACf,eAAe;IACf,WAAW;CACZ,CAAC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Hapi from '@hapi/hapi';\n\nexport const HapiComponentName = '@hapi/hapi';\n\n/**\n * This symbol is used to mark a Hapi route handler or server extension handler as\n * already patched, since its possible to use these handlers multiple times\n * i.e. when allowing multiple versions of one plugin, or when registering a plugin\n * multiple times on different servers.\n */\nexport const handlerPatched: unique symbol = Symbol('hapi-handler-patched');\n\nexport type HapiServerRouteInputMethod = (route: HapiServerRouteInput) => void;\n\nexport type HapiServerRouteInput =\n | PatchableServerRoute\n | PatchableServerRoute[];\n\nexport type PatchableServerRoute = Hapi.ServerRoute<any> & {\n [handlerPatched]?: boolean;\n};\n\nexport type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T>;\n\nexport type HapiPluginInput<T> =\n | HapiPluginObject<T>\n | Array<HapiPluginObject<T>>;\n\nexport type RegisterFunction<T> = (\n plugin: HapiPluginInput<T>,\n options?: Hapi.ServerRegisterOptions\n) => Promise<void>;\n\nexport type PatchableExtMethod = Hapi.Lifecycle.Method & {\n [handlerPatched]?: boolean;\n};\n\nexport type ServerExtDirectInput = [\n Hapi.ServerRequestExtType,\n Hapi.Lifecycle.Method,\n (Hapi.ServerExtOptions | undefined)?\n];\n\nexport const HapiLayerType = {\n ROUTER: 'router',\n PLUGIN: 'plugin',\n EXT: 'server.ext',\n};\n\nexport const HapiLifecycleMethodNames = new Set([\n 'onPreAuth',\n 'onCredentials',\n 'onPostAuth',\n 'onPreHandler',\n 'onPostHandler',\n 'onPreResponse',\n 'onRequest',\n]);\n"]}
@@ -1,6 +1,6 @@
1
1
  import { SpanAttributes } from '@opentelemetry/api';
2
2
  import type * as Hapi from '@hapi/hapi';
3
- import { PatchableExtMethod, ServerExtDirectInput } from './internal-types';
3
+ import { HapiPluginObject, PatchableExtMethod, ServerExtDirectInput } from './internal-types';
4
4
  export declare function getPluginName<T>(plugin: Hapi.Plugin<T>): string;
5
5
  export declare const isLifecycleExtType: (variableToCheck: unknown) => variableToCheck is Hapi.ServerRequestExtType;
6
6
  export declare const isLifecycleExtEventObj: (variableToCheck: unknown) => variableToCheck is Hapi.ServerExtEventsRequestObject;
@@ -14,4 +14,5 @@ export declare const getExtMetadata: (extPoint: Hapi.ServerRequestExtType, plugi
14
14
  attributes: SpanAttributes;
15
15
  name: string;
16
16
  };
17
+ export declare const getPluginFromInput: <T>(pluginObj: HapiPluginObject<T>) => Hapi.Plugin<T, void>;
17
18
  //# sourceMappingURL=utils.d.ts.map
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getExtMetadata = exports.getRouteMetadata = exports.isPatchableExtMethod = exports.isDirectExtInput = exports.isLifecycleExtEventObj = exports.isLifecycleExtType = exports.getPluginName = void 0;
18
+ exports.getPluginFromInput = exports.getExtMetadata = exports.getRouteMetadata = exports.isPatchableExtMethod = exports.isDirectExtInput = exports.isLifecycleExtEventObj = exports.isLifecycleExtType = exports.getPluginName = void 0;
19
19
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
20
20
  const internal_types_1 = require("./internal-types");
21
21
  const AttributeNames_1 = require("./enums/AttributeNames");
@@ -92,4 +92,14 @@ const getExtMetadata = (extPoint, pluginName) => {
92
92
  };
93
93
  };
94
94
  exports.getExtMetadata = getExtMetadata;
95
+ const getPluginFromInput = (pluginObj) => {
96
+ if ('plugin' in pluginObj) {
97
+ if ('plugin' in pluginObj.plugin) {
98
+ return pluginObj.plugin.plugin;
99
+ }
100
+ return pluginObj.plugin;
101
+ }
102
+ return pluginObj;
103
+ };
104
+ exports.getPluginFromInput = getPluginFromInput;
95
105
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,8EAAyE;AAEzE,qDAK0B;AAC1B,2DAAwD;AAExD,SAAgB,aAAa,CAAI,MAAsB;IACrD,IAAK,MAAiC,CAAC,IAAI,EAAE;QAC3C,OAAQ,MAAiC,CAAC,IAAI,CAAC;KAChD;SAAM;QACL,OAAQ,MAA6B,CAAC,GAAG,CAAC,IAAI,CAAC;KAChD;AACH,CAAC;AAND,sCAMC;AAEM,MAAM,kBAAkB,GAAG,CAChC,eAAwB,EACsB,EAAE;IAChD,OAAO,CACL,OAAO,eAAe,KAAK,QAAQ;QACnC,yCAAwB,CAAC,GAAG,CAAC,eAAe,CAAC,CAC9C,CAAC;AACJ,CAAC,CAAC;A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AC,EAAE,KAAK,CAAC,IAAI;YAC3C,CAAC,yCAAkB,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM;YAC9C,CAAC,+BAAc,CAAC,SAAS,CAAC,EAAE,8BAAa,CAAC,MAAM;SACjD;QACD,IAAI,EAAE,WAAW,KAAK,CAAC,IAAI,EAAE;KAC9B,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,gBAAgB,oBA0B3B;AAEK,MAAM,cAAc,GAAG,CAC5B,QAAmC,EACnC,UAAmB,EAInB,EAAE;IACF,IAAI,UAAU,EAAE;QACd,OAAO;YACL,UAAU,EAAE;gBACV,CAAC,+BAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ;gBACnC,CAAC,+BAAc,CAAC,SAAS,CAAC,EAAE,8BAAa,CAAC,GAAG;gBAC7C,CAAC,+BAAc,CAAC,WAAW,CAAC,EAAE,UAAU;aACzC;YACD,IAAI,EAAE,GAAG,UAAU,WAAW,QAAQ,EAAE;SACzC,CAAC;KACH;IACD,OAAO;QACL,UAAU,EAAE;YACV,CAAC,+BAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ;YACnC,CAAC,+BAAc,CAAC,SAAS,CAAC,EAAE,8BAAa,CAAC,GAAG;SAC9C;QACD,IAAI,EAAE,SAAS,QAAQ,EAAE;KAC1B,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,cAAc,kBAwBzB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SpanAttributes } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type * as Hapi from '@hapi/hapi';\nimport {\n HapiLayerType,\n HapiLifecycleMethodNames,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport { AttributeNames } from './enums/AttributeNames';\n\nexport function getPluginName<T>(plugin: Hapi.Plugin<T>): string {\n if ((plugin as Hapi.PluginNameVersion).name) {\n return (plugin as Hapi.PluginNameVersion).name;\n } else {\n return (plugin as Hapi.PluginPackage).pkg.name;\n }\n}\n\nexport const isLifecycleExtType = (\n variableToCheck: unknown\n): variableToCheck is Hapi.ServerRequestExtType => {\n return (\n typeof variableToCheck === 'string' &&\n HapiLifecycleMethodNames.has(variableToCheck)\n );\n};\n\nexport const isLifecycleExtEventObj = (\n variableToCheck: unknown\n): variableToCheck is Hapi.ServerExtEventsRequestObject => {\n const event = (variableToCheck as Hapi.ServerExtEventsRequestObject)?.type;\n return event !== undefined && isLifecycleExtType(event);\n};\n\nexport const isDirectExtInput = (\n variableToCheck: unknown\n): variableToCheck is ServerExtDirectInput => {\n return (\n Array.isArray(variableToCheck) &&\n variableToCheck.length <= 3 &&\n isLifecycleExtType(variableToCheck[0]) &&\n typeof variableToCheck[1] === 'function'\n );\n};\n\nexport const isPatchableExtMethod = (\n variableToCheck: PatchableExtMethod | PatchableExtMethod[]\n): variableToCheck is PatchableExtMethod => {\n return !Array.isArray(variableToCheck);\n};\n\nexport const getRouteMetadata = (\n route: Hapi.ServerRoute,\n pluginName?: string\n): {\n attributes: SpanAttributes;\n name: string;\n} => {\n if (pluginName) {\n return {\n attributes: {\n [SemanticAttributes.HTTP_ROUTE]: route.path,\n [SemanticAttributes.HTTP_METHOD]: route.method,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.PLUGIN,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n },\n name: `${pluginName}: route - ${route.path}`,\n };\n }\n return {\n attributes: {\n [SemanticAttributes.HTTP_ROUTE]: route.path,\n [SemanticAttributes.HTTP_METHOD]: route.method,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.ROUTER,\n },\n name: `route - ${route.path}`,\n };\n};\n\nexport const getExtMetadata = (\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string\n): {\n attributes: SpanAttributes;\n name: string;\n} => {\n if (pluginName) {\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n },\n name: `${pluginName}: ext - ${extPoint}`,\n };\n }\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n },\n name: `ext - ${extPoint}`,\n };\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,8EAAyE;AAEzE,qDAM0B;AAC1B,2DAAwD;AAExD,SAAgB,aAAa,CAAI,MAAsB;IACrD,IAAK,MAAiC,CAAC,IAAI,EAAE;QAC3C,OAAQ,MAAiC,CAAC,IAAI,CAAC;KAChD;SAAM;QACL,OAAQ,MAA6B,CAAC,GAAG,CAAC,IAAI,CAAC;KAChD;AACH,CAAC;AAND,sCAMC;AAEM,MAAM,kBAAkB,GAAG,CAChC,eAAwB,EACsB,EAAE;IAChD,OAAO,CACL,OAAO,eAAe,KAAK,QAAQ;QACnC,yCAAwB,CAAC,GAAG,CAAC,eAAe,CAAC,CAC9C,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B;AAEK,MAAM,sBAAsB,GAAG,CACpC,eAAwB,EAC8B,EAAE;;IACxD,MAAM,KAAK,GAAG,MAAC,eAAqD,0CAAE,IAAI,CAAC;IAC3E,OAAO,KAAK,KAAK,SAAS,IAAI,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC;AAC1D,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC;AAEK,MAAM,gBAAgB,GAAG,CAC9B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,CAC5B,QAAmC,EACnC,UAAmB,EAInB,EAAE;IACF,IAAI,UAAU,EAAE;QACd,OAAO;YACL,UAAU,EAAE;gBACV,CAAC,+BAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ;gBACnC,CAAC,+BAAc,CAAC,SAAS,CAAC,EAAE,8BAAa,CAAC,GAAG;gBAC7C,CAAC,+BAAc,CAAC,WAAW,CAAC,EAAE,UAAU;aACzC;YACD,IAAI,EAAE,GAAG,UAAU,WAAW,QAAQ,EAAE;SACzC,CAAC;KACH;IACD,OAAO;QACL,UAAU,EAAE;YACV,CAAC,+BAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ;YACnC,CAAC,+BAAc,CAAC,SAAS,CAAC,EAAE,8BAAa,CAAC,GAAG;SAC9C;QACD,IAAI,EAAE,SAAS,QAAQ,EAAE;KAC1B,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,cAAc,kBAwBzB;AAEK,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EACR,EAAE;IACxB,IAAI,QAAQ,IAAI,SAAS,EAAE;QACzB,IAAI,QAAQ,IAAI,SAAS,CAAC,MAAM,EAAE;YAChC,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;SAChC;QACD,OAAO,SAAS,CAAC,MAAM,CAAC;KACzB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SpanAttributes } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type * as Hapi from '@hapi/hapi';\nimport {\n HapiLayerType,\n HapiLifecycleMethodNames,\n HapiPluginObject,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport { AttributeNames } from './enums/AttributeNames';\n\nexport function getPluginName<T>(plugin: Hapi.Plugin<T>): string {\n if ((plugin as Hapi.PluginNameVersion).name) {\n return (plugin as Hapi.PluginNameVersion).name;\n } else {\n return (plugin as Hapi.PluginPackage).pkg.name;\n }\n}\n\nexport const isLifecycleExtType = (\n variableToCheck: unknown\n): variableToCheck is Hapi.ServerRequestExtType => {\n return (\n typeof variableToCheck === 'string' &&\n HapiLifecycleMethodNames.has(variableToCheck)\n );\n};\n\nexport const isLifecycleExtEventObj = (\n variableToCheck: unknown\n): variableToCheck is Hapi.ServerExtEventsRequestObject => {\n const event = (variableToCheck as Hapi.ServerExtEventsRequestObject)?.type;\n return event !== undefined && isLifecycleExtType(event);\n};\n\nexport const isDirectExtInput = (\n variableToCheck: unknown\n): variableToCheck is ServerExtDirectInput => {\n return (\n Array.isArray(variableToCheck) &&\n variableToCheck.length <= 3 &&\n isLifecycleExtType(variableToCheck[0]) &&\n typeof variableToCheck[1] === 'function'\n );\n};\n\nexport const isPatchableExtMethod = (\n variableToCheck: PatchableExtMethod | PatchableExtMethod[]\n): variableToCheck is PatchableExtMethod => {\n return !Array.isArray(variableToCheck);\n};\n\nexport const getRouteMetadata = (\n route: Hapi.ServerRoute,\n pluginName?: string\n): {\n attributes: SpanAttributes;\n name: string;\n} => {\n if (pluginName) {\n return {\n attributes: {\n [SemanticAttributes.HTTP_ROUTE]: route.path,\n [SemanticAttributes.HTTP_METHOD]: route.method,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.PLUGIN,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n },\n name: `${pluginName}: route - ${route.path}`,\n };\n }\n return {\n attributes: {\n [SemanticAttributes.HTTP_ROUTE]: route.path,\n [SemanticAttributes.HTTP_METHOD]: route.method,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.ROUTER,\n },\n name: `route - ${route.path}`,\n };\n};\n\nexport const getExtMetadata = (\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string\n): {\n attributes: SpanAttributes;\n name: string;\n} => {\n if (pluginName) {\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n },\n name: `${pluginName}: ext - ${extPoint}`,\n };\n }\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n },\n name: `ext - ${extPoint}`,\n };\n};\n\nexport const getPluginFromInput = <T>(\n pluginObj: HapiPluginObject<T>\n): Hapi.Plugin<T, void> => {\n if ('plugin' in pluginObj) {\n if ('plugin' in pluginObj.plugin) {\n return pluginObj.plugin.plugin;\n }\n return pluginObj.plugin;\n }\n return pluginObj;\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.37.0";
1
+ export declare const VERSION = "0.38.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.37.0';
20
+ exports.VERSION = '0.38.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.37.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.38.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-hapi",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "OpenTelemetry Hapi automatic instrumentation package.",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -43,13 +43,14 @@
43
43
  "@opentelemetry/api": "^1.3.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@hapi/hapi": "20.1.5",
46
+ "@hapi/hapi": "21.3.3",
47
47
  "@opentelemetry/api": "^1.3.0",
48
48
  "@opentelemetry/context-async-hooks": "^1.8.0",
49
49
  "@opentelemetry/sdk-trace-base": "^1.8.0",
50
50
  "@opentelemetry/sdk-trace-node": "^1.8.0",
51
51
  "@types/mocha": "7.0.2",
52
52
  "@types/node": "18.6.5",
53
+ "joi": "17.12.2",
53
54
  "mocha": "7.2.0",
54
55
  "nyc": "15.1.0",
55
56
  "rimraf": "5.0.5",
@@ -60,9 +61,8 @@
60
61
  "dependencies": {
61
62
  "@opentelemetry/core": "^1.8.0",
62
63
  "@opentelemetry/instrumentation": "^0.51.0",
63
- "@opentelemetry/semantic-conventions": "^1.0.0",
64
- "@types/hapi__hapi": "20.0.13"
64
+ "@opentelemetry/semantic-conventions": "^1.0.0"
65
65
  },
66
66
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi#readme",
67
- "gitHead": "96a87b48934f0afcf1fe637eed6704f35bd8e973"
67
+ "gitHead": "a2e2b5a1aa2910b903829d215184c43d2107b9ac"
68
68
  }