From a2c6cae8592cc5a66340e3b80c23472e74e1c0c9 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Wed, 3 Mar 2021 21:23:19 +0100 Subject: [PATCH 1/3] chore: moving hapi plugin to instrumentation --- examples/hapi/package.json | 17 +-- examples/hapi/server.js | 8 +- examples/hapi/tracer.js | 30 ++--- .../README.md | 36 +++--- .../package.json | 16 ++- .../src/hapi.ts | 118 +++++++++--------- .../test/hapi-plugin.test.ts | 6 +- .../test/hapi-server-ext.test.ts | 7 +- .../test/hapi.test.ts | 7 +- .../test/plugin.ts | 26 ++++ 10 files changed, 155 insertions(+), 116 deletions(-) create mode 100644 plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts diff --git a/examples/hapi/package.json b/examples/hapi/package.json index 0d3dd97c25..f07743b585 100644 --- a/examples/hapi/package.json +++ b/examples/hapi/package.json @@ -32,14 +32,15 @@ }, "dependencies": { "@hapi/hapi": "^19.2.0", - "@opentelemetry/api": "^0.17.0", - "@opentelemetry/exporter-jaeger": "^0.17.0", - "@opentelemetry/exporter-zipkin": "^0.17.0", - "@opentelemetry/hapi-instrumentation": "^0.13.1", - "@opentelemetry/instrumentation": "^0.17.0", - "@opentelemetry/node": "^0.17.0", - "@opentelemetry/plugin-http": "^0.17.0", - "@opentelemetry/tracing": "^0.17.0", + "@opentelemetry/api": "^0.18.0", + "@opentelemetry/exporter-jaeger": "^0.18.0", + "@opentelemetry/exporter-zipkin": "^0.18.0", + "@opentelemetry/instrumentation": "^0.18.0", + "@opentelemetry/instrumentation-hapi": "^0.13.1", + "@opentelemetry/instrumentation-http": "^0.18.0", + "@opentelemetry/node": "^0.18.0", + "@opentelemetry/plugin-http": "^0.18.0", + "@opentelemetry/tracing": "^0.18.0", "axios": "^0.19.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme", diff --git a/examples/hapi/server.js b/examples/hapi/server.js index cee9885d07..e0e8f921b5 100644 --- a/examples/hapi/server.js +++ b/examples/hapi/server.js @@ -1,6 +1,8 @@ 'use strict'; -const tracer = require('./tracer')('example-hapi-server'); +const api = require('@opentelemetry/api'); +require('./tracer')('example-hapi-server'); + // eslint-disable-next-line const Hapi = require('@hapi/hapi'); @@ -62,7 +64,7 @@ const posts = ['post 0', 'post 1', 'post 2']; function addPost(_, h) { posts.push(`post ${posts.length}`); - const currentSpan = tracer.getCurrentSpan(); + const currentSpan = api.getSpan(api.context.active()); currentSpan.addEvent('Added post'); currentSpan.setAttribute('Date', new Date()); console.log(`Added post: ${posts[posts.length - 1]}`); @@ -80,7 +82,7 @@ async function showNewPost(request) { } function runTest(_, h) { - const currentSpan = tracer.getCurrentSpan(); + const currentSpan = api.getSpan(api.context.active()); const { traceId } = currentSpan.context(); console.log(`traceid: ${traceId}`); console.log(`Jaeger URL: http://localhost:16686/trace/${traceId}`); diff --git a/examples/hapi/tracer.js b/examples/hapi/tracer.js index 142ad5d595..5c03883290 100644 --- a/examples/hapi/tracer.js +++ b/examples/hapi/tracer.js @@ -1,27 +1,18 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/api'); +const api = require('@opentelemetry/api'); const { NodeTracerProvider } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi'); +const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider({ - plugins: { - '@hapi/hapi': { - enabled: true, - path: '@opentelemetry/hapi-instrumentation', - enhancedDatabaseReporting: true, - }, - http: { - enabled: true, - path: '@opentelemetry/plugin-http', - }, - }, - }); + const provider = new NodeTracerProvider(); let exporter; if (EXPORTER === 'jaeger') { @@ -34,5 +25,14 @@ module.exports = (serviceName) => { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); - return opentelemetry.trace.getTracer('hapi-example'); + registerInstrumentations({ + instrumentations: [ + new HapiInstrumentation({ + enhancedDatabaseReporting: true, + }), + new HttpInstrumentation(), + ], + }); + + return api.trace.getTracer('hapi-example'); }; diff --git a/plugins/node/opentelemetry-hapi-instrumentation/README.md b/plugins/node/opentelemetry-hapi-instrumentation/README.md index 98daf053d1..834b3cfe7e 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/README.md +++ b/plugins/node/opentelemetry-hapi-instrumentation/README.md @@ -25,38 +25,42 @@ To load a specific instrumentation (Hapi in this case), specify it in the regist ```js const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - const provider = new NodeTracerProvider(); provider.register(); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); registerInstrumentations({ - instrumentations: [ - { - plugins: { - '@hapi/hapi': { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/hapi-instrumentation', - } - }, - }, - ], tracerProvider: provider, }); ``` -To load all of the [supported instrumentations](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each instrumentation is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing instrumentations for unused modules. +If instead you would just want to load a specific instrumentation only (**hapi** in this case); + ```js const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi'); +const provider = new NodeTracerProvider(); +provider.register(); +const hapiInstrumentation = new HapiInstrumentation(); +hapiInstrumentation.setTracerProvider(provider); +``` + +You can combine loading default plugins and HapiInstrumentation at the same time: + +```js +const { NodeTracerProvider } = require('@opentelemetry/node'); +const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); provider.register(); + registerInstrumentations({ + instrumentations: [ + new HapiInstrumentation(), + ], tracerProvider: provider, }); - ``` See [examples/hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/hapi) for a short example using Hapi diff --git a/plugins/node/opentelemetry-hapi-instrumentation/package.json b/plugins/node/opentelemetry-hapi-instrumentation/package.json index d49c9c01cc..8f7f61aff5 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/package.json +++ b/plugins/node/opentelemetry-hapi-instrumentation/package.json @@ -1,5 +1,5 @@ { - "name": "@opentelemetry/hapi-instrumentation", + "name": "@opentelemetry/instrumentation-hapi", "version": "0.13.1", "description": "OpenTelemetry Hapi automatic instrumentation package.", "main": "build/src/index.js", @@ -42,13 +42,12 @@ }, "devDependencies": { "@hapi/hapi": "20.0.1", - "@opentelemetry/context-async-hooks": "0.17.0", - "@opentelemetry/node": "0.17.0", - "@opentelemetry/tracing": "0.17.0", + "@opentelemetry/context-async-hooks": "0.18.0", + "@opentelemetry/node": "0.18.0", + "@opentelemetry/tracing": "0.18.0", "@types/hapi__hapi": "20.0.1", "@types/mocha": "7.0.2", "@types/node": "12.12.47", - "@types/shimmer": "1.0.1", "codecov": "3.7.0", "gts": "3.1.0", "mocha": "7.2.0", @@ -62,9 +61,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.17.0", - "@opentelemetry/core": "^0.17.0", - "@opentelemetry/semantic-conventions": "^0.17.0", - "shimmer": "^1.2.1" + "@opentelemetry/api": "^0.18.0", + "@opentelemetry/instrumentation": "^0.18.0", + "@opentelemetry/semantic-conventions": "^0.18.0" } } diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts b/plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts index dd59230aed..40c4209f21 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts +++ b/plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts @@ -14,8 +14,14 @@ * limitations under the License. */ -import { context, diag, getSpan, setSpan } from '@opentelemetry/api'; -import { BasePlugin } from '@opentelemetry/core'; +import * as api from '@opentelemetry/api'; +import { + InstrumentationBase, + InstrumentationConfig, + InstrumentationNodeModuleDefinition, + isWrapped, +} from '@opentelemetry/instrumentation'; + import type * as Hapi from '@hapi/hapi'; import { VERSION } from './version'; import { @@ -29,7 +35,6 @@ import { PatchableExtMethod, ServerExtDirectInput, } from './types'; -import * as shimmer from 'shimmer'; import { getRouteMetadata, getPluginName, @@ -41,51 +46,46 @@ import { } from './utils'; /** Hapi instrumentation for OpenTelemetry */ -export class HapiInstrumentation extends BasePlugin { - static readonly component = HapiComponentName; - - constructor(readonly moduleName: string) { - super('@opentelemetry/hapi-instrumentation', VERSION); +export class HapiInstrumentation extends InstrumentationBase { + constructor(config?: InstrumentationConfig) { + super('@opentelemetry/instrumentation-hapi', VERSION, config); } - /** - * Patches Hapi operations by wrapping the Hapi.server and Hapi.Server functions - */ - protected patch(): typeof Hapi { - diag.debug('Patching Hapi'); - if (this._moduleExports == null) { - return this._moduleExports; - } - - diag.debug('Patching Hapi.server'); - shimmer.wrap( - this._moduleExports, - 'server', - this._getServerPatch.bind(this) - ); + protected init() { + return new InstrumentationNodeModuleDefinition( + HapiComponentName, + ['>=17.0.0'], + moduleExports => { + if (!isWrapped(moduleExports.server)) { + api.diag.debug('Patching Hapi.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 - diag.debug('Patching Hapi.Server'); - shimmer.wrap( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this._moduleExports as any, - '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 (!isWrapped(moduleExports.Server)) { + api.diag.debug('Patching Hapi.Server'); + this._wrap( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + moduleExports as any, + 'Server', + this._getServerPatch.bind(this) + ); + } + return moduleExports; + }, + moduleExports => { + api.diag.debug('Unpatching Hapi'); + this._massUnwrap([moduleExports], ['server', 'Server']); + } ); - - return this._moduleExports; - } - - /** - * Unpatches all Hapi operations - */ - protected unpatch(): void { - diag.debug('Unpatching Hapi'); - shimmer.massUnwrap([this._moduleExports], ['server', 'Server']); } /** @@ -99,10 +99,11 @@ export class HapiInstrumentation extends BasePlugin { original: (options?: Hapi.ServerOptions) => Hapi.Server ) { const instrumentation: HapiInstrumentation = this; + const self = this; return function server(this: Hapi.Server, opts?: Hapi.ServerOptions) { const newServer: Hapi.Server = original.apply(this, [opts]); - shimmer.wrap(newServer, 'route', originalRouter => { + self._wrap(newServer, 'route', originalRouter => { return instrumentation._getServerRoutePatch.bind(instrumentation)( originalRouter ); @@ -111,7 +112,7 @@ export class HapiInstrumentation extends BasePlugin { // Casting as any is necessary here due to multiple overloads on the Hapi.ext // function, which requires supporting a variety of different parameters // as extension inputs - shimmer.wrap(newServer, 'ext', originalExtHandler => { + self._wrap(newServer, 'ext', originalExtHandler => { return instrumentation._getServerExtPatch.bind(instrumentation)( // eslint-disable-next-line @typescript-eslint/no-explicit-any originalExtHandler as any @@ -120,7 +121,7 @@ export class HapiInstrumentation extends BasePlugin { // Casting as any is necessary here due to multiple overloads on the Hapi.Server.register // function, which requires supporting a variety of different types of Plugin inputs - shimmer.wrap( + self._wrap( newServer, 'register', // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -141,7 +142,7 @@ export class HapiInstrumentation extends BasePlugin { original: RegisterFunction ): RegisterFunction { const instrumentation: HapiInstrumentation = this; - diag.debug('Patching Hapi.Server register function'); + api.diag.debug('Patching Hapi.Server register function'); return function register( this: Hapi.Server, pluginInput: HapiPluginInput, @@ -177,7 +178,7 @@ export class HapiInstrumentation extends BasePlugin { pluginName?: string ) { const instrumentation: HapiInstrumentation = this; - diag.debug('Patching Hapi.Server ext function'); + api.diag.debug('Patching Hapi.Server ext function'); return function ext( this: ThisParameterType, @@ -238,7 +239,7 @@ export class HapiInstrumentation extends BasePlugin { pluginName?: string ) { const instrumentation: HapiInstrumentation = this; - diag.debug('Patching Hapi.Server route function'); + api.diag.debug('Patching Hapi.Server route function'); return function route( this: Hapi.Server, route: HapiServerRouteInput @@ -273,8 +274,9 @@ export class HapiInstrumentation extends BasePlugin { const instrumentation: HapiInstrumentation = this; const pluginName = getPluginName(plugin); const oldHandler = plugin.register; + const self = this; const newRegisterHandler = function (server: Hapi.Server, options: T) { - shimmer.wrap(server, 'route', original => { + self._wrap(server, 'route', original => { return instrumentation._getServerRoutePatch.bind(instrumentation)( original, pluginName @@ -284,7 +286,7 @@ export class HapiInstrumentation extends BasePlugin { // Casting as any is necessary here due to multiple overloads on the Hapi.ext // function, which requires supporting a variety of different parameters // as extension inputs - shimmer.wrap(server, 'ext', originalExtHandler => { + self._wrap(server, 'ext', originalExtHandler => { return instrumentation._getServerExtPatch.bind(instrumentation)( // eslint-disable-next-line @typescript-eslint/no-explicit-any originalExtHandler as any, @@ -329,15 +331,15 @@ export class HapiInstrumentation extends BasePlugin { const newHandler: PatchableExtMethod = async function ( ...params: Parameters ) { - if (getSpan(context.active()) === undefined) { + if (api.getSpan(api.context.active()) === undefined) { return await method(...params); } const metadata = getExtMetadata(extPoint, pluginName); - const span = instrumentation._tracer.startSpan(metadata.name, { + const span = instrumentation.tracer.startSpan(metadata.name, { attributes: metadata.attributes, }); let res; - await context.with(setSpan(context.active(), span), async () => { + await api.context.with(api.setSpan(api.context.active(), span), async () => { res = await method(...params); }); span.end(); @@ -369,11 +371,11 @@ export class HapiInstrumentation extends BasePlugin { h: Hapi.ResponseToolkit, err?: Error ) { - if (getSpan(context.active()) === undefined) { + if (api.getSpan(api.context.active()) === undefined) { return await oldHandler(request, h, err); } const metadata = getRouteMetadata(route, pluginName); - const span = instrumentation._tracer.startSpan(metadata.name, { + const span = instrumentation.tracer.startSpan(metadata.name, { attributes: metadata.attributes, }); const res = await oldHandler(request, h, err); @@ -390,5 +392,3 @@ export class HapiInstrumentation extends BasePlugin { return route; } } - -export const plugin = new HapiInstrumentation(HapiComponentName); diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts index ba2ad5bc4e..f4e51c225a 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts +++ b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts @@ -22,8 +22,9 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import * as assert from 'assert'; +import { getPlugin } from './plugin'; +const plugin = getPlugin(); import * as hapi from '@hapi/hapi'; -import { plugin } from '../src'; import { AttributeNames, HapiLayerType } from '../src/types'; describe('Hapi Instrumentation - Hapi.Plugin Tests', () => { @@ -36,7 +37,8 @@ describe('Hapi Instrumentation - Hapi.Plugin Tests', () => { let server: hapi.Server; before(() => { - plugin.enable(hapi, provider); + plugin.enable(); + plugin.setTracerProvider(provider); }); beforeEach(async () => { diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts index 6a11935102..1e7b61ec50 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts +++ b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts @@ -22,8 +22,10 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import * as assert from 'assert'; +import { getPlugin } from './plugin'; +const plugin = getPlugin(); + import * as hapi from '@hapi/hapi'; -import { plugin } from '../src'; import { AttributeNames, HapiLayerType } from '../src/types'; describe('Hapi Instrumentation - Server.Ext Tests', () => { @@ -36,7 +38,8 @@ describe('Hapi Instrumentation - Server.Ext Tests', () => { let server: hapi.Server; before(() => { - plugin.enable(hapi, provider); + plugin.enable(); + plugin.setTracerProvider(provider); }); beforeEach(async () => { diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts index 3e8c200d7d..5d71d67152 100644 --- a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts +++ b/plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts @@ -21,9 +21,11 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; +import { getPlugin } from './plugin'; +const plugin = getPlugin(); + import * as assert from 'assert'; import * as hapi from '@hapi/hapi'; -import { plugin } from '../src'; import { AttributeNames, HapiLayerType } from '../src/types'; describe('Hapi Instrumentation - Core Tests', () => { @@ -36,7 +38,8 @@ describe('Hapi Instrumentation - Core Tests', () => { let server: hapi.Server; before(() => { - plugin.enable(hapi, provider); + plugin.enable(); + plugin.setTracerProvider(provider); }); beforeEach(async () => { diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts b/plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts new file mode 100644 index 0000000000..86fa26911e --- /dev/null +++ b/plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { HapiInstrumentation } from '../src'; + +let plugin: HapiInstrumentation; +export function getPlugin() { + if (!plugin) { + plugin = new HapiInstrumentation(); + } + return plugin; +} + From c8510ae7ae8f6d1a72abe92a5298c1f00313b60f Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Wed, 3 Mar 2021 21:47:43 +0100 Subject: [PATCH 2/3] chore: moving hapi plugin to instrumentation --- .../.eslintignore | 0 .../.eslintrc.js | 0 .../.mocharc.js | 0 .../.npmignore | 0 .../LICENSE | 0 .../README.md | 0 .../package.json | 0 .../src/hapi.ts | 0 .../src/index.ts | 0 .../src/types.ts | 0 .../src/utils.ts | 0 .../src/version.ts | 0 .../test/hapi-plugin.test.ts | 0 .../test/hapi-server-ext.test.ts | 0 .../test/hapi.test.ts | 0 .../test/plugin.ts | 0 .../test/testPackage.json | 0 .../tsconfig.json | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/.eslintignore (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/.eslintrc.js (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/.mocharc.js (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/.npmignore (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/LICENSE (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/README.md (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/package.json (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/src/hapi.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/src/index.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/src/types.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/src/utils.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/src/version.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/test/hapi-plugin.test.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/test/hapi-server-ext.test.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/test/hapi.test.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/test/plugin.ts (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/test/testPackage.json (100%) rename plugins/node/{opentelemetry-hapi-instrumentation => opentelemetry-instrumentation-hapi}/tsconfig.json (100%) diff --git a/plugins/node/opentelemetry-hapi-instrumentation/.eslintignore b/plugins/node/opentelemetry-instrumentation-hapi/.eslintignore similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/.eslintignore rename to plugins/node/opentelemetry-instrumentation-hapi/.eslintignore diff --git a/plugins/node/opentelemetry-hapi-instrumentation/.eslintrc.js b/plugins/node/opentelemetry-instrumentation-hapi/.eslintrc.js similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/.eslintrc.js rename to plugins/node/opentelemetry-instrumentation-hapi/.eslintrc.js diff --git a/plugins/node/opentelemetry-hapi-instrumentation/.mocharc.js b/plugins/node/opentelemetry-instrumentation-hapi/.mocharc.js similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/.mocharc.js rename to plugins/node/opentelemetry-instrumentation-hapi/.mocharc.js diff --git a/plugins/node/opentelemetry-hapi-instrumentation/.npmignore b/plugins/node/opentelemetry-instrumentation-hapi/.npmignore similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/.npmignore rename to plugins/node/opentelemetry-instrumentation-hapi/.npmignore diff --git a/plugins/node/opentelemetry-hapi-instrumentation/LICENSE b/plugins/node/opentelemetry-instrumentation-hapi/LICENSE similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/LICENSE rename to plugins/node/opentelemetry-instrumentation-hapi/LICENSE diff --git a/plugins/node/opentelemetry-hapi-instrumentation/README.md b/plugins/node/opentelemetry-instrumentation-hapi/README.md similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/README.md rename to plugins/node/opentelemetry-instrumentation-hapi/README.md diff --git a/plugins/node/opentelemetry-hapi-instrumentation/package.json b/plugins/node/opentelemetry-instrumentation-hapi/package.json similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/package.json rename to plugins/node/opentelemetry-instrumentation-hapi/package.json diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/src/hapi.ts rename to plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/index.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/index.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/src/index.ts rename to plugins/node/opentelemetry-instrumentation-hapi/src/index.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/types.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/types.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/src/types.ts rename to plugins/node/opentelemetry-instrumentation-hapi/src/types.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/utils.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/src/utils.ts rename to plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/src/version.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/version.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/src/version.ts rename to plugins/node/opentelemetry-instrumentation-hapi/src/version.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/test/hapi-plugin.test.ts rename to plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/test/hapi-server-ext.test.ts rename to plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/test/hapi.test.ts rename to plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/test/plugin.ts rename to plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts diff --git a/plugins/node/opentelemetry-hapi-instrumentation/test/testPackage.json b/plugins/node/opentelemetry-instrumentation-hapi/test/testPackage.json similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/test/testPackage.json rename to plugins/node/opentelemetry-instrumentation-hapi/test/testPackage.json diff --git a/plugins/node/opentelemetry-hapi-instrumentation/tsconfig.json b/plugins/node/opentelemetry-instrumentation-hapi/tsconfig.json similarity index 100% rename from plugins/node/opentelemetry-hapi-instrumentation/tsconfig.json rename to plugins/node/opentelemetry-instrumentation-hapi/tsconfig.json From 9ea1745642592763ececb55b76d1b4b99509a504 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 4 Mar 2021 20:01:07 +0100 Subject: [PATCH 3/3] chore: reviews and linting --- examples/hapi/package.json | 1 - .../opentelemetry-instrumentation-hapi/README.md | 2 +- .../src/hapi.ts | 15 +++++++-------- .../test/plugin.ts | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/hapi/package.json b/examples/hapi/package.json index f07743b585..f8873cda01 100644 --- a/examples/hapi/package.json +++ b/examples/hapi/package.json @@ -39,7 +39,6 @@ "@opentelemetry/instrumentation-hapi": "^0.13.1", "@opentelemetry/instrumentation-http": "^0.18.0", "@opentelemetry/node": "^0.18.0", - "@opentelemetry/plugin-http": "^0.18.0", "@opentelemetry/tracing": "^0.18.0", "axios": "^0.19.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-hapi/README.md b/plugins/node/opentelemetry-instrumentation-hapi/README.md index 834b3cfe7e..3479398e54 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/README.md +++ b/plugins/node/opentelemetry-instrumentation-hapi/README.md @@ -12,7 +12,7 @@ For automatic instrumentation see the ## Installation ```bash -npm install --save @opentelemetry/hapi-instrumentation +npm install --save @opentelemetry/instrumentation-hapi ``` ### Supported Versions - @hapi/hapi `^17.0.0` diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts index 40c4209f21..9035c68c6a 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/hapi.ts @@ -58,11 +58,7 @@ export class HapiInstrumentation extends InstrumentationBase { moduleExports => { if (!isWrapped(moduleExports.server)) { api.diag.debug('Patching Hapi.server'); - this._wrap( - moduleExports, - 'server', - this._getServerPatch.bind(this) - ); + this._wrap(moduleExports, 'server', this._getServerPatch.bind(this)); } // Casting as any is necessary here due to an issue with the @types/hapi__hapi @@ -339,9 +335,12 @@ export class HapiInstrumentation extends InstrumentationBase { attributes: metadata.attributes, }); let res; - await api.context.with(api.setSpan(api.context.active(), span), async () => { - res = await method(...params); - }); + await api.context.with( + api.setSpan(api.context.active(), span), + async () => { + res = await method(...params); + } + ); span.end(); return res; }; diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts index 86fa26911e..e835296103 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/plugin.ts @@ -23,4 +23,3 @@ export function getPlugin() { } return plugin; } -