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.

feat(log-details): support json view for nested attributes + enable new log details (#12597)

Aditya Singhfcfc1923c327
diff --git a/frontend/src/components/LogDetail/constants.ts b/frontend/src/components/LogDetail/constants.ts
index 83f837bb3e..0e51910536 100644
--- a/frontend/src/components/LogDetail/constants.ts
+++ b/frontend/src/components/LogDetail/constants.ts
@@ -1,9 +1,5 @@
-import getLocalStorage from 'api/browser/localstorage/get';
-import { LOCALSTORAGE } from 'constants/localStorage';
-
-// Temp feature flag before actual roll-out
-export const isLogDetailsV2 =
- getLocalStorage(LOCALSTORAGE.LOG_DETAILS_V2) === 'true';
+// temporary flag to be removed with old log details code.
+export const isLogDetailsV2 = true;
export const VIEW_TYPES = {
OVERVIEW: 'OVERVIEW',
diff --git a/frontend/src/constants/localStorage.ts b/frontend/src/constants/localStorage.ts
index accec86768..4f79192e06 100644
--- a/frontend/src/constants/localStorage.ts
+++ b/frontend/src/constants/localStorage.ts
@@ -13,7 +13,6 @@ export enum LOCALSTORAGE {
TRACES_LIST_COLUMNS = 'TRACES_LIST_COLUMNS',
LOGS_LIST_COLUMNS = 'LOGS_LIST_COLUMNS',
LOGS_LIST_COLUMN_SIZING = 'LOGS_LIST_COLUMN_SIZING',
- LOG_DETAILS_V2 = 'LOG_DETAILS_V2',
LOGGED_IN_USER_NAME = 'LOGGED_IN_USER_NAME',
LOGGED_IN_USER_EMAIL = 'LOGGED_IN_USER_EMAIL',
CHAT_SUPPORT = 'CHAT_SUPPORT',
diff --git a/frontend/src/container/LogDetailedView/Overview.tsx b/frontend/src/container/LogDetailedView/Overview.tsx
index 2fb3e0ad33..7cd35162da 100644
--- a/frontend/src/container/LogDetailedView/Overview.tsx
+++ b/frontend/src/container/LogDetailedView/Overview.tsx
@@ -23,9 +23,9 @@ import { useLogAttributeActions } from './hooks/useLogAttributeActions';
import TableView from './TableView';
import {
aggregateAttributesResourcesToObject,
+ buildPrettyViewData,
getBodyDisplayString,
getSanitizedLogBody,
- parseJsonStringBody,
removeEscapeCharacters,
} from './utils';
@@ -71,11 +71,7 @@ function Overview({
if (isLogDetailsV2) {
const raw = aggregateAttributesResourcesToObject(logData);
- const prettyData = Object.fromEntries(
- Object.entries({ ...raw, body: parseJsonStringBody(raw.body) }).filter(
- ([, value]) => value !== undefined,
- ),
- );
+ const prettyData = buildPrettyViewData(raw);
return (
<div className="overview-container">
<DataViewer
diff --git a/frontend/src/container/LogDetailedView/constants.ts b/frontend/src/container/LogDetailedView/constants.ts
index d9aaaccdc0..8f2d714e21 100644
--- a/frontend/src/container/LogDetailedView/constants.ts
+++ b/frontend/src/container/LogDetailedView/constants.ts
@@ -1,6 +1,6 @@
export enum LogAttributeBucket {
ATTRIBUTES = 'attributes',
- RESOURCES = 'resources',
+ RESOURCES = 'resource',
SCOPE = 'scope',
}
diff --git a/frontend/src/container/LogDetailedView/logAttributeActions.utils.test.ts b/frontend/src/container/LogDetailedView/logAttributeActions.utils.test.ts
index 52461b97e5..be2b1dfed8 100644
--- a/frontend/src/container/LogDetailedView/logAttributeActions.utils.test.ts
+++ b/frontend/src/container/LogDetailedView/logAttributeActions.utils.test.ts
@@ -33,7 +33,7 @@ describe('buildLogFilterTarget', () => {
it('maps `resources` with Resource type', () => {
expect(
- buildLogFilterTarget(['resources', 'service.name'], 'api', true),
+ buildLogFilterTarget(['resource', 'service.name'], 'api', true),
).toMatchObject({
fieldKey: 'service.name',
metricsType: MetricsType.Resource,
@@ -53,6 +53,30 @@ describe('buildLogFilterTarget', () => {
});
});
+ describe('nested attribute values (parsed JSON)', () => {
+ it('marks a sub-field of a parsed attribute copy-only (restricted, no group-by)', () => {
+ const t = buildLogFilterTarget(['attributes', 'payload', 'x'], 1, true);
+ expect(t.isRestricted).toBe(true);
+ expect(t.groupBySupported).toBe(false);
+ expect(t.groupByKey).toBeUndefined();
+ });
+
+ it('leaves a top-level attribute (depth 2) filterable', () => {
+ const t = buildLogFilterTarget(['attributes', 'payload'], 'v', true);
+ expect(t.isRestricted).toBe(false);
+ expect(t.groupBySupported).toBe(true);
+ });
+
+ it('does not restrict nested resource/scope values', () => {
+ expect(
+ buildLogFilterTarget(['resource', 'k8s', 'pod'], 'p', true).isRestricted,
+ ).toBe(false);
+ expect(
+ buildLogFilterTarget(['scope', 'a', 'b'], 'v', true).isRestricted,
+ ).toBe(false);
+ });
+ });
+
describe('restricted fields (timestamp / id)', () => {
it.each(['timestamp', 'id'])(
'marks %s restricted with no group-by',
@@ -65,6 +89,30 @@ describe('buildLogFilterTarget', () => {
);
});
+ describe('group-by-restricted fields (trace_id)', () => {
+ it('allows filtering but not group-by on top-level trace_id', () => {
+ const t = buildLogFilterTarget(['trace_id'], 'abc123', true);
+ expect(t.isRestricted).toBe(false);
+ expect(t.filterInOperator).toBe('=');
+ expect(t.groupBySupported).toBe(false);
+ expect(t.groupByKey).toBeUndefined();
+ });
+
+ it.each([
+ ['resource', ['resource', 'trace_id']],
+ ['attributes', ['attributes', 'trace_id']],
+ ])(
+ 'blocks group-by on a %s field named trace_id, keeping filter',
+ (_bucket, path) => {
+ const t = buildLogFilterTarget(path as string[], 'abc123', true);
+ expect(t.isRestricted).toBe(false);
+ expect(t.filterInOperator).toBe('=');
+ expect(t.groupBySupported).toBe(false);
+ expect(t.groupByKey).toBeUndefined();
+ },
+ );
+ });
+
describe('body scalars', () => {
it('maps a top-level body scalar to body.<key> with =/!=, groupable when json body on', () => {
const t = buildLogFilterTarget(['body', 'message'], 'hello', true);
diff --git a/frontend/src/container/LogDetailedView/logAttributeActions.utils.ts b/frontend/src/container/LogDetailedView/logAttributeActions.utils.ts
index 5d8683bbf8..36a3d05b93 100644
--- a/frontend/src/container/LogDetailedView/logAttributeActions.utils.ts
+++ b/frontend/src/container/LogDetailedView/logAttributeActions.utils.ts
@@ -5,7 +5,10 @@ import {
QUERY_BUILDER_FUNCTIONS,
} from 'constants/antlrQueryConstants';
import { OPERATORS as QUERY_BUILDER_OPERATORS } from 'constants/queryBuilder';
-import { RESTRICTED_SELECTED_FIELDS } from 'container/LogsFilters/config';
+import {
+ RESTRICTED_GROUP_BY_FIELDS,
+ RESTRICTED_SELECTED_FIELDS,
+} from 'container/LogsFilters/config';
import { MetricsType } from 'container/MetricsApplication/constant';
import { getOperatorValue } from 'container/QueryBuilder/filters/QueryBuilderSearch/utils';
import { chooseAutocompleteFromCustomValue } from 'lib/newQueryBuilder/chooseAutocompleteFromCustomValue';
@@ -83,15 +86,24 @@ export const buildLogFilterTarget = (
if (root !== 'body') {
const fieldKey =
fieldKeyPath.length > 1 ? fieldKeyPath.slice(1).join('.') : String(root);
- const isRestricted = RESTRICTED_SELECTED_FIELDS.includes(fieldKey);
+ // Temporarily removing filter/group-by support for nested attributes.
+ // This will be removed once backend starts to support these actions.
+ const isNestedAttributeValue =
+ root === LogAttributeBucket.ATTRIBUTES && fieldKeyPath.length > 2;
+
+ const isRestricted =
+ RESTRICTED_SELECTED_FIELDS.includes(fieldKey) || isNestedAttributeValue;
+
+ const groupBySupported =
+ !isRestricted && !RESTRICTED_GROUP_BY_FIELDS.includes(fieldKey);
return {
fieldKey,
filterInOperator: OPERATORS['='],
filterOutOperator: OPERATORS['!='],
dataType: getDataTypes(value),
metricsType: metricsTypeForRoot(root),
- groupBySupported: !isRestricted,
- groupByKey: isRestricted ? undefined : fieldKey,
+ groupBySupported,
+ groupByKey: groupBySupported ? fieldKey : undefined,
isRestricted,
};
}
diff --git a/frontend/src/container/LogDetailedView/util.test.ts b/frontend/src/container/LogDetailedView/util.test.ts
index e1ddebe6ba..58fc000ec2 100644
--- a/frontend/src/container/LogDetailedView/util.test.ts
+++ b/frontend/src/container/LogDetailedView/util.test.ts
@@ -3,45 +3,79 @@ import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
import {
aggregateAttributesResourcesToObject,
+ buildPrettyViewData,
flattenObject,
getDataTypes,
getSanitizedLogBody,
- parseJsonStringBody,
+ parseJsonStringValue,
recursiveParseJSON,
} from './utils';
-describe('parseJsonStringBody', () => {
+describe('parseJsonStringValue', () => {
it('parses a JSON-object string into an object', () => {
- expect(parseJsonStringBody('{"a":1,"b":{"c":2}}')).toStrictEqual({
+ expect(parseJsonStringValue('{"a":1,"b":{"c":2}}')).toStrictEqual({
a: 1,
b: { c: 2 },
});
});
it('parses a JSON-array string into an array', () => {
- expect(parseJsonStringBody('[1,2,3]')).toStrictEqual([1, 2, 3]);
+ expect(parseJsonStringValue('[1,2,3]')).toStrictEqual([1, 2, 3]);
});
it('returns a plain (non-JSON) string unchanged', () => {
- expect(parseJsonStringBody('plain log line')).toBe('plain log line');
+ expect(parseJsonStringValue('plain log line')).toBe('plain log line');
});
it('returns a string that is not object/array-looking unchanged', () => {
- expect(parseJsonStringBody('42')).toBe('42');
+ expect(parseJsonStringValue('42')).toBe('42');
});
it('returns an invalid JSON string unchanged', () => {
- expect(parseJsonStringBody('{not valid}')).toBe('{not valid}');
+ expect(parseJsonStringValue('{not valid}')).toBe('{not valid}');
});
- it('returns an already-object body unchanged (same reference)', () => {
- const body = { message: 'hi', a: 1 };
- expect(parseJsonStringBody(body)).toBe(body);
+ it('returns an already-object value unchanged (same reference)', () => {
+ const value = { message: 'hi', a: 1 };
+ expect(parseJsonStringValue(value)).toBe(value);
});
- it('leaves a body larger than the 128KB parse guard as a string', () => {
+ it('leaves a value larger than the 128KB parse guard as a string', () => {
const huge = `{"x":"${'a'.repeat(130 * 1024)}"}`;
- expect(parseJsonStringBody(huge)).toBe(huge);
+ expect(parseJsonStringValue(huge)).toBe(huge);
+ });
+});
+
+describe('buildPrettyViewData', () => {
+ const baseRaw = {
+ id: 'log-1',
+ timestamp: 1234,
+ body: 'hello',
+ attributes: {},
+ resource: {},
+ scope: {},
+ } as any;
+
+ it('parses a JSON-string body into a tree', () => {
+ const result = buildPrettyViewData({ ...baseRaw, body: '{"a":1}' });
+ expect(result.body).toStrictEqual({ a: 1 });
+ });
+
+ it('parses attribute values that are JSON strings, leaves others as-is', () => {
+ const result = buildPrettyViewData({
+ ...baseRaw,
+ attributes: { payload: '{"x":1}', name: 'cart', count: 3 },
+ });
+ expect(result.attributes).toStrictEqual({
+ payload: { x: 1 },
+ name: 'cart',
+ count: 3,
+ });
+ });
+
+ it('drops undefined fields so they do not render as empty rows', () => {
+ const result = buildPrettyViewData({ ...baseRaw, trace_id: undefined });
+ expect('trace_id' in result).toBe(false);
});
});
@@ -65,7 +99,7 @@ describe('aggregateAttributesResourcesToObject', () => {
'http.method': 'GET',
retries: 3,
});
- expect(result.resources).toStrictEqual({ 'service.name': 'cart' });
+ expect(result.resource).toStrictEqual({ 'service.name': 'cart' });
expect(result.scope).toStrictEqual({ lib: 'otel' });
expect(result.body).toBe('hello');
expect(result.id).toBe('log-1');
diff --git a/frontend/src/container/LogDetailedView/utils.tsx b/frontend/src/container/LogDetailedView/utils.tsx
index 6a6072c16b..486cff2aa2 100644
--- a/frontend/src/container/LogDetailedView/utils.tsx
+++ b/frontend/src/container/LogDetailedView/utils.tsx
@@ -276,7 +276,7 @@ export const aggregateAttributesResourcesToObject = (
traceFlags: logData.traceFlags,
traceId: logData.traceId,
attributes: {},
- resources: {},
+ resource: {},
scope: {},
severity_text: logData.severity_text,
severity_number: logData.severity_number,
@@ -290,8 +290,8 @@ export const aggregateAttributesResourcesToObject = (
outputJson.attributes = outputJson.attributes || {};
Object.assign(outputJson.attributes, logData[key as keyof ILog]);
} else if (key.startsWith('resources_')) {
- outputJson.resources = outputJson.resources || {};
- Object.assign(outputJson.resources, logData[key as keyof ILog]);
+ outputJson.resource = outputJson.resource || {};
+ Object.assign(outputJson.resource, logData[key as keyof ILog]);
} else if (key.startsWith('scope_string')) {
outputJson.scope = outputJson.scope || {};
Object.assign(outputJson.scope, logData[key as keyof ILog]);
@@ -315,30 +315,57 @@ export const aggregateAttributesResourcesToString = (logData: ILog): string => {
}
};
-const MAX_JSON_BODY_PARSE_BYTES = 128 * 1024;
+const MAX_JSON_PARSE_BYTES = 128 * 1024;
-// A JSON-encoded object/array `body` is parsed so DataViewer renders it as a
-// tree instead of one escaped string; plain-text bodies are returned unchanged.
+// A JSON-encoded object/array string is parsed so DataViewer renders it as a tree
+// instead of one escaped string; non-JSON / plain-text values are returned unchanged.
// Guarded against very large payloads.
-export const parseJsonStringBody = (body: ILog['body']): ILog['body'] => {
- if (typeof body !== 'string') {
- return body;
+export const parseJsonStringValue = (value: unknown): unknown => {
+ if (typeof value !== 'string') {
+ return value;
}
- const trimmed = body.trim();
+ const trimmed = value.trim();
const looksLikeJson = trimmed.startsWith('{') || trimmed.startsWith('[');
- if (!looksLikeJson || trimmed.length > MAX_JSON_BODY_PARSE_BYTES) {
- return body;
+ if (!looksLikeJson || trimmed.length > MAX_JSON_PARSE_BYTES) {
+ return value;
}
try {
const parsed = JSON.parse(trimmed);
- return parsed !== null && typeof parsed === 'object'
- ? (parsed as ILogBody)
- : body;
+ return parsed !== null && typeof parsed === 'object' ? parsed : value;
} catch {
- return body;
+ return value;
}
};
+// Parse each attribute value that's a stringified JSON string into an object
+// Non-JSON values are left unchanged.
+const parseAttributeJsonValues = (
+ attributes: Record<string, unknown>,
+): Record<string, unknown> => {
+ const parsed: Record<string, unknown> = {};
+ Object.keys(attributes).forEach((key) => {
+ parsed[key] = parseJsonStringValue(attributes[key]);
+ });
+ return parsed;
+};
+
+export const buildPrettyViewData = (
+ raw: ILogAggregateAttributesResources,
+): Record<string, unknown> => {
+ const prettyData: Record<string, unknown> = { ...raw };
+ prettyData.body = parseJsonStringValue(raw.body);
+ prettyData.attributes = parseAttributeJsonValues(raw.attributes);
+
+ // drop undefined fields so they don't render as empty rows
+ Object.keys(prettyData).forEach((key) => {
+ if (prettyData[key] === undefined) {
+ delete prettyData[key];
+ }
+ });
+
+ return prettyData;
+};
+
const isFloat = (num: number): boolean => num % 1 !== 0;
const isBooleanString = (str: string): boolean =>
diff --git a/frontend/src/container/LogsFilters/config.ts b/frontend/src/container/LogsFilters/config.ts
index 12741d0df1..5a846a744f 100644
--- a/frontend/src/container/LogsFilters/config.ts
+++ b/frontend/src/container/LogsFilters/config.ts
@@ -2,6 +2,9 @@ import { blue, red } from '@ant-design/colors';
export const RESTRICTED_SELECTED_FIELDS = ['timestamp', 'id'];
+// Fields that can be filtered on but not grouped by in the log details view.
+export const RESTRICTED_GROUP_BY_FIELDS = ['body', 'trace_id'];
+
export const ICON_STYLE = {
PLUS: { color: blue[5] },
CLOSE: { color: red[5] },
diff --git a/frontend/src/types/api/logs/log.ts b/frontend/src/types/api/logs/log.ts
index 8a0c57e2aa..0746b228b9 100644
--- a/frontend/src/types/api/logs/log.ts
+++ b/frontend/src/types/api/logs/log.ts
@@ -41,6 +41,6 @@ type OmitAttributesResources = Pick<
export type ILogAggregateAttributesResources = OmitAttributesResources & {
attributes: Record<string, never>;
- resources: Record<string, never>;
+ resource: Record<string, never>;
scope: Record<string, never>;
};