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: use allow list in getSpanDisplayData (#13124)

Gaurav Tewaric1cc58ac506b
diff --git a/frontend/src/pages/TraceDetailsV3/__tests__/getSpanDisplayData.test.ts b/frontend/src/pages/TraceDetailsV3/__tests__/getSpanDisplayData.test.ts
new file mode 100644
index 0000000000..55ced5be64
--- /dev/null
+++ b/frontend/src/pages/TraceDetailsV3/__tests__/getSpanDisplayData.test.ts
@@ -0,0 +1,29 @@
+import { SpanV3 } from 'types/api/trace/getTraceV3';
+
+import { getSpanDisplayData } from '../utils';
+
+describe('getSpanDisplayData', () => {
+ it('keeps only allow-listed fields', () => {
+ const span = {
+ span_id: 's1',
+ trace_id: 't1',
+ name: 'GET /api',
+ attributes: { 'http.method': 'GET' },
+ resource: { 'service.name': 'api' },
+ level: 1,
+ has_children: true,
+ sub_tree_node_count: 3,
+ 'service.name': 'api',
+ time_unix: 1700000000,
+ formattedInput: '[]',
+ } as unknown as SpanV3;
+
+ expect(getSpanDisplayData(span)).toStrictEqual({
+ span_id: 's1',
+ trace_id: 't1',
+ name: 'GET /api',
+ attributes: { 'http.method': 'GET' },
+ resource: { 'service.name': 'api' },
+ });
+ });
+});
diff --git a/frontend/src/pages/TraceDetailsV3/utils.ts b/frontend/src/pages/TraceDetailsV3/utils.ts
index c9633847d7..654a0c2ca3 100644
--- a/frontend/src/pages/TraceDetailsV3/utils.ts
+++ b/frontend/src/pages/TraceDetailsV3/utils.ts
@@ -1,3 +1,5 @@
+import type { SpantypesWaterfallSpanDTO } from 'api/generated/services/sigNoz.schemas';
+import { pick } from 'lodash-es';
import { SpanV3 } from 'types/api/trace/getTraceV3';
import { COLOR_BY_OPTIONS } from './constants';
@@ -46,28 +48,43 @@ export function hasInfraMetadata(span: SpanV3 | undefined): boolean {
return INFRA_METADATA_KEYS.some((key) => getSpanAttribute(span, key));
}
-// Top-level fields that exist on the API response only to support waterfall
-// rendering. They have no value in the Span Details DataViewer. Drop the whole
-// constant + helper once the backend stops emitting them.
-const HIDDEN_SPAN_FIELDS_IN_DETAILS_VIEW: ReadonlySet<string> = new Set([
- 'sub_tree_node_count',
- 'has_children',
- 'level',
- 'service.name',
-]);
+// Top-level fields shown in the Span Details DataViewer. Everything else on the
+// API response (e.g. waterfall rendering data) is hidden.
+const VISIBLE_SPAN_FIELDS_IN_DETAILS_VIEW = [
+ 'span_id',
+ 'trace_id',
+ 'parent_span_id',
+ 'name',
+ 'kind_string',
+ 'duration_nano',
+ 'has_error',
+ 'status_code',
+ 'status_code_string',
+ 'status_message',
+ 'flags',
+ 'is_remote',
+ 'trace_state',
+ 'attributes',
+ 'resource',
+ 'events',
+ 'references',
+ 'http_method',
+ 'http_url',
+ 'http_host',
+ 'db_name',
+ 'db_operation',
+ 'external_http_method',
+ 'external_http_url',
+ 'response_status_code',
+ // Keys must exist on the waterfall DTO.
+] as const satisfies readonly (keyof SpantypesWaterfallSpanDTO)[];
/**
- * Shallow-copies the span with waterfall-only fields stripped, for display in
- * the Span Details DataViewer.
+ * Shallow-copies the allow-listed span fields, for display in the Span Details
+ * DataViewer.
*/
export function getSpanDisplayData(span: SpanV3): Record<string, unknown> {
- const result: Record<string, unknown> = {};
- for (const [key, value] of Object.entries(span)) {
- if (!HIDDEN_SPAN_FIELDS_IN_DETAILS_VIEW.has(key)) {
- result[key] = value;
- }
- }
- return result;
+ return pick(span, VISIBLE_SPAN_FIELDS_IN_DETAILS_VIEW);
}
/**