Skip to content

Commit 0fb7484

Browse files
committed
chore: typo
1 parent b2ac664 commit 0fb7484

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/middleware-http-debug-log/src/getMiddlewareTimerPlugin.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
* This plugin logs or records the timings of the middleware named in options.middlewareNames.
1313
*
1414
* @param options.middlewareNames - names of the middleware to measure.
15-
* @param options.storage - a container for the data. If non is provided, metrics will be logged to console.
15+
* @param options.storage - a container for the data. If none is provided, metrics will be logged to console.
1616
*
1717
* @beta
1818
*/
@@ -22,16 +22,16 @@ export function getMiddlewareTimerPlugin(
2222
storage?: Record<string, number[]>;
2323
} = {}
2424
) {
25+
const middlewareNames =
26+
options.middlewareNames ??
27+
(["serializerMiddleware", "deserializerMiddleware", "httpSigningMiddleware", "retryMiddleware"] as string[]);
28+
2529
return {
2630
applyToStack(middlewareStack: MiddlewareStack<any, any>) {
27-
const middlewareNames =
28-
options.middlewareNames ??
29-
(["serializerMiddleware", "deserializerMiddleware", "httpSigningMiddleware", "retryMiddleware"] as string[]);
3031
for (const mw of middlewareNames) {
3132
middlewareStack.addRelativeTo(
3233
(next: SerializeHandler<any, any>, context: HandlerExecutionContext) =>
3334
async (args: SerializeHandlerArguments<any>) => {
34-
context.middlewareTimings[mw] = context.middlewareTimings[mw] ?? ({} as Record<string, number>);
3535
context.middlewareTimings[mw].leaderPreNext = performance.now();
3636
const handlerOutput = await next(args);
3737
context.middlewareTimings[mw].leaderPostNext = performance.now();
@@ -48,11 +48,10 @@ export function getMiddlewareTimerPlugin(
4848
middlewareStack.addRelativeTo(
4949
(next: SerializeHandler<any, any>, context: HandlerExecutionContext) =>
5050
async (args: SerializeHandlerArguments<any>) => {
51-
context.middlewareTimings[mw] = context.middlewareTimings[mw] ?? ({} as Record<string, number>);
5251
context.middlewareTimings[mw].trailerPreNext = performance.now();
53-
const r = await next(args);
52+
const handlerOutput = await next(args);
5453
context.middlewareTimings[mw].trailerPostNext = performance.now();
55-
return r;
54+
return handlerOutput;
5655
},
5756
{
5857
name: mw + "-after",
@@ -67,6 +66,10 @@ export function getMiddlewareTimerPlugin(
6766
(next: InitializeHandler<any, any>, context: HandlerExecutionContext) =>
6867
async (args: InitializeHandlerArguments<any>) => {
6968
context.middlewareTimings = context.middlewareTimings ?? ({} as Record<string, Record<string, number>>);
69+
for (const mw of middlewareNames) {
70+
context.middlewareTimings[mw] = {} as Record<string, number>;
71+
}
72+
7073
const handlerOutput = await next(args);
7174

7275
for (const [mw, timings] of Object.entries(

0 commit comments

Comments
 (0)