Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.4 KB
Raw Blame
import { ToggleGroup } from '@signozhq/ui/toggle-group';
import { useAppParams } from 'lib/router/useAppParams';

import { TraceDetailsTab } from '../constants';
import { TraceDetailEventKeys, TraceDetailEvents } from '../events';
import { useTraceDetailLogEvent } from '../hooks/useTraceDetailLogEvent';
import { useTraceDetailsTab } from '../hooks/useTraceDetailsTab';

import styles from './TraceDetailsHeader.module.scss';

const TAB_ITEMS = [
	{
		value: TraceDetailsTab.Overview,
		label: 'Overview',
		testId: 'trace-details-tab-overview',
	},
	{
		value: TraceDetailsTab.Thread,
		label: 'Thread',
		testId: 'trace-details-tab-thread',
	},
];

function TraceDetailsTabs(): JSX.Element {
	const { id: traceId = '' } = useAppParams<'id'>();
	const [tab, setTab] = useTraceDetailsTab();
	const logTraceEvent = useTraceDetailLogEvent('v3', traceId);

	const handleChange = (value: string): void => {
		logTraceEvent(TraceDetailEvents.DetailsTabChanged, {
			[TraceDetailEventKeys.From]: tab,
			[TraceDetailEventKeys.To]: value,
		});
		// Pushed so the thread's "Go back" returns to the previous tab, not the previous page.
		void setTab(value as TraceDetailsTab, { history: 'push' });
	};

	return (
		<div className={styles.tabs}>
			<ToggleGroup
				variant="outlined"
				color="secondary"
				type="single"
				value={tab}
				onChange={handleChange}
				size="sm"
				items={TAB_ITEMS}
			/>
		</div>
	);
}

export default TraceDetailsTabs;