From 62e228293a2a28cae42cb9e24cb0ef5c2300a224 Mon Sep 17 00:00:00 2001 From: Makito Date: Mon, 23 Dec 2024 18:01:29 +0800 Subject: [PATCH 1/8] fix(tracing): overall and per-span latency display --- packages/core/tracing/sandbox/App.vue | 5 ++ .../sandbox/fixtures/trace-batches.json | 2 +- .../trace-viewer/SpanAttributeTable.vue | 15 +++- .../trace-viewer/SpanLatencyTable.vue | 68 +++++++++++++++++++ .../components/trace-viewer/TraceLatency.vue | 45 ++++++++++++ .../components/trace-viewer/TraceViewer.vue | 13 ++-- .../components/waterfall/WaterfallLegend.vue | 55 --------------- .../components/waterfall/WaterfallSpanBar.vue | 27 +------- .../core/tracing/src/composables/useI18n.ts | 2 + packages/core/tracing/src/constants/spans.ts | 9 +++ .../core/tracing/src/constants/waterfall.ts | 30 -------- packages/core/tracing/src/locales/en.json | 21 +++--- packages/core/tracing/src/types/spans.ts | 7 ++ packages/core/tracing/src/utils/spans.ts | 29 +++++++- packages/core/tracing/src/utils/time.ts | 15 ++++ 15 files changed, 214 insertions(+), 129 deletions(-) create mode 100644 packages/core/tracing/src/components/trace-viewer/SpanLatencyTable.vue create mode 100644 packages/core/tracing/src/components/trace-viewer/TraceLatency.vue delete mode 100644 packages/core/tracing/src/components/waterfall/WaterfallLegend.vue diff --git a/packages/core/tracing/sandbox/App.vue b/packages/core/tracing/sandbox/App.vue index 58dc016d60..f27acf9d27 100644 --- a/packages/core/tracing/sandbox/App.vue +++ b/packages/core/tracing/sandbox/App.vue @@ -6,3 +6,8 @@ + diff --git a/packages/core/tracing/sandbox/fixtures/trace-batches.json b/packages/core/tracing/sandbox/fixtures/trace-batches.json index 369770bd43..30f943e2d7 100644 --- a/packages/core/tracing/sandbox/fixtures/trace-batches.json +++ b/packages/core/tracing/sandbox/fixtures/trace-batches.json @@ -1 +1 @@ -{"batches":[{"resource":{"attributes":[{"key":"session.id","value":{"stringValue":"0193cf2f-943d-793a-819b-04ccf30948f3"}},{"key":"service.instance.id","value":{"stringValue":"4eb9bfce-d4fb-429d-b5d4-f37be1dfd680"}},{"key":"service.version","value":{"stringValue":"3.10.0.0"}},{"key":"service.name","value":{"stringValue":"kong"}}]},"scopeSpans":[{"scope":{"name":"kong-internal","version":"0.1.0"},"spans":[{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"jaw9O51b7eQ=","name":"kong","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734347832732999936","endTimeUnixNano":"1734347833661143808","attributes":[{"key":"url.full","value":{"stringValue":"http://localhost/foo/anything"}},{"key":"http.response.status_code","value":{"doubleValue":200}},{"key":"network.peer.address","value":{"stringValue":"34.226.108.155"}},{"key":"proxy.kong.latency.upstream.ttfb","value":{"doubleValue":568}},{"key":"proxy.kong.latency.upstream.read_response_duration","value":{"doubleValue":1}},{"key":"proxy.kong.latency.total","value":{"doubleValue":927}},{"key":"proxy.kong.latency.redis.total_io","value":{"doubleValue":0}},{"key":"proxy.kong.latency.tcpsock.total_io","value":{"doubleValue":0}},{"key":"http.request.size","value":{"stringValue":"280"}},{"key":"proxy.kong.request.id","value":{"stringValue":"0f9fc8071dbf62141d8f136bbb4cdd39"}},{"key":"client.address","value":{"stringValue":"127.0.0.1"}},{"key":"network.protocol.name","value":{"stringValue":"http"}},{"key":"proxy.kong.service.id","value":{"stringValue":"6ac56e3e-6f02-417b-b683-3d8bcfa7a839"}},{"key":"network.peer.port","value":{"doubleValue":443}},{"key":"network.protocol.version","value":{"stringValue":"1.1"}},{"key":"proxy.kong.route.id","value":{"stringValue":"34627a0f-d67f-4aff-b5db-462e0d4ca1f3"}},{"key":"client.port","value":{"stringValue":"51632"}},{"key":"proxy.kong.upstream.id","value":{"stringValue":"060cc439-1fa0-4711-a87b-7721d71c4eb4"}},{"key":"http.request.method","value":{"stringValue":"POST"}},{"key":"proxy.kong.upstream.addr","value":{"stringValue":"34.226.108.155"}},{"key":"proxy.kong.upstream.host","value":{"stringValue":"34.226.108.155:443"}},{"key":"http.request.header.host","value":{"stringValue":"localhost"}},{"key":"proxy.kong.target.id","value":{"stringValue":"4fa11aba-7e12-48ff-9bc8-827db4939301"}},{"key":"http.route","value":{"stringValue":"/foo"}},{"key":"url.scheme","value":{"stringValue":"http"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"eU4w1buq/ME=","parentSpanId":"jaw9O51b7eQ=","name":"kong.read_client_http_headers","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734347832732999936","endTimeUnixNano":"1734347832733523456","attributes":[{"key":"proxy.kong.http.request.headers.count","value":{"doubleValue":8}},{"key":"proxy.kong.http.request.headers.size","value":{"doubleValue":195}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"Pq8AHC6l7/k=","parentSpanId":"jaw9O51b7eQ=","name":"kong.phase.rewrite","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832733757440","endTimeUnixNano":"1734347832734179072","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"jB8u1zr5ziA=","parentSpanId":"jaw9O51b7eQ=","name":"kong.phase.access","kind":"SPAN_KIND_INTERNAL","endTimeUnixNano":"1734347832734516480","status":{},"events":[{"timeUnixNano":"1730397283960413400","attributes":[{"key":"message","value":{"stringValue":"exception"}},{"key":"exception.message","value":{"stringValue":"./kong/plugins/request-transformer/handler.lua:20: attempt to index global 'some_nil_variable' (a nil value)"}}],"droppedAttributesCount":0,"name":""}]},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"jB8u1zr5zig=","parentSpanId":"jaw9O51b7eQ=","name":"kong.phase.access","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832734516480","status":{},"events":[{"timeUnixNano":"1730397283960413400","attributes":[{"key":"message","value":{"stringValue":"exception"}},{"key":"exception.message","value":{"stringValue":"./kong/plugins/request-transformer/handler.lua:20: attempt to index global 'some_nil_variable' (a nil value)"}}],"droppedAttributesCount":0,"name":""}]},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"kvqrSQxXvCg=","parentSpanId":"jB8u1zr5zig=","name":"kong.router","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832734629632","endTimeUnixNano":"1734347832734826752","attributes":[{"key":"proxy.kong.router.matched","value":{"boolValue":true}},{"key":"proxy.kong.service.id","value":{"stringValue":"6ac56e3e-6f02-417b-b683-3d8bcfa7a839"}},{"key":"proxy.kong.route.id","value":{"stringValue":"34627a0f-d67f-4aff-b5db-462e0d4ca1f3"}},{"key":"proxy.kong.router.upstream_path","value":{"stringValue":"/"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"Cur1GqHIG/8=","parentSpanId":"jB8u1zr5zig=","name":"kong.phase.access","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832735258880","endTimeUnixNano":"1734347832736532224","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"TltE6SKF1Gw=","parentSpanId":"Cur1GqHIG/8=","name":"kong.router","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832735565312","endTimeUnixNano":"1734347832735602944","attributes":[{"key":"proxy.kong.router.matched","value":{"boolValue":true}},{"key":"proxy.kong.service.id","value":{"stringValue":"6ac56e3e-6f02-417b-b683-3d8bcfa7a839"}},{"key":"proxy.kong.route.id","value":{"stringValue":"34627a0f-d67f-4aff-b5db-462e0d4ca1f3"}},{"key":"proxy.kong.router.upstream_path","value":{"stringValue":"/"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"VWA3UYCXUxs=","parentSpanId":"Cur1GqHIG/8=","name":"kong.access.plugin.acme","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832735847168","endTimeUnixNano":"1734347832735917568","attributes":[{"key":"proxy.kong.plugin.id","value":{"stringValue":"a34e6c20-3f98-4841-9858-3ca8a09095b7"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"CfAKAQA8cJI=","parentSpanId":"Cur1GqHIG/8=","name":"kong.access.plugin.request-transformer","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347832736018176","endTimeUnixNano":"1734347832736438528","attributes":[{"key":"proxy.kong.plugin.id","value":{"stringValue":"bdcb19c8-3dca-4ea9-8a0e-679fb50a3138"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"9CpiF5ZqCak=","parentSpanId":"CfAKAQA8cJI=","name":"kong.read_client_http_body","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734347832736348160","endTimeUnixNano":"1734347832736356096","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"YSaVrPJeALo=","parentSpanId":"CfAKAQA8cJI=","name":"kong.read_client_http_body","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734347832736419840","endTimeUnixNano":"1734347832736424960","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"cjHPVXNFEgI=","parentSpanId":"jB8u1zr5zig=","name":"kong.read_client_http_body","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734347832736904448","endTimeUnixNano":"1734347832736909312","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"mziYy3y5MYI=","parentSpanId":"jB8u1zr5zig=","name":"kong.phase.header_filter","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347833659182848","endTimeUnixNano":"1734347833659495168","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"JAhrk1KDjxo=","parentSpanId":"jB8u1zr5zig=","name":"kong.phase.body_filter","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734347833659626752","endTimeUnixNano":"1734347833660816128","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"izyzMU3IxCE=","parentSpanId":"jaw9O51b7eQ=","name":"kong.upstream.selection","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734347832737147392","endTimeUnixNano":"1734347833091174400","attributes":[{"key":"proxy.kong.upstream.lb_algorithm","value":{"stringValue":"round-robin"}},{"key":"try_count","value":{"doubleValue":1}},{"key":"proxy.kong.upstream.id","value":{"stringValue":"060cc439-1fa0-4711-a87b-7721d71c4eb4"}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"1pq1U0wCeVY=","parentSpanId":"izyzMU3IxCE=","name":"kong.upstream.try_select","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734347832737147392","endTimeUnixNano":"1734347833091174400","attributes":[{"key":"try_count","value":{"doubleValue":1}},{"key":"keepalive","value":{"boolValue":true}},{"key":"network.peer.name","value":{"stringValue":"httpbin.org"}},{"key":"network.peer.address","value":{"stringValue":"34.226.108.155"}},{"key":"proxy.kong.target.id","value":{"stringValue":"4fa11aba-7e12-48ff-9bc8-827db4939301"}},{"key":"network.peer.port","value":{"doubleValue":443}},{"key":"proxy.kong.latency.upstream.connect_duration","value":{"doubleValue":354}}],"status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"pNj/Jg8tINw=","parentSpanId":"jaw9O51b7eQ=","name":"kong.upstream.ttfb","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734347833091174400","endTimeUnixNano":"1734347833659174400","status":{}},{"traceId":"NIyrU6/7p6ncDoct0nEbgA==","spanId":"7peBX+7x154=","parentSpanId":"jaw9O51b7eQ=","name":"kong.upstream.read_response","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734347833659174400","endTimeUnixNano":"1734347833660174336","status":{}}]}]}]} +{"batches":[{"resource":{"attributes":[{"key":"service.instance.id","value":{"stringValue":"5445b0c8-417b-47a0-b747-c7565e925795"}},{"key":"service.version","value":{"stringValue":"3.10.0.0"}},{"key":"session.id","value":{"stringValue":"0193f2d3-3c27-72c1-8c98-968e21c0aee1"}},{"key":"service.name","value":{"stringValue":"kong"}}]},"scopeSpans":[{"scope":{"name":"kong-internal","version":"0.1.0"},"spans":[{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"XGRJrQWeLiY=","name":"kong","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734945777892000000","endTimeUnixNano":"1734945778545911040","attributes":[{"key":"proxy.kong.route.id","value":{"stringValue":"d4783d0e-f7bd-41e5-b676-4bea060a4482"}},{"key":"proxy.kong.consumer.id","value":{"stringValue":"26c55ffc-ff1e-44ee-8c1d-a57d0efed5bb"}},{"key":"proxy.kong.upstream.id","value":{"stringValue":"unknown"}},{"key":"proxy.kong.latency.3p.redis.total_io","value":{"doubleValue":0}},{"key":"proxy.kong.upstream.addr","value":{"stringValue":"98.85.100.80"}},{"key":"proxy.kong.upstream.host","value":{"stringValue":"98.85.100.80:80"}},{"key":"proxy.kong.latency.client","value":{"doubleValue":1.230848}},{"key":"proxy.kong.target.id","value":{"stringValue":"unknown"}},{"key":"http.request.header.host","value":{"stringValue":"localhost"}},{"key":"proxy.kong.latency.upstream","value":{"doubleValue":553.02685546875}},{"key":"proxy.kong.request.id","value":{"stringValue":"15016151c88a7d6efdd9f70211390e00"}},{"key":"http.request.method","value":{"stringValue":"GET"}},{"key":"proxy.kong.latency.3p.total_io","value":{"doubleValue":97.96864}},{"key":"url.scheme","value":{"stringValue":"http"}},{"key":"http.request.size","value":{"stringValue":"177"}},{"key":"proxy.kong.latency.upstream.ttfb","value":{"doubleValue":273}},{"key":"network.protocol.version","value":{"stringValue":"1.1"}},{"key":"network.protocol.name","value":{"stringValue":"http"}},{"key":"proxy.kong.latency.3p.http_client.total_io","value":{"doubleValue":0}},{"key":"network.peer.address","value":{"stringValue":"98.85.100.80"}},{"key":"http.response.status_code","value":{"doubleValue":200}},{"key":"proxy.kong.latency.internal","value":{"doubleValue":0.7736565312499124}},{"key":"proxy.kong.latency.total","value":{"doubleValue":653}},{"key":"url.full","value":{"stringValue":"http://localhost/headers"}},{"key":"proxy.kong.latency.3p.tcpsock.total_io","value":{"doubleValue":0}},{"key":"http.route","value":{"stringValue":"/"}},{"key":"proxy.kong.latency.3p.dns.total_io","value":{"doubleValue":97.96864}},{"key":"client.port","value":{"stringValue":"54336"}},{"key":"proxy.kong.latency.upstream.read_response_duration","value":{"doubleValue":42}},{"key":"client.address","value":{"stringValue":"10.88.0.3"}},{"key":"network.peer.port","value":{"doubleValue":80}},{"key":"proxy.kong.service.id","value":{"stringValue":"1e4a129d-fc17-454f-91ae-e9e337d91ef7"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"aacSUwadpqE=","parentSpanId":"XGRJrQWeLiY=","name":"kong.read_client_http_headers","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734945777892000000","endTimeUnixNano":"1734945777892954368","attributes":[{"key":"proxy.kong.http.request.headers.count","value":{"doubleValue":7}},{"key":"proxy.kong.http.request.headers.size","value":{"doubleValue":154}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"PEs/Bv4uaTI=","parentSpanId":"XGRJrQWeLiY=","name":"kong.phase.rewrite","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777892962048","endTimeUnixNano":"1734945777893030656","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"7pDGDX3R5Oo=","parentSpanId":"XGRJrQWeLiY=","name":"kong.phase.access","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777893038080","endTimeUnixNano":"1734945777992456960","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"SjF7n5NjpnM=","parentSpanId":"7pDGDX3R5Oo=","name":"kong.router","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777893170176","endTimeUnixNano":"1734945777893306368","attributes":[{"key":"proxy.kong.router.matched","value":{"boolValue":true}},{"key":"proxy.kong.router.upstream_path","value":{"stringValue":"/"}},{"key":"proxy.kong.route.id","value":{"stringValue":"d4783d0e-f7bd-41e5-b676-4bea060a4482"}},{"key":"proxy.kong.service.id","value":{"stringValue":"1e4a129d-fc17-454f-91ae-e9e337d91ef7"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"IassFhpADd4=","parentSpanId":"7pDGDX3R5Oo=","name":"kong.access.plugin.basic-auth","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777893407232","endTimeUnixNano":"1734945777893959680","attributes":[{"key":"proxy.kong.plugin.id","value":{"stringValue":"9159d5cf-a5c2-4b52-9b7b-ef8364738bd5"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"+SHWMqgXcNI=","parentSpanId":"7pDGDX3R5Oo=","name":"kong.access.plugin.rate-limiting","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777893981696","endTimeUnixNano":"1734945777894172928","attributes":[{"key":"proxy.kong.plugin.id","value":{"stringValue":"6def3c80-02b6-4c06-9cc8-aa4b6054083d"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"QS939BibQew=","parentSpanId":"7pDGDX3R5Oo=","name":"kong.access.plugin.request-transformer","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945777894209280","endTimeUnixNano":"1734945777894420992","attributes":[{"key":"proxy.kong.plugin.id","value":{"stringValue":"a20e552b-a9ec-442e-8112-519fd4cba2cd"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"ouLjxrSPI+U=","parentSpanId":"7pDGDX3R5Oo=","name":"kong.dns","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734945777894442496","endTimeUnixNano":"1734945777992443648","attributes":[{"key":"proxy.kong.dns.record.ip","value":{"stringValue":"98.85.100.80"}},{"key":"proxy.kong.dns.record.port","value":{"doubleValue":80}},{"key":"proxy.kong.dns.tries","value":{"arrayValue":{"values":[{"kvlistValue":{"values":[{"key":"msg","value":{"arrayValue":{"values":[{"stringValue":"cache-miss"}]}}},{"key":"qname","value":{"stringValue":"(short)httpbin.org"}}]}},{"kvlistValue":{"values":[{"key":"qtype","value":{"doubleValue":33}},{"key":"msg","value":{"arrayValue":{"values":[{"stringValue":"cache-miss"},{"stringValue":"querying"},{"stringValue":"dns server error: 3 name error"}]}}},{"key":"qname","value":{"stringValue":"httpbin.org"}}]}},{"kvlistValue":{"values":[{"key":"qtype","value":{"doubleValue":1}},{"key":"msg","value":{"arrayValue":{"values":[{"stringValue":"cache-miss"},{"stringValue":"querying"}]}}},{"key":"qname","value":{"stringValue":"httpbin.org"}}]}}]}}},{"key":"proxy.kong.dns.record.domain","value":{"stringValue":"httpbin.org"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"VhrEVU4LHpU=","parentSpanId":"XGRJrQWeLiY=","name":"kong.read_client_http_body","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734945777992481536","endTimeUnixNano":"1734945777992624128","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"9lvYW/eP63k=","parentSpanId":"XGRJrQWeLiY=","name":"kong.phase.header_filter","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945778503905792","endTimeUnixNano":"1734945778504432640","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"QqQCNGmyUrQ=","parentSpanId":"XGRJrQWeLiY=","name":"kong.phase.body_filter","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1734945778545603072","endTimeUnixNano":"1734945778545764864","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"UO4zpoqc014=","parentSpanId":"XGRJrQWeLiY=","name":"kong.upstream.selection","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734945777992626432","endTimeUnixNano":"1734945778230653440","attributes":[{"key":"proxy.kong.upstream.id","value":{"stringValue":"unknown"}},{"key":"try_count","value":{"doubleValue":1}},{"key":"proxy.kong.upstream.lb_algorithm","value":{"stringValue":"unknown"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"5r+nlh8z2Os=","parentSpanId":"UO4zpoqc014=","name":"kong.upstream.try_select","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734945777992626432","endTimeUnixNano":"1734945778230653440","attributes":[{"key":"network.peer.port","value":{"doubleValue":80}},{"key":"try_count","value":{"doubleValue":1}},{"key":"network.peer.address","value":{"stringValue":"98.85.100.80"}},{"key":"proxy.kong.latency.upstream.connect_duration","value":{"doubleValue":238}},{"key":"keepalive","value":{"boolValue":true}},{"key":"network.peer.name","value":{"stringValue":"httpbin.org"}},{"key":"proxy.kong.target.id","value":{"stringValue":"unknown"}}],"status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"NkBDHdQ8Prk=","parentSpanId":"XGRJrQWeLiY=","name":"kong.upstream.ttfb","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734945778230653440","endTimeUnixNano":"1734945778503653376","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"Tx2fk5OVCb4=","parentSpanId":"XGRJrQWeLiY=","name":"kong.upstream.read_response","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1734945778503653376","endTimeUnixNano":"1734945778545653248","status":{}},{"traceId":"OO2ACWBe0hJbXNOOKR4m6A==","spanId":"bcQ4HvPhEGo=","parentSpanId":"XGRJrQWeLiY=","name":"kong.wait_for_client_read","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1734945778545764864","endTimeUnixNano":"1734945778545898752","status":{}}]}]}]} diff --git a/packages/core/tracing/src/components/trace-viewer/SpanAttributeTable.vue b/packages/core/tracing/src/components/trace-viewer/SpanAttributeTable.vue index e605ebf032..b63d9edf05 100644 --- a/packages/core/tracing/src/components/trace-viewer/SpanAttributeTable.vue +++ b/packages/core/tracing/src/components/trace-viewer/SpanAttributeTable.vue @@ -13,9 +13,9 @@ :span="span" /> - diff --git a/packages/core/tracing/src/constants/spans.ts b/packages/core/tracing/src/constants/spans.ts index 9fa7fd3c60..e26a133068 100644 --- a/packages/core/tracing/src/constants/spans.ts +++ b/packages/core/tracing/src/constants/spans.ts @@ -17,7 +17,8 @@ export const SPAN_LATENCY_ATTRIBUTES: Record = { 'proxy.kong.latency.client': 'trace_viewer.latency.labels.client', } -const SPAN_ATTR_KEY_KONG_PREFIX = 'proxy.kong' +export const SPAN_ATTR_KEY_KONG_PREFIX = 'proxy.kong.' +export const SPAN_ATTR_KEY_KONG_LATENCY_PREFIX = 'proxy.kong.latency.' /** * These are known attributes that will appear in the spans for ease of access. @@ -27,12 +28,12 @@ export const SPAN_ATTRIBUTE_KEYS = { HTTP_REQUEST_METHOD: 'http.request.method', HTTP_RESPONSE_STATUS_CODE: 'http.response.status_code', HTTP_ROUTE: 'http.route', - KONG_CONSUMER_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.consumer.id`, - KONG_PLUGIN_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.plugin.id`, - KONG_ROUTE_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.route.id`, - KONG_SERVICE_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.service.id`, - KONG_TARGET_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.target.id`, - KONG_UPSTREAM_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}.upstream.id`, + KONG_CONSUMER_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}consumer.id`, + KONG_PLUGIN_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}plugin.id`, + KONG_ROUTE_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}route.id`, + KONG_SERVICE_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}service.id`, + KONG_TARGET_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}target.id`, + KONG_UPSTREAM_ID: `${SPAN_ATTR_KEY_KONG_PREFIX}upstream.id`, URL_FULL: 'url.full', } satisfies Record diff --git a/packages/core/tracing/src/types/spans.ts b/packages/core/tracing/src/types/spans.ts index c631296360..3de712f718 100644 --- a/packages/core/tracing/src/types/spans.ts +++ b/packages/core/tracing/src/types/spans.ts @@ -79,6 +79,9 @@ export interface SpanSamplerAttribute { export interface SpanLatency { key: string - labelKey: TranslationKey + /** + * When omitted, we will use the `key` as the label. + */ + labelKey?: TranslationKey milliseconds: number } diff --git a/packages/core/tracing/src/utils/spans.ts b/packages/core/tracing/src/utils/spans.ts index edd50ed9ad..61b4a90161 100644 --- a/packages/core/tracing/src/utils/spans.ts +++ b/packages/core/tracing/src/utils/spans.ts @@ -1,5 +1,6 @@ import { cloneDeep } from 'lodash-es' -import { SPAN_LATENCY_ATTRIBUTES, SPAN_ZERO_ID } from '../constants' +import type { TranslationKey } from '../composables/useI18n' +import { SPAN_ATTR_KEY_KONG_LATENCY_PREFIX, SPAN_LATENCY_ATTRIBUTES, SPAN_ZERO_ID } from '../constants' import { type IAnyValue, type IKeyValue, type Span, type SpanLatency, type SpanNode } from '../types' /** @@ -183,7 +184,7 @@ export const unwrapAnyValue = (value: IAnyValue): T | null => { return null } -const latencyOrdering = Object.keys(SPAN_LATENCY_ATTRIBUTES) +const LATENCY_ORDERING = Object.keys(SPAN_LATENCY_ATTRIBUTES) export const toSpanLatencies = (attributes?: IKeyValue[]): SpanLatency[] => { if (!attributes) { @@ -192,10 +193,10 @@ export const toSpanLatencies = (attributes?: IKeyValue[]): SpanLatency[] => { return attributes .reduce((attrs, attr) => { - const labelKey = SPAN_LATENCY_ATTRIBUTES[attr.key] - if (!labelKey) { + if (!attr.key.startsWith(SPAN_ATTR_KEY_KONG_LATENCY_PREFIX)) { return attrs } + const labelKey: TranslationKey | undefined = SPAN_LATENCY_ATTRIBUTES[attr.key] attrs.push({ key: attr.key, @@ -205,5 +206,9 @@ export const toSpanLatencies = (attributes?: IKeyValue[]): SpanLatency[] => { return attrs }, [] as SpanLatency[]) - .sort((a, b) => latencyOrdering.indexOf(a.key) - latencyOrdering.indexOf(b.key)) + .sort((a, b) => { + const ia = LATENCY_ORDERING.indexOf(a.key) + const ib = LATENCY_ORDERING.indexOf(b.key) + return (ia >= 0 ? ia : LATENCY_ORDERING.length) - (ib >= 0 ? ib : LATENCY_ORDERING.length) + }) } From 9c9e4126863169f473b45e5dbd48c06d4f4fdce6 Mon Sep 17 00:00:00 2001 From: Makito Date: Tue, 24 Dec 2024 17:27:13 +0800 Subject: [PATCH 7/8] fix(tracing): revert --- packages/core/tracing/src/utils/time.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/core/tracing/src/utils/time.ts b/packages/core/tracing/src/utils/time.ts index 7803629d83..b902bd2448 100644 --- a/packages/core/tracing/src/utils/time.ts +++ b/packages/core/tracing/src/utils/time.ts @@ -11,10 +11,6 @@ export const getDurationFormatter = (locales: Intl.LocalesArgument = 'en') => { let t = nanoseconds - if (t === 0) { - return '0' - } - if (t < 1000) { return `${fmt.format(t)}ns` } From 99138e437fc56492b838e4acc2e936b8f46a3b46 Mon Sep 17 00:00:00 2001 From: Makito Date: Wed, 25 Dec 2024 13:59:17 +0800 Subject: [PATCH 8/8] fix(tracing): address feedback on latency display --- ...{SpanDescription.vue => SpanBasicInfo.vue} | 50 ++++--- .../trace-viewer/SpanLatencyTable.vue | 39 ++++- .../components/trace-viewer/TraceLatency.vue | 4 +- .../components/trace-viewer/TraceViewer.vue | 4 +- .../components/waterfall/WaterfallSpanRow.vue | 5 +- packages/core/tracing/src/constants/spans.ts | 32 ++-- packages/core/tracing/src/locales/en.json | 141 ++++++++++++------ packages/core/tracing/src/types/spans.ts | 3 +- packages/core/tracing/src/utils/spans.ts | 69 +++++++-- 9 files changed, 248 insertions(+), 99 deletions(-) rename packages/core/tracing/src/components/trace-viewer/{SpanDescription.vue => SpanBasicInfo.vue} (55%) diff --git a/packages/core/tracing/src/components/trace-viewer/SpanDescription.vue b/packages/core/tracing/src/components/trace-viewer/SpanBasicInfo.vue similarity index 55% rename from packages/core/tracing/src/components/trace-viewer/SpanDescription.vue rename to packages/core/tracing/src/components/trace-viewer/SpanBasicInfo.vue index 96675a3c85..25dacad457 100644 --- a/packages/core/tracing/src/components/trace-viewer/SpanDescription.vue +++ b/packages/core/tracing/src/components/trace-viewer/SpanBasicInfo.vue @@ -1,13 +1,22 @@ @@ -63,6 +80,12 @@ const latencies = computed(() => toSpanLatencies(props.span.attributes)) font-size: $kui-font-size-30; } } + + .latency-nested { + :deep(.config-card-details-label) { + padding-left: $kui-space-40; + } + } } } diff --git a/packages/core/tracing/src/components/trace-viewer/TraceLatency.vue b/packages/core/tracing/src/components/trace-viewer/TraceLatency.vue index b1e6f1c2af..06b457d295 100644 --- a/packages/core/tracing/src/components/trace-viewer/TraceLatency.vue +++ b/packages/core/tracing/src/components/trace-viewer/TraceLatency.vue @@ -18,13 +18,13 @@ import { computed } from 'vue' import composables from '../../composables' import type { SpanNode } from '../../types' -import { formatLatency, toSpanLatencies } from '../../utils' +import { formatLatency, toOverviewLatencies } from '../../utils' const { i18n: { t } } = composables.useI18n() const props = defineProps<{ span: SpanNode['span'] }>() -const latencies = computed(() => toSpanLatencies(props.span.attributes)) +const latencies = computed(() => toOverviewLatencies(props.span.attributes))