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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
import { ReactNode, useEffect, useMemo, useState } from 'react';
// eslint-disable-next-line no-restricted-imports
import { useSelector } from 'react-redux';
import { Histogram, RefreshCw } from '@signozhq/icons';
import { AppLink } from 'lib/router/AppLink';
import { useAppParams } from 'lib/router/useAppParams';
import { Alert, Table } from 'antd';
import { Typography } from '@signozhq/ui/typography';
import ROUTES from 'constants/routes';
import useErrorNotification from 'hooks/useErrorNotification';
import { useQueryService } from 'hooks/useQueryService';
import useResourceAttribute from 'hooks/useResourceAttribute';
import { convertRawQueriesToTraceSelectedTags } from 'hooks/useResourceAttribute/utils';
import { AppState } from 'store/reducers';
import { GlobalReducer } from 'types/reducer/globalTime';
import { Tags } from 'hooks/useResourceAttribute/types';
import './ServiceTopLevelOperations.styles.scss';
export default function ServiceTopLevelOperations(): JSX.Element {
const { servicename: encodedServiceName } = useAppParams<'servicename'>();
const { maxTime, minTime, selectedTime } = useSelector<
AppState,
GlobalReducer
>((state) => state.globalTime);
const servicename = decodeURIComponent(encodedServiceName || '');
const { queries } = useResourceAttribute();
const selectedTags = useMemo(
() => (convertRawQueriesToTraceSelectedTags(queries) as Tags[]) || [],
[queries],
);
const [topLevelOperations, setTopLevelOperations] = useState<string[]>([]);
const { data, error, isLoading } = useQueryService({
minTime,
maxTime,
selectedTime,
selectedTags,
});
useErrorNotification(error);
useEffect(() => {
const selectedService = data?.find(
(service) => service.serviceName === servicename,
);
setTopLevelOperations(selectedService?.dataWarning?.topLevelOps || []);
}, [servicename, data]);
const alertDesc = (): ReactNode => (
<div className="">
SigNoz calculates the RED metrics for a service using the entry-point spans.
For more details, you can check out our
<a
href="https://signoz.io/docs/userguide/metrics/"
target="_blank"
rel="noreferrer"
>
{' '}
docs
</a>
. We expect the number of unique entry-point operations to be no more than
2500. The high number of top level operations might be due to an
instrumentation issue in your service. Below table shows the sample top level
operations. Please refer to official docs for span name guidelines{' '}
<a
href="https://opentelemetry.io/docs/specs/otel/trace/api/#span"
target="_blank"
rel="noreferrer"
>
{' '}
here
</a>{' '}
and update the instrumentation to to follow the guidelines. If there are any
dynamic IDs in the span name, make sure to use the span attributes instead.
If you have more questions, please reach out to us via support.
</div>
);
const columns = [
{
title: 'Top Level Operation',
key: 'top-level-operation',
render: (operation: string): JSX.Element => (
<div className="top-level-operations-list-item" key={operation}>
<Typography.Text> {operation} </Typography.Text>
</div>
),
},
];
return (
<div className="container">
<Typography.Title level={5} className="top-level-operations-header">
<AppLink to={ROUTES.APPLICATION}>
<span className="breadcrumb">
{' '}
<Histogram size={12} /> services{' '}
</span>
</AppLink>
<div className="divider">/</div>
<AppLink to={`${ROUTES.APPLICATION}/${servicename}`}>
<span className="breadcrumb">{servicename} </span>
</AppLink>
</Typography.Title>
<div className="info-alert">
<Alert message={alertDesc()} type="info" showIcon />
</div>
{isLoading && (
<div className="loading-top-level-operations">
<Typography.Title level={5}>
<RefreshCw className="animate-spin" size="sm" /> Loading ...
</Typography.Title>
</div>
)}
{!isLoading && (
<div
className="top-level-operations-list"
data-testid="top-level-operations-table"
>
<Table
columns={columns}
bordered
title={(): string => 'Top Level Operations'}
// @ts-expect-error
dataSource={topLevelOperations}
loading={isLoading}
showHeader={false}
pagination={{
pageSize: 100,
hideOnSinglePage: true,
showTotal: (total: number, range: number[]): string =>
`${range[0]}-${range[1]} of ${total}`,
}}
/>
</div>
)}
</div>
);
}