grafana/public/app/plugins/panel/traces/TracesPanel.tsx
Joey Tawadrous 09634b518c
Traces Panel: Add new Traces Panel visualization (#47534)
* Panel

* Support tempo dash variables

* Support tempo explore variables

* Only show span links for explore

* Cleanup

* Added tests

* apply variables to search

* Tests for search variables

* Handling no data

* Interpolation and tests

* TracesPanel tests

* More tests

* Fix for backend test

* Manager integration test fix

* Traces doc and updated visualizations index doc

* Logs for this span

* Search, scrollToTop, other improvements

* Refactor to extract common code

* Removed TopOfViewRefType optional

* Remove topOfViewRef optional

* Removed another optional and fixed tests

* Test

* Only show search bar if trace

* Support traces panel in add to dashboard

* Self review

* Update betterer

* Linter fixes

* Updated traces doc

* Ahh, moved the for more info too

* Updated betterer.results

* Added new icon

* Updated expectedListResp.json
2022-05-03 17:42:36 +01:00

70 lines
2.5 KiB
TypeScript

import { css } from '@emotion/css';
import TracePageSearchBar from '@jaegertracing/jaeger-ui-components/src/TracePageHeader/TracePageSearchBar';
import { TopOfViewRefType } from '@jaegertracing/jaeger-ui-components/src/TraceTimelineViewer/VirtualizedTraceView';
import React, { useMemo, useState, createRef } from 'react';
import { useAsync } from 'react-use';
import { PanelProps } from '@grafana/data';
import { getDataSourceSrv } from '@grafana/runtime';
import { TraceView } from 'app/features/explore/TraceView/TraceView';
import { useSearch } from 'app/features/explore/TraceView/useSearch';
import { transformDataFrames } from 'app/features/explore/TraceView/utils/transform';
const styles = {
wrapper: css`
height: 100%;
overflow: scroll;
`,
};
export const TracesPanel: React.FunctionComponent<PanelProps> = ({ data }) => {
const topOfViewRef = createRef<HTMLDivElement>();
const traceProp = useMemo(() => transformDataFrames(data.series[0]), [data.series]);
const { search, setSearch, spanFindMatches } = useSearch(traceProp?.spans);
const [focusedSpanIdForSearch, setFocusedSpanIdForSearch] = useState('');
const [searchBarSuffix, setSearchBarSuffix] = useState('');
const dataSource = useAsync(async () => {
return await getDataSourceSrv().get(data.request?.targets[0].datasource?.uid);
});
const scrollElement = document.getElementsByClassName(styles.wrapper)[0];
if (!data || !data.series.length || !traceProp) {
return (
<div className="panel-empty">
<p>No data found in response</p>
</div>
);
}
return (
<div className={styles.wrapper}>
<div ref={topOfViewRef}></div>
{data.series[0]?.meta?.preferredVisualisationType === 'trace' ? (
<TracePageSearchBar
navigable={true}
searchValue={search}
setSearch={setSearch}
spanFindMatches={spanFindMatches}
searchBarSuffix={searchBarSuffix}
setSearchBarSuffix={setSearchBarSuffix}
focusedSpanIdForSearch={focusedSpanIdForSearch}
setFocusedSpanIdForSearch={setFocusedSpanIdForSearch}
/>
) : null}
<TraceView
dataFrames={data.series}
scrollElement={scrollElement}
traceProp={traceProp}
spanFindMatches={spanFindMatches}
search={search}
focusedSpanIdForSearch={focusedSpanIdForSearch}
queryResponse={data}
datasource={dataSource.value}
topOfViewRef={topOfViewRef}
topOfViewRefType={TopOfViewRefType.Panel}
/>
</div>
);
};