@opentelemetry/instrumentation-hapi 0.48.0 → 0.50.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
@@ -11,9 +11,9 @@ Compatible with OpenTelemetry JS API and SDK `1.0+`.
11
11
 
12
12
  ## Status
13
13
 
14
- | Maturity | [Component Owner](../../../.github/component_owners.yml) | Compatibility |
14
+ | Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility |
15
15
  | ----------------------------------------------------- | -------------------------------------------------------- | --------------------- |
16
- | [Unmaintained](../../../CONTRIBUTING.md#unmaintained) | N/A | API 1.0+<br/>SDK 1.0+ |
16
+ | [Unmaintained](../../CONTRIBUTING.md#unmaintained) | N/A | API 1.0+<br/>SDK 1.0+ |
17
17
 
18
18
  ## Installation
19
19
 
@@ -60,7 +60,7 @@ hapiInstrumentation.setTracerProvider(provider);
60
60
 
61
61
  See [examples/hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/hapi) for a short example using Hapi
62
62
 
63
- <!--
63
+ <!--
64
64
  The dev dependency of `@hapi/podium@4.1.1` is required to force the compatible type declarations. See: https://github.com/hapijs/hapi/issues/4240
65
65
  -->
66
66
 
@@ -70,14 +70,24 @@ This package provides automatic tracing for hapi server routes and [request life
70
70
 
71
71
  ## Semantic Conventions
72
72
 
73
- This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
73
+ Prior to version `0.48.0`, this instrumentation created spans targeting an experimental semantic convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md).
74
74
 
75
- Attributes collected:
75
+ HTTP semantic conventions (semconv) were stabilized in v1.23.0, and a [migration process](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#http-semantic-convention-stability-migration) was defined. `instrumentation-hapi` versions 0.48.0 and later include support for migrating to stable HTTP semantic conventions, as described below. The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new HTTP semconv, after which a new minor version will use the *new* semconv by default and drop support for the old semconv. See the [HTTP semconv migration plan for OpenTelemetry JS instrumentations](https://github.com/open-telemetry/opentelemetry-js/issues/5646).
76
76
 
77
- | Attribute | Short Description |
78
- |---------------------|----------------------------------------------------|
79
- | `http.method` | HTTP method |
80
- | `http.route` | Route assigned to handler. Ex: `/users/:id` |
77
+ To select which semconv version(s) is emitted from this instrumentation, use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable.
78
+
79
+ - `http`: emit the new (stable) v1.23.0+ semantics
80
+ - `http/dup`: emit **both** the old v1.7.0 and the new (stable) v1.23.0+ semantics
81
+ - By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used.
82
+
83
+ ### Attributes collected
84
+
85
+ The following semconv attributes are collected on hapi route spans:
86
+
87
+ | v1.7.0 semconv | v1.23.0 semconv | Notes |
88
+ | -------------- | --------------------- | ----- |
89
+ | `http.method` | `http.request.method` | HTTP request method |
90
+ | `http.route` | `http.route` (same) | Route assigned to handler. Ex: `/users/:id` |
81
91
 
82
92
  ## Useful links
83
93
 
@@ -1,6 +1,7 @@
1
1
  import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
2
  /** Hapi instrumentation for OpenTelemetry */
3
3
  export declare class HapiInstrumentation extends InstrumentationBase {
4
+ private _semconvStability;
4
5
  constructor(config?: InstrumentationConfig);
5
6
  protected init(): InstrumentationNodeModuleDefinition;
6
7
  /**
@@ -25,8 +25,10 @@ const internal_types_1 = require("./internal-types");
25
25
  const utils_1 = require("./utils");
26
26
  /** Hapi instrumentation for OpenTelemetry */
27
27
  class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
28
+ _semconvStability;
28
29
  constructor(config = {}) {
29
30
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
31
+ this._semconvStability = (0, instrumentation_1.semconvStabilityFromStr)('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
30
32
  }
31
33
  init() {
32
34
  return new instrumentation_1.InstrumentationNodeModuleDefinition(internal_types_1.HapiComponentName, ['>=17.0.0 <22'], (module) => {
@@ -260,7 +262,7 @@ class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
260
262
  if (rpcMetadata?.type === core_1.RPCType.HTTP) {
261
263
  rpcMetadata.route = route.path;
262
264
  }
263
- const metadata = (0, utils_1.getRouteMetadata)(route, pluginName);
265
+ const metadata = (0, utils_1.getRouteMetadata)(route, instrumentation._semconvStability, pluginName);
264
266
  const span = instrumentation.tracer.startSpan(metadata.name, {
265
267
  attributes: metadata.attributes,
266
268
  });
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,8CAA8D;AAC9D,oEAKwC;AAGxC,kBAAkB;AAClB,uCAA0D;AAC1D,qDAU0B;AAC1B,mCASiB;AAEjB,6CAA6C;AAC7C,MAAa,mBAAoB,SAAQ,qCAAmB;IAC1D,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAES,IAAI;QACZ,OAAO,IAAI,qDAAmC,CAC5C,kCAAiB,EACjB,CAAC,cAAc,CAAC,EAChB,CAAC,MAAW,EAAE,EAAE;YACd,MAAM,aAAa,GACjB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YACpE,IAAI,CAAC,IAAA,2BAAS,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBACpC,IAAI,CAAC,KAAK,CACR,aAAa,EACb,QAAQ,EACR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AAC,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,KAAK,CAAC,OAAO,EAAE,OAAO,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;AA5XD,kDA4XC","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';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_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(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17.0.0 <22'],\n (module: any) => {\n const moduleExports: typeof Hapi =\n module[Symbol.toStringTag] === 'Module' ? module.default : module;\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 (module: any) => {\n const moduleExports: typeof Hapi =\n module[Symbol.toStringTag] === 'Module' ? module.default : module;\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 oldRegister = plugin.register;\n const self = this;\n const newRegisterHandler = function (\n this: typeof plugin,\n server: Hapi.Server,\n options: T\n ) {\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 oldRegister.call(this, 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
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,8CAA8D;AAC9D,oEAOwC;AAGxC,kBAAkB;AAClB,uCAA0D;AAC1D,qDAU0B;AAC1B,mCASiB;AAEjB,6CAA6C;AAC7C,MAAa,mBAAoB,SAAQ,qCAAmB;IAClD,iBAAiB,CAAmB;IAE5C,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,IAAA,yCAAuB,EAC9C,MAAM,EACN,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAC1C,CAAC;IACJ,CAAC;IAES,IAAI;QACZ,OAAO,IAAI,qDAAmC,CAC5C,kCAAiB,EACjB,CAAC,cAAc,CAAC,EAChB,CAAC,MAAW,EAAE,EAAE;YACd,MAAM,aAAa,GACjB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YACpE,IAAI,CAAC,IAAA,2BAAS,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBACpC,IAAI,CAAC,KAAK,CACR,aAAa,EACb,QAAQ,EACR,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAQ,CACvC,CAAC;aACH;YAED,IAAI,CAAC,IAAA,2BAAS,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBACpC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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,KAAK,CAAC,OAAO,EAAE,OAAO,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;AAtYD,kDAsYC","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 SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\n\nimport type * as Hapi from '@hapi/hapi';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_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 private _semconvStability: SemconvStability;\n\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n this._semconvStability = semconvStabilityFromStr(\n 'http',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17.0.0 <22'],\n (module: any) => {\n const moduleExports: typeof Hapi =\n module[Symbol.toStringTag] === 'Module' ? module.default : module;\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 (module: any) => {\n const moduleExports: typeof Hapi =\n module[Symbol.toStringTag] === 'Module' ? module.default : module;\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 oldRegister = plugin.register;\n const self = this;\n const newRegisterHandler = function (\n this: typeof plugin,\n server: Hapi.Server,\n options: T\n ) {\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 oldRegister.call(this, 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(\n route,\n instrumentation._semconvStability,\n pluginName\n );\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"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Deprecated, use `http.request.method` instead.
3
+ *
4
+ * @example GET
5
+ * @example POST
6
+ * @example HEAD
7
+ *
8
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
9
+ *
10
+ * @deprecated Replaced by `http.request.method`.
11
+ */
12
+ export declare const ATTR_HTTP_METHOD: "http.method";
13
+ //# sourceMappingURL=semconv.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ATTR_HTTP_METHOD = void 0;
19
+ /*
20
+ * This file contains a copy of unstable semantic convention definitions
21
+ * used by this package.
22
+ * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
23
+ */
24
+ /**
25
+ * Deprecated, use `http.request.method` instead.
26
+ *
27
+ * @example GET
28
+ * @example POST
29
+ * @example HEAD
30
+ *
31
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
32
+ *
33
+ * @deprecated Replaced by `http.request.method`.
34
+ */
35
+ exports.ATTR_HTTP_METHOD = 'http.method';
36
+ //# sourceMappingURL=semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAG,aAAsB,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/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use `http.request.method` instead.\n *\n * @example GET\n * @example POST\n * @example HEAD\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.request.method`.\n */\nexport const ATTR_HTTP_METHOD = 'http.method' as const;\n"]}
@@ -1,17 +1,18 @@
1
- import { SpanAttributes } from '@opentelemetry/api';
1
+ import { Attributes } from '@opentelemetry/api';
2
2
  import type * as Hapi from '@hapi/hapi';
3
3
  import { HapiPluginObject, PatchableExtMethod, ServerExtDirectInput } from './internal-types';
4
+ import { SemconvStability } from '@opentelemetry/instrumentation';
4
5
  export declare function getPluginName<T>(plugin: Hapi.Plugin<T>): string;
5
6
  export declare const isLifecycleExtType: (variableToCheck: unknown) => variableToCheck is Hapi.ServerRequestExtType;
6
7
  export declare const isLifecycleExtEventObj: (variableToCheck: unknown) => variableToCheck is Hapi.ServerExtEventsRequestObject;
7
8
  export declare const isDirectExtInput: (variableToCheck: unknown) => variableToCheck is ServerExtDirectInput;
8
9
  export declare const isPatchableExtMethod: (variableToCheck: PatchableExtMethod | PatchableExtMethod[]) => variableToCheck is PatchableExtMethod;
9
- export declare const getRouteMetadata: (route: Hapi.ServerRoute, pluginName?: string) => {
10
- attributes: SpanAttributes;
10
+ export declare const getRouteMetadata: (route: Hapi.ServerRoute, semconvStability: SemconvStability, pluginName?: string) => {
11
+ attributes: Attributes;
11
12
  name: string;
12
13
  };
13
14
  export declare const getExtMetadata: (extPoint: Hapi.ServerRequestExtType, pluginName?: string) => {
14
- attributes: SpanAttributes;
15
+ attributes: Attributes;
15
16
  name: string;
16
17
  };
17
18
  export declare const getPluginFromInput: <T>(pluginObj: HapiPluginObject<T>) => Hapi.Plugin<T, void>;
@@ -17,8 +17,10 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
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
+ const semconv_1 = require("./semconv");
20
21
  const internal_types_1 = require("./internal-types");
21
22
  const AttributeNames_1 = require("./enums/AttributeNames");
23
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
22
24
  function getPluginName(plugin) {
23
25
  if (plugin.name) {
24
26
  return plugin.name;
@@ -49,26 +51,32 @@ const isPatchableExtMethod = (variableToCheck) => {
49
51
  return !Array.isArray(variableToCheck);
50
52
  };
51
53
  exports.isPatchableExtMethod = isPatchableExtMethod;
52
- const getRouteMetadata = (route, pluginName) => {
54
+ const getRouteMetadata = (route, semconvStability, pluginName) => {
55
+ const attributes = {
56
+ [semantic_conventions_1.ATTR_HTTP_ROUTE]: route.path,
57
+ };
58
+ if (semconvStability & instrumentation_1.SemconvStability.OLD) {
59
+ attributes[semconv_1.ATTR_HTTP_METHOD] = route.method;
60
+ }
61
+ if (semconvStability & instrumentation_1.SemconvStability.STABLE) {
62
+ // Note: This currently does *not* normalize the method name to uppercase
63
+ // and conditionally include `http.request.method.original` as described
64
+ // at https://opentelemetry.io/docs/specs/semconv/http/http-spans/
65
+ // These attributes are for a *hapi* span, and not the parent HTTP span,
66
+ // so the HTTP span guidance doesn't strictly apply.
67
+ attributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD] = route.method;
68
+ }
69
+ let name;
53
70
  if (pluginName) {
54
- return {
55
- attributes: {
56
- [semantic_conventions_1.SEMATTRS_HTTP_ROUTE]: route.path,
57
- [semantic_conventions_1.SEMATTRS_HTTP_METHOD]: route.method,
58
- [AttributeNames_1.AttributeNames.HAPI_TYPE]: internal_types_1.HapiLayerType.PLUGIN,
59
- [AttributeNames_1.AttributeNames.PLUGIN_NAME]: pluginName,
60
- },
61
- name: `${pluginName}: route - ${route.path}`,
62
- };
71
+ attributes[AttributeNames_1.AttributeNames.HAPI_TYPE] = internal_types_1.HapiLayerType.PLUGIN;
72
+ attributes[AttributeNames_1.AttributeNames.PLUGIN_NAME] = pluginName;
73
+ name = `${pluginName}: route - ${route.path}`;
63
74
  }
64
- return {
65
- attributes: {
66
- [semantic_conventions_1.SEMATTRS_HTTP_ROUTE]: route.path,
67
- [semantic_conventions_1.SEMATTRS_HTTP_METHOD]: route.method,
68
- [AttributeNames_1.AttributeNames.HAPI_TYPE]: internal_types_1.HapiLayerType.ROUTER,
69
- },
70
- name: `route - ${route.path}`,
71
- };
75
+ else {
76
+ attributes[AttributeNames_1.AttributeNames.HAPI_TYPE] = internal_types_1.HapiLayerType.ROUTER;
77
+ name = `route - ${route.path}`;
78
+ }
79
+ return { attributes, name };
72
80
  };
73
81
  exports.getRouteMetadata = getRouteMetadata;
74
82
  const getExtMetadata = (extPoint, pluginName) => {
@@ -1 +1 @@
1
- {"version":3,"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AAQ,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 {\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_ROUTE,\n} 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 [SEMATTRS_HTTP_ROUTE]: route.path,\n [SEMATTRS_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 [SEMATTRS_HTTP_ROUTE]: route.path,\n [SEMATTRS_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
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,8EAG6C;AAC7C,uCAA6C;AAE7C,qDAM0B;AAC1B,2DAAwD;AACxD,oEAAkE;AAElE,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,GAAI,eAAqD,EAAE,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,eAAwB,EACiB,EAAE;IAC3C,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAC9B,eAAe,CAAC,MAAM,IAAI,CAAC;QAC3B,IAAA,0BAAkB,EAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACtC,OAAO,eAAe,CAAC,CAAC,CAAC,KAAK,UAAU,CACzC,CAAC;AACJ,CAAC,CAAC;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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 { Attributes } from '@opentelemetry/api';\nimport {\n ATTR_HTTP_ROUTE,\n ATTR_HTTP_REQUEST_METHOD,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_METHOD } from './semconv';\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';\nimport { SemconvStability } from '@opentelemetry/instrumentation';\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 semconvStability: SemconvStability,\n pluginName?: string\n): {\n attributes: Attributes;\n name: string;\n} => {\n const attributes: Attributes = {\n [ATTR_HTTP_ROUTE]: route.path,\n };\n if (semconvStability & SemconvStability.OLD) {\n attributes[ATTR_HTTP_METHOD] = route.method;\n }\n if (semconvStability & SemconvStability.STABLE) {\n // Note: This currently does *not* normalize the method name to uppercase\n // and conditionally include `http.request.method.original` as described\n // at https://opentelemetry.io/docs/specs/semconv/http/http-spans/\n // These attributes are for a *hapi* span, and not the parent HTTP span,\n // so the HTTP span guidance doesn't strictly apply.\n attributes[ATTR_HTTP_REQUEST_METHOD] = route.method;\n }\n\n let name;\n if (pluginName) {\n attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.PLUGIN;\n attributes[AttributeNames.PLUGIN_NAME] = pluginName;\n name = `${pluginName}: route - ${route.path}`;\n } else {\n attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.ROUTER;\n name = `route - ${route.path}`;\n }\n\n return { attributes, name };\n};\n\nexport const getExtMetadata = (\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string\n): {\n attributes: Attributes;\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,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.48.0";
1
+ export declare const PACKAGE_VERSION = "0.50.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-hapi";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.48.0';
20
+ exports.PACKAGE_VERSION = '0.50.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-hapi';
22
22
  //# 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,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,qCAAqC,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 PACKAGE_VERSION = '0.48.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-hapi';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,qCAAqC,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 PACKAGE_VERSION = '0.50.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-hapi';\n"]}
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-hapi",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "description": "OpenTelemetry instrumentation for `@hapi/hapi` http web application framework",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
7
- "repository": "open-telemetry/opentelemetry-js-contrib",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib.git",
10
+ "directory": "packages/instrumentation-hapi"
11
+ },
8
12
  "scripts": {
9
13
  "test": "nyc mocha 'test/**/*.test.ts'",
10
14
  "test-all-versions": "tav",
@@ -12,8 +16,8 @@
12
16
  "clean": "rimraf build/*",
13
17
  "lint": "eslint . --ext .ts",
14
18
  "lint:fix": "eslint . --ext .ts --fix",
15
- "lint:readme": "node ../../../scripts/lint-readme.js",
16
- "version:update": "node ../../../scripts/version-update.js",
19
+ "lint:readme": "node ../../scripts/lint-readme.js",
20
+ "version:update": "node ../../scripts/version-update.js",
17
21
  "setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-hapi",
18
22
  "compile": "tsc -p .",
19
23
  "prepublishOnly": "npm run compile"
@@ -46,7 +50,7 @@
46
50
  "@hapi/hapi": "21.3.12",
47
51
  "@opentelemetry/api": "^1.3.0",
48
52
  "@opentelemetry/context-async-hooks": "^2.0.0",
49
- "@opentelemetry/contrib-test-utils": "^0.48.0",
53
+ "@opentelemetry/contrib-test-utils": "^0.49.0",
50
54
  "@opentelemetry/sdk-trace-base": "^2.0.0",
51
55
  "@opentelemetry/sdk-trace-node": "^2.0.0",
52
56
  "@types/mocha": "10.0.10",
@@ -59,9 +63,9 @@
59
63
  },
60
64
  "dependencies": {
61
65
  "@opentelemetry/core": "^2.0.0",
62
- "@opentelemetry/instrumentation": "^0.202.0",
66
+ "@opentelemetry/instrumentation": "^0.203.0",
63
67
  "@opentelemetry/semantic-conventions": "^1.27.0"
64
68
  },
65
- "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi#readme",
66
- "gitHead": "7481f71d615acf161b5c86dd4abce1434a860a3d"
69
+ "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-hapi#readme",
70
+ "gitHead": "e7960a2061c0a039ffa57ed8dbb73d605d65f4f6"
67
71
  }