Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow hapi plugin from array to be registered as argument #1253

Merged
merged 2 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class HapiInstrumentation extends InstrumentationBase {
if (Array.isArray(pluginInput)) {
for (const pluginObj of pluginInput) {
instrumentation._wrapRegisterHandler(
pluginObj.plugin?.plugin ?? pluginObj.plugin
pluginObj.plugin?.plugin ?? pluginObj.plugin ?? pluginObj
);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,64 @@ describe('Hapi Instrumentation - Hapi.Plugin Tests', () => {
);
});

it('should create spans for routes across multiple plugins declared in attribute level', async () => {
const rootSpan = tracer.startSpan('rootSpan');

await server.register([packagePlugin, simplePlugin]);
await server.start();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);

await context.with(
trace.setSpan(context.active(), rootSpan),
async () => {
const res1 = await server.inject({
method: 'GET',
url: '/package',
});
assert.strictEqual(res1.statusCode, 200);
const res2 = await server.inject({
method: 'GET',
url: '/hello',
});
assert.strictEqual(res2.statusCode, 200);

rootSpan.end();

assert.deepStrictEqual(memoryExporter.getFinishedSpans().length, 3);

const firstHandlerSpan = memoryExporter
.getFinishedSpans()
.find(span => span.name === 'plugin-by-package: route - /package');
assert.notStrictEqual(firstHandlerSpan, undefined);
assert.strictEqual(
firstHandlerSpan?.attributes[AttributeNames.HAPI_TYPE],
HapiLayerType.PLUGIN
);
assert.strictEqual(
firstHandlerSpan?.attributes[AttributeNames.PLUGIN_NAME],
'plugin-by-package'
);
const secondHandlerSpan = memoryExporter
.getFinishedSpans()
.find(span => span.name === 'simplePlugin: route - /hello');
assert.notStrictEqual(secondHandlerSpan, undefined);
assert.strictEqual(
secondHandlerSpan?.attributes[AttributeNames.HAPI_TYPE],
HapiLayerType.PLUGIN
);
assert.strictEqual(
secondHandlerSpan?.attributes[AttributeNames.PLUGIN_NAME],
'simplePlugin'
);

const exportedRootSpan = memoryExporter
.getFinishedSpans()
.find(span => span.name === 'rootSpan');
assert.notStrictEqual(exportedRootSpan, undefined);
}
);
});

it('should instrument multiple versions of the same plugin just once', async () => {
const rootSpan = tracer.startSpan('rootSpan');

Expand Down