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(logs): unwrap lone message field from json log body (#12206)

Aditya Singh31cb4d752086
diff --git a/frontend/src/api/v5/queryRange/convertV5Response.test.ts b/frontend/src/api/v5/queryRange/convertV5Response.test.ts
index c1e39aa51e..3c7758d5bb 100644
--- a/frontend/src/api/v5/queryRange/convertV5Response.test.ts
+++ b/frontend/src/api/v5/queryRange/convertV5Response.test.ts
@@ -380,4 +380,88 @@ describe('convertV5ResponseToLegacy', () => {
},
});
});
+
+ describe('raw logs body: extract lone `message` field', () => {
+ function makeRawResult(
+ rows: Array<{ timestamp: string; data: Record<string, any> }>,
+ type: 'raw' | 'trace' = 'raw',
+ ): ReturnType<typeof convertV5ResponseToLegacy> {
+ const v5Data = {
+ type,
+ data: { results: [{ queryName: 'A', rows }] },
+ meta: { rowsScanned: 0, bytesScanned: 0, durationMs: 0, stepIntervals: {} },
+ } as unknown as QueryRangeResponseV5;
+
+ const params = makeBaseParams(type as RequestType, [
+ {
+ type: 'builder_query',
+ spec: {
+ name: 'A',
+ signal: type === 'trace' ? 'traces' : 'logs',
+ stepInterval: 60,
+ disabled: false,
+ aggregations: [],
+ },
+ },
+ ]);
+
+ const input: SuccessResponse<MetricRangePayloadV5, QueryRangeRequestV5> =
+ makeBaseSuccess({ data: v5Data }, params);
+
+ return convertV5ResponseToLegacy(input, { A: 'A' }, false);
+ }
+
+ it('unwraps body when it is an object with only a message field', () => {
+ const result = makeRawResult([
+ { timestamp: '2026-07-21T00:00:00Z', data: { body: { message: 'hello' } } },
+ ]);
+
+ expect(result.payload.data.result[0].list?.[0]?.data?.body).toBe('hello');
+ });
+
+ it('leaves body unchanged when the object has keys besides message', () => {
+ const body = { message: 'hello', level: 'INFO' };
+ const result = makeRawResult([
+ { timestamp: '2026-07-21T00:00:00Z', data: { body } },
+ ]);
+
+ expect(result.payload.data.result[0].list?.[0]?.data?.body).toStrictEqual(
+ body,
+ );
+ });
+
+ it('leaves a string body unchanged (use_json_body off)', () => {
+ const result = makeRawResult([
+ {
+ timestamp: '2026-07-21T00:00:00Z',
+ data: { body: '{"message":"hello"}' },
+ },
+ ]);
+
+ expect(result.payload.data.result[0].list?.[0]?.data?.body).toBe(
+ '{"message":"hello"}',
+ );
+ });
+
+ it('stringifies the nested object when message is an object', () => {
+ const nested = { a: 1, b: 2 };
+ const result = makeRawResult([
+ { timestamp: '2026-07-21T00:00:00Z', data: { body: { message: nested } } },
+ ]);
+
+ expect(result.payload.data.result[0].list?.[0]?.data?.body).toBe(
+ JSON.stringify(nested),
+ );
+ });
+
+ it('does not add a body key to rows without a body (traces)', () => {
+ const result = makeRawResult(
+ [{ timestamp: '2026-07-21T00:00:00Z', data: { name: 'span-1' } }],
+ 'trace',
+ );
+
+ const data = (result.payload.data.result[0].list?.[0] as any)?.data ?? {};
+ expect('body' in data).toBe(false);
+ });
+ });
});
diff --git a/frontend/src/api/v5/queryRange/convertV5Response.ts b/frontend/src/api/v5/queryRange/convertV5Response.ts
index c113a71eb1..6e9bd73dea 100644
--- a/frontend/src/api/v5/queryRange/convertV5Response.ts
+++ b/frontend/src/api/v5/queryRange/convertV5Response.ts
@@ -273,6 +273,19 @@ function convertScalarWithFormatForWeb(
});
}
+function extractOnlyMessageBody(body: unknown): unknown {
+ const isJsonBody = body && typeof body === 'object' && !Array.isArray(body);
+ if (isJsonBody) {
+ const keys = Object.keys(body);
+ const hasOnlyMessageKey = keys.length === 1 && keys[0] === 'message';
+ if (hasOnlyMessageKey) {
+ const { message } = body as { message: unknown };
+ return typeof message === 'string' ? message : JSON.stringify(message);
+ }
+ }
+ return body;
+}
+
/**
* Converts V5 RawData to legacy format
*/
@@ -285,14 +298,22 @@ function convertRawData(
queryName: rawData.queryName,
legend: legendMap[rawData.queryName] || rawData.queryName,
series: null,
- list: rawData.rows?.map((row) => ({
- timestamp: row.timestamp,
- data: {
+ list: rawData.rows?.map((row) => {
+ const data = {
// Map raw data to ILog structure - spread row.data first to include all properties
...row.data,
date: row.timestamp,
- } as any,
- })),
+ } as any;
+
+ if ('body' in row.data) {
+ data.body = extractOnlyMessageBody(row.data.body);
+ }
+
+ return {
+ timestamp: row.timestamp,
+ data,
+ };
+ }),
nextCursor: rawData.nextCursor,
};
}