Skip to content

Commit

Permalink
fix: getMetaData 取值
Browse files Browse the repository at this point in the history
  • Loading branch information
linyyyang committed Feb 26, 2023
1 parent a5535be commit 4b87999
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/handler/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-19 00:23:06
* @LastEditTime: 2023-02-20 18:33:35
* @LastEditTime: 2023-02-26 13:07:58
*/
import * as Helper from "koatty_lib";
import { KoattyContext } from "koatty_core";
Expand Down Expand Up @@ -34,8 +34,8 @@ export async function grpcHandler(ctx: KoattyContext, next: Function, ext?: any)
// event callback
const finish = () => {
const now = Date.now();
const originalPath = ctx.getMetaData("originalPath");
const startTime = ctx.getMetaData("startTime");
const originalPath = ctx.getMetaData("originalPath")[0];
const startTime = ctx.getMetaData("startTime")[0];
const status = StatusCodeConvert(ctx.status);
const msg = `{"action":"${ctx.protocol}","code":"${status}","startTime":"${startTime}","duration":"${(now - Helper.toInt(startTime)) || 0}","requestId":"${ext.requestId}","endTime":"${now}","path":"${originalPath}"}`;
Logger[(status > 0 ? 'Error' : 'Info')](msg);
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: richen
* @Date: 2020-11-20 17:37:32
* @LastEditors: Please set LastEditors
* @LastEditTime: 2023-02-21 15:58:50
* @LastEditTime: 2023-02-26 13:07:10
* @License: BSD (3-Clause)
* @Copyright (c) - <richenlin(at)gmail.com>
*/
Expand Down Expand Up @@ -105,8 +105,8 @@ export function Trace(options: TraceOptions, app: Koatty): Koa.Middleware {
let requestId = '';
if (openTrace) {
if (ctx.protocol === "grpc") {
const request: any = ctx.getMetaData("_body") || {};
requestId = `${ctx.getMetaData(requestIdName)}` || <string>request[requestIdName];
const request: any = ctx.getMetaData("_body")[0] || {};
requestId = `${ctx.getMetaData(requestIdName)[0]}` || <string>request[requestIdName];
} else {
requestId = <string>ctx.headers[requestIdName] || <string>ctx.query[requestIdName];
}
Expand Down

0 comments on commit 4b87999

Please sign in to comment.