From 724f159cf5f1a7d8e9862ff6991002f7003cb350 Mon Sep 17 00:00:00 2001 From: Mario Du Date: Wed, 12 Dec 2018 18:11:42 +0800 Subject: [PATCH] feat: support custom http trace name --- packages/hook/src/patch/HttpServer.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/hook/src/patch/HttpServer.ts b/packages/hook/src/patch/HttpServer.ts index 934a5294..e53634f3 100644 --- a/packages/hook/src/patch/HttpServer.ts +++ b/packages/hook/src/patch/HttpServer.ts @@ -5,6 +5,7 @@ import { parse as parseUrl } from 'url'; import { parse as parseQS, ParsedUrlQuery } from 'querystring'; import * as http from 'http'; import { IncomingMessage } from 'http'; +import * as is from 'is-type-of'; const debug = require('debug')('Pandora:Hook:HttpServerPatcher'); @@ -35,7 +36,8 @@ export class HttpServerPatcher extends Patcher { recordPostData?: boolean, bufferTransformer?: bufferTransformer, requestFilter?: requestFilter, - recordUrl?: boolean + recordUrl?: boolean, + traceName?: (span) => string }) { super(options || {}); @@ -204,7 +206,12 @@ export class HttpServerPatcher extends Patcher { }); } - tracer.named(`HTTP-${tags[ 'http.method' ].value}:${tags[ 'http.url' ].value}`); + if (options.traceName && is.isFunction(options.traceName)) { + tracer.named(`HTTP-${options.traceName(span)}`); + } else { + tracer.named(`HTTP-${tags[ 'http.method' ].value}:${tags[ 'http.url' ].value}`); + } + tracer.setCurrentSpan(span); function onFinishedFactory(eventName) {