From 8f4cad7b219bf70d12145bcaaed431965067ca1f Mon Sep 17 00:00:00 2001 From: Kaung Zin Hein <83657429+Zen-cronic@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:29:26 -0500 Subject: [PATCH] Fix: Deep clone trace data for consistency (#2571) Resolves #2483 ## Description of the changes - deep cloned the trace data before passing it to @pyroscope/flamegraph ## How was this change tested? - npm run test - visual comparison with this traces data [trace.zip](https://github.com/user-attachments/files/18364826/trace.zip): Timeline view: ![timeline](https://github.com/user-attachments/assets/52f3e039-0ef9-40e9-9461-69e3c3867995) Flamegraph view: ![flamegraph](https://github.com/user-attachments/assets/e68110e1-e26a-4a09-99b3-beb99ebc5275) Navigating back and forth between flamegraph and timeline views no longer show inconsistent data ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Kaung Zin Hein Signed-off-by: Kaung Zin Hein <83657429+Zen-cronic@users.noreply.github.com> Co-authored-by: Yuri Shkuro --- .../src/components/TracePage/TraceFlamegraph/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.tsx b/packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.tsx index 5d4a5e7a5c..0347a36f5a 100644 --- a/packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.tsx +++ b/packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.tsx @@ -13,12 +13,15 @@ // limitations under the License. import React from 'react'; import { FlamegraphRenderer, convertJaegerTraceToProfile } from '@pyroscope/flamegraph'; +import _cloneDeep from 'lodash/cloneDeep'; import '@pyroscope/flamegraph/dist/index.css'; import './index.css'; const TraceFlamegraph = ({ trace }: any) => { - const convertedProfile = trace && trace.data ? convertJaegerTraceToProfile(trace.data) : null; + // Cloned b/c convertJaegerTraceToProfile or FlamegraphRenderer can possibly mutate the trace + // https://github.com/jaegertracing/jaeger-ui/issues/2483 + const convertedProfile = trace && trace.data ? convertJaegerTraceToProfile(_cloneDeep(trace.data)) : null; return (