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
feat(log-details): add highlights section to log details drawer [2/3] (#12425)
Aditya Singh0dd9a156b988
diff --git a/frontend/src/components/LogDetail/LogHighlights/LogHighlights.module.scss b/frontend/src/components/LogDetail/LogHighlights/LogHighlights.module.scssnew file mode 100644index 0000000000..2e24698dec--- /dev/null+++ b/frontend/src/components/LogDetail/LogHighlights/LogHighlights.module.scss@@ -0,0 +1,46 @@+.highlights {+ display: grid;+ grid-template-columns: repeat(4, minmax(0, 1fr));+ gap: 12px 16px;+ padding: 12px 0;++ // Constrain each KeyValueLabel (the grid items) to its cell.+ :global(.key-value-label) {+ width: auto;+ min-width: 0;+ overflow: hidden;+ }+}++.valueBadge {+ --badge-font-size: 13px;+ box-sizing: border-box;+ max-width: 100%;+ min-width: 0;+}++// Truncating text inside a badge+.badgeText {+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.serviceDot {+ width: 6px;+ height: 6px;+ border-radius: 50%;+ background: var(--accent-forest);+ flex-shrink: 0;+ margin-right: 4px;+}++.traceLink {+ display: inline-block;+ max-width: 100%;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ color: var(--accent-primary);+}diff --git a/frontend/src/components/LogDetail/LogHighlights/LogHighlights.tsx b/frontend/src/components/LogDetail/LogHighlights/LogHighlights.tsxnew file mode 100644index 0000000000..11e08cc9c5--- /dev/null+++ b/frontend/src/components/LogDetail/LogHighlights/LogHighlights.tsx@@ -0,0 +1,36 @@+import KeyValueLabel from 'periscope/components/KeyValueLabel';+import { ILog } from 'types/api/logs/log';++import { LOG_HIGHLIGHTS } from './config';+import styles from './LogHighlights.module.scss';++interface LogHighlightsProps {+ log: ILog;+}++function LogHighlights({ log }: LogHighlightsProps): JSX.Element | null {+ const fields = LOG_HIGHLIGHTS.map((field) => ({+ key: field.key,+ label: field.label,+ value: field.render(log),+ })).filter((field) => field.value != null);++ if (fields.length === 0) {+ return null;+ }++ return (+ <div className={styles.highlights} data-testid="log-details-highlights">+ {fields.map((field) => (+ <KeyValueLabel+ key={field.key}+ badgeKey={field.label}+ badgeValue={field.value}+ direction="column"+ />+ ))}+ </div>+ );+}++export default LogHighlights;diff --git a/frontend/src/components/LogDetail/LogHighlights/TraceIdField.tsx b/frontend/src/components/LogDetail/LogHighlights/TraceIdField.tsxnew file mode 100644index 0000000000..393cf27a47--- /dev/null+++ b/frontend/src/components/LogDetail/LogHighlights/TraceIdField.tsx@@ -0,0 +1,23 @@+import { Link } from 'react-router-dom';++import styles from './LogHighlights.module.scss';++interface TraceIdFieldProps {+ traceId: string;+}++function TraceIdField({ traceId }: TraceIdFieldProps): JSX.Element {+ return (+ <Link+ to={{ pathname: `/trace/${traceId}` }}+ target="_blank"+ rel="noreferrer"+ className={styles.traceLink}+ title={traceId}+ >+ {traceId}+ </Link>+ );+}++export default TraceIdField;diff --git a/frontend/src/components/LogDetail/LogHighlights/config.tsx b/frontend/src/components/LogDetail/LogHighlights/config.tsxnew file mode 100644index 0000000000..7fd6ca3bab--- /dev/null+++ b/frontend/src/components/LogDetail/LogHighlights/config.tsx@@ -0,0 +1,102 @@+import { ReactNode } from 'react';+import { Badge, BadgeColor } from '@signozhq/ui/badge';+import { LogType } from 'components/Logs/LogStateIndicator/LogStateIndicator';+import { getLogIndicatorType } from 'components/Logs/LogStateIndicator/utils';+import { ILog } from 'types/api/logs/log';++import styles from './LogHighlights.module.scss';+import TraceIdField from './TraceIdField';++// Severity badge color mirrors the LogStateIndicator bar+const SEVERITY_COLOR: Record<string, BadgeColor> = {+ [LogType.TRACE]: 'forest',+ [LogType.DEBUG]: 'aqua',+ [LogType.INFO]: 'robin',+ [LogType.WARN]: 'amber',+ [LogType.ERROR]: 'cherry',+ [LogType.FATAL]: 'sakura',+};++export interface LogHighlightConfig {+ key: string;+ label: string;+ render: (log: ILog) => ReactNode | null;+}++// Resource/attribute lookup (keys like `service.name` live in resources_string,+// occasionally attributes_string). Typed loosely as these are string maps.+const getAttr = (log: ILog, key: string): string =>+ (log.resources_string as unknown as Record<string, string>)?.[key] ||+ (log.attributes_string as unknown as Record<string, string>)?.[key] ||+ '';++const valueBadge = (+ value: string,+ options?: { prefix?: ReactNode; color?: BadgeColor },+): ReactNode => (+ <Badge color={options?.color ?? 'vanilla'} className={styles.valueBadge}>+ {options?.prefix}+ <span className={styles.badgeText} title={value}>+ {value}+ </span>+ </Badge>+);++export const LOG_HIGHLIGHTS: LogHighlightConfig[] = [+ {+ key: 'service',+ label: 'SERVICE',+ render: (log): ReactNode | null => {+ const value = getAttr(log, 'service.name');+ return value+ ? valueBadge(value, {+ prefix: <span className={styles.serviceDot} />,+ })+ : null;+ },+ },+ {+ key: 'severity',+ label: 'SEVERITY',+ render: (log): ReactNode | null => {+ if (!log.severity_text) {+ return null;+ }+ return valueBadge(log.severity_text, {+ color: SEVERITY_COLOR[getLogIndicatorType(log)] ?? 'vanilla',+ });+ },+ },+ {+ key: 'namespace',+ label: 'NAMESPACE',+ render: (log): ReactNode | null => {+ const value = getAttr(log, 'service.namespace');+ return value ? valueBadge(value) : null;+ },+ },+ {+ key: 'environment',+ label: 'ENVIRONMENT',+ render: (log): ReactNode | null => {+ const value = getAttr(log, 'deployment.environment');+ return value ? valueBadge(value) : null;+ },+ },+ {+ key: 'traceId',+ label: 'TRACE ID',+ render: (log): ReactNode | null => {+ const traceId = log.trace_id || log.traceId;+ return traceId ? <TraceIdField traceId={traceId} /> : null;+ },+ },+ {+ key: 'spanId',+ label: 'SPAN ID',+ render: (log): ReactNode | null => {+ const spanId = log.span_id || log.spanID;+ return spanId ? valueBadge(spanId) : null;+ },+ },+];diff --git a/frontend/src/components/LogDetail/__tests__/LogDetail.test.tsx b/frontend/src/components/LogDetail/__tests__/LogDetail.test.tsxindex 67642d6f17..c7b4b45b87 100644--- a/frontend/src/components/LogDetail/__tests__/LogDetail.test.tsx+++ b/frontend/src/components/LogDetail/__tests__/LogDetail.test.tsx@@ -115,6 +115,45 @@ describe('LogDetail drawer — header (isLogDetailsV2)', () => {expect(screen.queryByText('Open in Explorer')).not.toBeInTheDocument();});+ it('renders Highlights for fields present on the log, omitting absent ones', () => {+ const logWithMeta = {+ ...mockLog,+ severity_text: 'ERROR',+ trace_id: 'trace-abc',+ resources_string: {+ 'service.name': 'checkout',+ 'deployment.environment': 'production',+ },+ } as unknown as ILog;++ renderDrawer({ log: logWithMeta });++ const highlights = screen.getByTestId('log-details-highlights');+ expect(highlights).toHaveTextContent('SEVERITY');+ expect(highlights).toHaveTextContent('ERROR');+ expect(highlights).toHaveTextContent('SERVICE');+ expect(highlights).toHaveTextContent('checkout');+ expect(highlights).toHaveTextContent('ENVIRONMENT');+ expect(highlights).toHaveTextContent('production');+ expect(highlights).toHaveTextContent('TRACE ID');+ // Absent fields are omitted (no namespace / span id on this log).+ expect(highlights).not.toHaveTextContent('NAMESPACE');+ expect(highlights).not.toHaveTextContent('SPAN ID');+ });++ it('links the trace id highlight to the trace detail in a new tab', () => {+ const logWithTrace = {+ ...mockLog,+ trace_id: 'trace-abc',+ } as unknown as ILog;++ renderDrawer({ log: logWithTrace });++ const link = screen.getByRole('link', { name: 'trace-abc' });+ expect(link).toHaveAttribute('target', '_blank');+ expect(link.getAttribute('href')).toContain('/trace/trace-abc');+ });+it('navigates to the next / previous log with the Down / Up arrow keys', async () => {const user = userEvent.setup({ pointerEventsCheck: 0 });const logs = [makeLog('log-0'), makeLog('log-1'), makeLog('log-2')];diff --git a/frontend/src/components/LogDetail/index.tsx b/frontend/src/components/LogDetail/index.tsxindex 3c4c0c81bc..6d6791ceca 100644--- a/frontend/src/components/LogDetail/index.tsx+++ b/frontend/src/components/LogDetail/index.tsx@@ -55,6 +55,7 @@ import { isLogDetailsV2, RESOURCE_KEYS, VIEW_TYPES, VIEWS } from './constants';import { LogDetailInnerProps, LogDetailProps } from './LogDetail.interfaces';import LogDetailsHeader from './LogDetailsHeader/LogDetailsHeader';import { useLogNavigation } from './LogDetailsHeader/useLogNavigation';+import LogHighlights from './LogHighlights/LogHighlights';import './LogDetails.styles.scss';@@ -399,6 +400,8 @@ function LogDetailInner({<div className="log-overflow-shadow"> </div></div>+ {isLogDetailsV2 && <LogHighlights log={log} />}+<div className="tabs-and-search"><ToggleGroupSimpletype="single"