Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/instrumentation-hapi

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-hapi - npm Package Compare versions

Comparing version 0.37.0 to 0.38.0

57

build/src/instrumentation.js

@@ -27,19 +27,12 @@ "use strict";

class HapiInstrumentation extends instrumentation_1.InstrumentationBase {
constructor(config) {
constructor(config = {}) {
super('@opentelemetry/instrumentation-hapi', version_1.VERSION, config);
}
init() {
return new instrumentation_1.InstrumentationNodeModuleDefinition(internal_types_1.HapiComponentName, ['>=17 <21'], (moduleExports) => {
return new instrumentation_1.InstrumentationNodeModuleDefinition(internal_types_1.HapiComponentName, ['>=17 <22'], (moduleExports) => {
if (!(0, instrumentation_1.isWrapped)(moduleExports.server)) {
this._wrap(moduleExports, 'server', this._getServerPatch.bind(this));
}
// Casting as any is necessary here due to an issue with the @types/hapi__hapi
// type definition for Hapi.Server. Hapi.Server (note the uppercase) can also function
// as a factory function, similarly to Hapi.server (lowercase), and so should
// also be supported and instrumented. This is an issue with the DefinitelyTyped repo.
// Function is defined at: https://github.com/hapijs/hapi/blob/main/lib/index.js#L9
if (!(0, instrumentation_1.isWrapped)(moduleExports.Server)) {
this._wrap(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
moduleExports, 'Server', this._getServerPatch.bind(this));
this._wrap(moduleExports, 'Server', this._getServerPatch.bind(this));
}

@@ -91,12 +84,12 @@ return moduleExports;

const instrumentation = this;
api.diag.debug('Patching Hapi.Server register function');
return function register(pluginInput, options) {
var _a, _b, _c, _d, _e, _f;
if (Array.isArray(pluginInput)) {
for (const pluginObj of pluginInput) {
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);
const plugin = (0, utils_1.getPluginFromInput)(pluginObj);
instrumentation._wrapRegisterHandler(plugin);
}
}
else {
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);
const plugin = (0, utils_1.getPluginFromInput)(pluginInput);
instrumentation._wrapRegisterHandler(plugin);
}

@@ -118,3 +111,2 @@ return original.apply(this, [pluginInput, options]);

const instrumentation = this;
api.diag.debug('Patching Hapi.Server ext function');
return function ext(...args) {

@@ -160,3 +152,2 @@ if (Array.isArray(args[0])) {

const instrumentation = this;
api.diag.debug('Patching Hapi.Server route function');
return function route(route) {

@@ -187,3 +178,2 @@ if (Array.isArray(route)) {

const newRegisterHandler = function (server, options) {
server.route;
self._wrap(server, 'route', original => {

@@ -262,3 +252,3 @@ return instrumentation._getServerRoutePatch.bind(instrumentation)(original, pluginName);

_wrapRouteHandler(route, pluginName) {
var _a, _b, _c;
var _a;
const instrumentation = this;

@@ -268,7 +258,6 @@ if (route[internal_types_1.handlerPatched] === true)

route[internal_types_1.handlerPatched] = true;
const oldHandler = (_b = (_a = route.options) === null || _a === void 0 ? void 0 : _a.handler) !== null && _b !== void 0 ? _b : route.handler;
if (typeof oldHandler === 'function') {
const newHandler = async function (...params) {
const wrapHandler = oldHandler => {
return async function (...params) {
if (api.trace.getSpan(api.context.active()) === undefined) {
return await oldHandler(...params);
return await oldHandler.call(this, ...params);
}

@@ -284,3 +273,3 @@ const rpcMetadata = (0, core_1.getRPCMetadata)(api.context.active());

try {
return await api.context.with(api.trace.setSpan(api.context.active(), span), () => oldHandler(...params));
return await api.context.with(api.trace.setSpan(api.context.active(), span), () => oldHandler.call(this, ...params));
}

@@ -299,9 +288,19 @@ catch (err) {

};
if ((_c = route.options) === null || _c === void 0 ? void 0 : _c.handler) {
route.options.handler = newHandler;
}
else {
route.handler = newHandler;
}
};
if (typeof route.handler === 'function') {
route.handler = wrapHandler(route.handler);
}
else if (typeof route.options === 'function') {
const oldOptions = route.options;
route.options = function (server) {
const options = oldOptions(server);
if (typeof options.handler === 'function') {
options.handler = wrapHandler(options.handler);
}
return options;
};
}
else if (typeof ((_a = route.options) === null || _a === void 0 ? void 0 : _a.handler) === 'function') {
route.options.handler = wrapHandler(route.options.handler);
}
return route;

@@ -308,0 +307,0 @@ }

@@ -1,2 +0,2 @@

import type * as Hapi from 'hapi__hapi';
import type * as Hapi from '@hapi/hapi';
export declare const HapiComponentName = "@hapi/hapi";

@@ -14,9 +14,4 @@ /**

[handlerPatched]?: boolean;
options?: {
handler?: Hapi.Lifecycle.Method;
};
};
export declare type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T> & {
plugin: Hapi.ServerRegisterPluginObject<T>;
};
export declare type HapiPluginObject<T> = Hapi.ServerRegisterPluginObject<T>;
export declare type HapiPluginInput<T> = HapiPluginObject<T> | Array<HapiPluginObject<T>>;

@@ -23,0 +18,0 @@ export declare type RegisterFunction<T> = (plugin: HapiPluginInput<T>, options?: Hapi.ServerRegisterOptions) => Promise<void>;

import { SpanAttributes } from '@opentelemetry/api';
import type * as Hapi from '@hapi/hapi';
import { PatchableExtMethod, ServerExtDirectInput } from './internal-types';
import { HapiPluginObject, PatchableExtMethod, ServerExtDirectInput } from './internal-types';
export declare function getPluginName<T>(plugin: Hapi.Plugin<T>): string;

@@ -17,2 +17,3 @@ export declare const isLifecycleExtType: (variableToCheck: unknown) => variableToCheck is Hapi.ServerRequestExtType;

};
export declare const getPluginFromInput: <T>(pluginObj: HapiPluginObject<T>) => Hapi.Plugin<T, void>;
//# sourceMappingURL=utils.d.ts.map

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getExtMetadata = exports.getRouteMetadata = exports.isPatchableExtMethod = exports.isDirectExtInput = exports.isLifecycleExtEventObj = exports.isLifecycleExtType = exports.getPluginName = void 0;
exports.getPluginFromInput = exports.getExtMetadata = exports.getRouteMetadata = exports.isPatchableExtMethod = exports.isDirectExtInput = exports.isLifecycleExtEventObj = exports.isLifecycleExtType = exports.getPluginName = void 0;
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");

@@ -96,2 +96,12 @@ const internal_types_1 = require("./internal-types");

exports.getExtMetadata = getExtMetadata;
const getPluginFromInput = (pluginObj) => {
if ('plugin' in pluginObj) {
if ('plugin' in pluginObj.plugin) {
return pluginObj.plugin.plugin;
}
return pluginObj.plugin;
}
return pluginObj;
};
exports.getPluginFromInput = getPluginFromInput;
//# sourceMappingURL=utils.js.map

@@ -1,2 +0,2 @@

export declare const VERSION = "0.37.0";
export declare const VERSION = "0.38.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.37.0';
exports.VERSION = '0.38.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/instrumentation-hapi",
"version": "0.37.0",
"version": "0.38.0",
"description": "OpenTelemetry Hapi automatic instrumentation package.",

@@ -46,3 +46,3 @@ "main": "build/src/index.js",

"devDependencies": {
"@hapi/hapi": "20.1.5",
"@hapi/hapi": "21.3.3",
"@opentelemetry/api": "^1.3.0",

@@ -54,2 +54,3 @@ "@opentelemetry/context-async-hooks": "^1.8.0",

"@types/node": "18.6.5",
"joi": "17.12.2",
"mocha": "7.2.0",

@@ -65,7 +66,6 @@ "nyc": "15.1.0",

"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@types/hapi__hapi": "20.0.13"
"@opentelemetry/semantic-conventions": "^1.0.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi#readme",
"gitHead": "96a87b48934f0afcf1fe637eed6704f35bd8e973"
"gitHead": "a2e2b5a1aa2910b903829d215184c43d2107b9ac"
}

@@ -24,3 +24,3 @@ # OpenTelemetry Hapi Instrumentation for Node.js

- `>=17.0.0 <21`
- `>=17.0.0 <22`

@@ -27,0 +27,0 @@ ## Usage

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc