Skip to content

Commit

Permalink
Merge branch 'main' into chore/tav-version-cut
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 authored Jun 21, 2022
2 parents 41ce7ca + a8c5c9f commit 85288c3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class HapiInstrumentation extends InstrumentationBase {
}
} else {
instrumentation._wrapRegisterHandler(
pluginInput.plugin?.plugin ?? pluginInput.plugin
pluginInput.plugin?.plugin ?? pluginInput.plugin ?? pluginInput
);
}
return original.apply(this, [pluginInput, options]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,49 @@ describe('Hapi Instrumentation - Hapi.Plugin Tests', () => {
);
});
});

describe('when plugin is declared in attribute level', () => {
it('should instrument package-based plugins', async () => {
const rootSpan = tracer.startSpan('rootSpan');
// Suppress this ts error due the Hapi plugin type definition is incomplete. server.register can accept nested plugin. See reference https://hapi.dev/api/?v=20.0.0#-routeoptionshandler
await server.register(packagePlugin);
await server.start();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);

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

rootSpan.end();
assert.deepStrictEqual(memoryExporter.getFinishedSpans().length, 2);

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

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

0 comments on commit 85288c3

Please sign in to comment.