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
chore: Accept body as Map in FE (#11291)
Piyush Singariyaa50bc53f4ce8
diff --git a/frontend/src/components/LogDetail/index.tsx b/frontend/src/components/LogDetail/index.tsxindex e1c59d289d..e2687a2ed4 100644--- a/frontend/src/components/LogDetail/index.tsx+++ b/frontend/src/components/LogDetail/index.tsx@@ -50,6 +50,7 @@ import {import { JsonView } from 'periscope/components/JsonView';import { useAppContext } from 'providers/App/App';import { AppState } from 'store/reducers';+import { ILogBody } from 'types/api/logs/log';import { Query, TagFilter } from 'types/api/queryBuilder/queryBuilderData';import { DataSource, StringOperators } from 'types/common/queryBuilder';import { GlobalReducer } from 'types/reducer/globalTime';@@ -217,20 +218,17 @@ function LogDetailInner({const logBody = useMemo(() => {if (!isBodyJsonQueryEnabled) {- return log?.body || '';+ return (log?.body as string) ?? '';}-- try {- const json = JSON.parse(log?.body || '');-- if (typeof json?.message === 'string' && json.message !== '') {- return json.message;- }-- return log?.body || '';- } catch {- return log?.body || '';+ // Feature enabled: body is always a map; message is always a string+ const bodyObj = log?.body as ILogBody;+ if (!bodyObj) {+ return '';+ }+ if (bodyObj.message) {+ return bodyObj.message;}+ return JSON.stringify(bodyObj);}, [isBodyJsonQueryEnabled, log?.body]);const htmlBody = useMemo(diff --git a/frontend/src/components/Logs/RawLogView/index.tsx b/frontend/src/components/Logs/RawLogView/index.tsxindex 8c9f1f7f8b..a488b47822 100644--- a/frontend/src/components/Logs/RawLogView/index.tsx+++ b/frontend/src/components/Logs/RawLogView/index.tsx@@ -9,7 +9,10 @@ import { Color } from '@signozhq/design-tokens';import { Tooltip } from 'antd';import { VIEW_TYPES } from 'components/LogDetail/constants';import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';-import { getSanitizedLogBody } from 'container/LogDetailedView/utils';+import {+ getBodyDisplayString,+ getSanitizedLogBody,+} from 'container/LogDetailedView/utils';import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';// hooksimport { useIsDarkMode } from 'hooks/useDarkMode';@@ -99,7 +102,7 @@ function RawLogView({// Check if body is selectedconst showBody = selectedFields.some((field) => field.name === 'body');if (showBody) {- parts.push(`${attributesText} ${data.body}`);+ parts.push(`${attributesText} ${getBodyDisplayString(data.body)}`);} else {parts.push(attributesText);}diff --git a/frontend/src/components/Logs/TableView/useLogsTableColumns.tsx b/frontend/src/components/Logs/TableView/useLogsTableColumns.tsxindex 7b554318a7..b8da0e7de6 100644--- a/frontend/src/components/Logs/TableView/useLogsTableColumns.tsx+++ b/frontend/src/components/Logs/TableView/useLogsTableColumns.tsx@@ -2,7 +2,10 @@ import type { ReactElement } from 'react';import { useMemo } from 'react';import TanStackTable from 'components/TanStackTableView';import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';-import { getSanitizedLogBody } from 'container/LogDetailedView/utils';+import {+ getBodyDisplayString,+ getSanitizedLogBody,+} from 'container/LogDetailedView/utils';import { FontSize } from 'container/OptionsMenu/types';import { FlatLogData } from 'lib/logs/flatLogData';import { useTimezone } from 'providers/Timezone';@@ -87,7 +90,7 @@ export function useLogsTableColumns({? {id: 'body',header: 'Body',- accessorFn: (log): string => log.body,+ accessorFn: (log): string => getBodyDisplayString(log.body),canBeHidden: false,width: { default: '100%', min: 300 },cell: ({ value, isActive }): ReactElement => (diff --git a/frontend/src/container/LogDetailedView/Overview.tsx b/frontend/src/container/LogDetailedView/Overview.tsxindex b3cc3f7924..e9d1ed6ca1 100644--- a/frontend/src/container/LogDetailedView/Overview.tsx+++ b/frontend/src/container/LogDetailedView/Overview.tsx@@ -14,7 +14,7 @@ import { ILog } from 'types/api/logs/log';import { ActionItemProps } from './ActionItem';import TableView from './TableView';-import { removeEscapeCharacters } from './utils';+import { getBodyDisplayString, removeEscapeCharacters } from './utils';import './Overview.styles.scss';@@ -112,7 +112,7 @@ function Overview({children: (<div className="logs-body-content"><MEditor- value={removeEscapeCharacters(logData.body)}+ value={removeEscapeCharacters(getBodyDisplayString(logData.body))}language="json"options={options}onChange={(): void => {}}diff --git a/frontend/src/container/LogDetailedView/TableView.tsx b/frontend/src/container/LogDetailedView/TableView.tsxindex d707e4ea18..c75fc6e7f8 100644--- a/frontend/src/container/LogDetailedView/TableView.tsx+++ b/frontend/src/container/LogDetailedView/TableView.tsx@@ -106,10 +106,20 @@ function TableView({isListViewPanel,]);- const flattenLogData: Record<string, string> | null = useMemo(- () => (logData ? flattenObject(logData) : null),- [logData],- );+ // When USE_JSON_BODY is enabled, body arrives as a pre-parsed object. Serialize it+ // back to a string so flattenObject keeps `body` as a single table row instead of+ // recursively expanding it into dotted sub-keys (body.message, body.foo.bar, …),+ // which would break the tree view in BodyContent that relies on record.field === 'body'.+ const flattenLogData: Record<string, string> | null = useMemo(() => {+ if (!logData) {+ return null;+ }+ const normalizedLog =+ typeof logData.body === 'object' && logData.body !== null+ ? { ...logData, body: JSON.stringify(logData.body) }+ : logData;+ return flattenObject(normalizedLog);+ }, [logData]);const handleClick = (operator: string,diff --git a/frontend/src/container/LogDetailedView/TableView/useAsyncJSONProcessing.ts b/frontend/src/container/LogDetailedView/TableView/useAsyncJSONProcessing.tsindex 933fc8a9b8..2fd5b04cd4 100644--- a/frontend/src/container/LogDetailedView/TableView/useAsyncJSONProcessing.ts+++ b/frontend/src/container/LogDetailedView/TableView/useAsyncJSONProcessing.ts@@ -10,7 +10,7 @@ const MAX_BODY_BYTES = 100 * 1024; // 100 KB// Hook for async JSON processingconst useAsyncJSONProcessing = (- value: string,+ value: string | Record<string, unknown>,shouldProcess: boolean,handleChangeSelectedView?: ChangeViewFunctionType,): {@@ -40,11 +40,17 @@ const useAsyncJSONProcessing = (return (): void => {};}- // Avoid processing if the json is too large- const byteSize = new Blob([value]).size;- if (byteSize > MAX_BODY_BYTES) {- return (): void => {};- }+ // When value is already a parsed object skip the size check and JSON parsing+ const parseBody = (): Record<string, unknown> | null => {+ if (typeof value === 'object' && value !== null) {+ return value as Record<string, unknown>;+ }+ const byteSize = new Blob([value as string]).size;+ if (byteSize > MAX_BODY_BYTES) {+ return null;+ }+ return recursiveParseJSON(value as string);+ };processingRef.current = true;setJsonState({ isLoading: true, treeData: null, error: null });@@ -53,8 +59,8 @@ const useAsyncJSONProcessing = (const processAsync = (): void => {setTimeout(() => {try {- const parsedBody = recursiveParseJSON(value);- if (!isEmpty(parsedBody)) {+ const parsedBody = parseBody();+ if (parsedBody && !isEmpty(parsedBody)) {const treeData = jsonToDataNodes(parsedBody, {isBodyJsonQueryEnabled,handleChangeSelectedView,@@ -82,8 +88,8 @@ const useAsyncJSONProcessing = (// eslint-disable-next-line sonarjs/no-identical-functions(): void => {try {- const parsedBody = recursiveParseJSON(value);- if (!isEmpty(parsedBody)) {+ const parsedBody = parseBody();+ if (parsedBody && !isEmpty(parsedBody)) {const treeData = jsonToDataNodes(parsedBody, {isBodyJsonQueryEnabled,handleChangeSelectedView,diff --git a/frontend/src/container/LogDetailedView/utils.tsx b/frontend/src/container/LogDetailedView/utils.tsxindex 65d22f7bac..ba3dc56d5f 100644--- a/frontend/src/container/LogDetailedView/utils.tsx+++ b/frontend/src/container/LogDetailedView/utils.tsx@@ -4,7 +4,11 @@ import { ChangeViewFunctionType } from 'container/ExplorerOptions/types';import { MetricsType } from 'container/MetricsApplication/constant';import dompurify from 'dompurify';import { uniqueId } from 'lodash-es';-import { ILog, ILogAggregateAttributesResources } from 'types/api/logs/log';+import {+ ILog,+ ILogAggregateAttributesResources,+ ILogBody,+} from 'types/api/logs/log';import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';import { FORBID_DOM_PURIFY_ATTR, FORBID_DOM_PURIFY_TAGS } from 'utils/app';@@ -433,3 +437,8 @@ export const getSanitizedLogBody = (return '{}';}};++// Returns a plain string for display contexts (Monaco editor, table cells, raw log row).+export function getBodyDisplayString(body: string | ILogBody): string {+ return typeof body === 'string' ? body : JSON.stringify(body as ILogBody);+}diff --git a/frontend/src/container/PipelinePage/PipelineListsView/Preview/components/LogsList/index.tsx b/frontend/src/container/PipelinePage/PipelineListsView/Preview/components/LogsList/index.tsxindex a4cf3ca5fd..5b20e97aba 100644--- a/frontend/src/container/PipelinePage/PipelineListsView/Preview/components/LogsList/index.tsx+++ b/frontend/src/container/PipelinePage/PipelineListsView/Preview/components/LogsList/index.tsx@@ -2,6 +2,7 @@ import { Expand } from '@signozhq/icons';import LogDetail from 'components/LogDetail';import { VIEW_TYPES } from 'components/LogDetail/constants';import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';+import { getBodyDisplayString } from 'container/LogDetailedView/utils';import { useActiveLog } from 'hooks/logs/useActiveLog';import { useTimezone } from 'providers/Timezone';import { ILog } from 'types/api/logs/log';@@ -26,7 +27,9 @@ function LogsList({ logs }: LogsListProps): JSX.Element {DATE_TIME_FORMATS.UTC_MONTH_SHORT,)}</div>- <div className="logs-preview-list-item-body">{log.body}</div>+ <div className="logs-preview-list-item-body">+ {getBodyDisplayString(log.body)}+ </div><divclassName="logs-preview-list-item-expand"onClick={makeLogDetailsHandler(log)}diff --git a/frontend/src/types/api/logs/log.ts b/frontend/src/types/api/logs/log.tsindex 64402a576e..d4c1daf52f 100644--- a/frontend/src/types/api/logs/log.ts+++ b/frontend/src/types/api/logs/log.ts@@ -1,3 +1,8 @@+export interface ILogBody {+ message?: string | null;+ [key: string]: unknown;+}+export interface ILog {date: string;timestamp: number | string;@@ -8,7 +13,7 @@ export interface ILog {traceFlags: number;severityText: string;severityNumber: number;- body: string;+ body: string | ILogBody;resources_string: Record<string, never>;scope_string: Record<string, never>;attributesString: Record<string, never>;