perf(http): add route to span name

This commit is contained in:
TomyJan 2024-08-08 15:05:52 +08:00
parent f96a636780
commit 2a0cf298f4
3 changed files with 9 additions and 4 deletions

View File

@ -1,12 +1,12 @@
{ {
"name": "@tachybase/opentelemetry-instrumentation-http", "name": "@tachybase/opentelemetry-instrumentation-http",
"version": "0.1.0", "version": "0.1.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@tachybase/opentelemetry-instrumentation-http", "name": "@tachybase/opentelemetry-instrumentation-http",
"version": "0.1.0", "version": "0.1.1",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@opentelemetry/core": "1.25.1", "@opentelemetry/core": "1.25.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@tachybase/opentelemetry-instrumentation-http", "name": "@tachybase/opentelemetry-instrumentation-http",
"version": "0.1.0", "version": "0.1.1",
"description": "OpenTelemetry instrumentation for `node:http` and `node:https` http client and server modules for TachyBase", "description": "OpenTelemetry instrumentation for `node:http` and `node:https` http client and server modules for TachyBase",
"author": "TachyBase Team", "author": "TachyBase Team",
"homepage": "https://git.daoyoucloud.com/TomyJan/opentelemetry-auto-instrumentations/plugins/node/opentelemetry-instrumentation-http", "homepage": "https://git.daoyoucloud.com/TomyJan/opentelemetry-auto-instrumentations/plugins/node/opentelemetry-instrumentation-http",

View File

@ -774,7 +774,12 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
* propagate context without recording it. * propagate context without recording it.
*/ */
// 修改 name 加上具体的 route // 修改 name 加上具体的 route
name = `${name} ${options.attributes?.[SEMATTRS_HTTP_ROUTE] ?? ''}`; name = `${name} ${options.attributes?.[SEMATTRS_HTTP_ROUTE] ?? options.attributes?.['http.target'] ?? ''}`;
// 删除 url 中的 query
const queryIndex = name.indexOf('?');
if (queryIndex !== -1) {
name = name.slice(0, queryIndex);
}
const requireParent = const requireParent =
options.kind === SpanKind.CLIENT options.kind === SpanKind.CLIENT
? this.getConfig().requireParentforOutgoingSpans ? this.getConfig().requireParentforOutgoingSpans