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(trace): add visuals for events on span waterfall and flamegraph (#7889)
Dimitris Mavrommatis3fc6f7ee63d7
diff --git a/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.styles.scss b/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.styles.scssindex 16501c6b01..853858a529 100644--- a/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.styles.scss+++ b/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.styles.scss@@ -18,6 +18,27 @@background-color: yellow;border-radius: 6px;cursor: pointer;++ .event-dot {+ position: absolute;+ top: 50%;+ transform: translate(-50%, -50%) rotate(45deg);+ width: 6px;+ height: 6px;+ background-color: var(--bg-robin-500);+ border: 1px solid var(--bg-robin-600);+ cursor: pointer;+ z-index: 1;++ &.error {+ background-color: var(--bg-cherry-500);+ border-color: var(--bg-cherry-600);+ }++ &:hover {+ transform: translate(-50%, -50%) rotate(45deg) scale(1.5);+ }+ }}}diff --git a/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.tsx b/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.tsxindex bd99cebee6..9d3476245e 100644--- a/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.tsx+++ b/frontend/src/container/PaginatedTraceFlamegraph/TraceFlamegraphStates/Success/Success.tsx@@ -6,6 +6,7 @@ import { Tooltip } from 'antd';import Color from 'color';import TimelineV2 from 'components/TimelineV2/TimelineV2';import { themeColors } from 'constants/theme';+import { convertTimeToRelevantUnit } from 'container/TraceDetail/utils';import { useIsDarkMode } from 'hooks/useDarkMode';import { generateColor } from 'lib/uPlotLib/utils/generateColor';import {@@ -20,6 +21,7 @@ import { useHistory, useLocation } from 'react-router-dom';import { ListRange, Virtuoso, VirtuosoHandle } from 'react-virtuoso';import { FlamegraphSpan } from 'types/api/trace/getTraceFlamegraph';import { Span } from 'types/api/trace/getTraceV2';+import { toFixed } from 'utils/toFixed';interface ITraceMetadata {startTime: number;@@ -91,7 +93,31 @@ function Success(props: ISuccessProps): JSX.Element {searchParams.set('spanId', span.spanId);history.replace({ search: searchParams.toString() });}}- />+ >+ {span.event?.map((event) => {+ const eventTimeMs = event.timeUnixNano / 1e6;+ const eventOffsetPercent =+ ((eventTimeMs - span.timestamp) / (span.durationNano / 1e6)) * 100;+ const clampedOffset = Math.max(1, Math.min(eventOffsetPercent, 99));+ const { isError } = event;+ const { time, timeUnitName } = convertTimeToRelevantUnit(+ eventTimeMs - span.timestamp,+ );+ return (+ <Tooltip+ key={`${span.spanId}-event-${event.name}-${event.timeUnixNano}`}+ title={`${event.name} @ ${toFixed(time, 2)} ${timeUnitName}`}+ >+ <div+ className={`event-dot ${isError ? 'error' : ''}`}+ style={{+ left: `${clampedOffset}%`,+ }}+ />+ </Tooltip>+ );+ })}+ </div></Tooltip>);})}diff --git a/frontend/src/container/SpanDetailsDrawer/Events/Events.styles.scss b/frontend/src/container/SpanDetailsDrawer/Events/Events.styles.scssindex 70382bf715..79a03432c5 100644--- a/frontend/src/container/SpanDetailsDrawer/Events/Events.styles.scss+++ b/frontend/src/container/SpanDetailsDrawer/Events/Events.styles.scss@@ -56,7 +56,7 @@gap: 6px;.diamond {- fill: var(--bg-cherry-500);+ fill: var(--bg-robin-500);}}}diff --git a/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx b/frontend/src/container/SpanDetailsDrawer/Events/Events.tsxindex 4eccd8254c..336556c10b 100644--- a/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx+++ b/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx@@ -3,8 +3,8 @@ import './Events.styles.scss';import { Collapse, Input, Tooltip, Typography } from 'antd';import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';import { Diamond } from 'lucide-react';-import { useMemo, useState } from 'react';-import { Event, Span } from 'types/api/trace/getTraceV2';+import { useState } from 'react';+import { Span } from 'types/api/trace/getTraceV2';import NoData from '../NoData/NoData';@@ -17,14 +17,7 @@ interface IEventsTableProps {function EventsTable(props: IEventsTableProps): JSX.Element {const { span, startTime, isSearchVisible } = props;const [fieldSearchInput, setFieldSearchInput] = useState<string>('');- const events: Event[] = useMemo(() => {- const tempEvents = [];- for (let i = 0; i < span.event?.length; i++) {- const parsedEvent = JSON.parse(span.event[i]);- tempEvents.push(parsedEvent);- }- return tempEvents;- }, [span.event]);+ const events = span.event;return (<div className="events-table">@@ -81,7 +74,18 @@ function EventsTable(props: IEventsTableProps): JSX.Element {)}</Typography.Text><Typography.Text className="timestamp-text">- after the start+ since trace start+ </Typography.Text>+ </div>+ <div className="timestamp-container">+ <Typography.Text className="attribute-value">+ {getYAxisFormattedValue(+ `${(event.timeUnixNano || 0) / 1e6 - span.timestamp}`,+ 'ms',+ )}+ </Typography.Text>+ <Typography.Text className="timestamp-text">+ since span start</Typography.Text></div></div>diff --git a/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.styles.scss b/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.styles.scssindex e2e5053ce4..afff69ee58 100644--- a/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.styles.scss+++ b/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.styles.scss@@ -273,6 +273,27 @@border-radius: 6px;}+ .event-dot {+ position: absolute;+ top: 50%;+ transform: translate(-50%, -50%) rotate(45deg);+ width: 6px;+ height: 6px;+ background-color: var(--bg-robin-500);+ border: 1px solid var(--bg-robin-600);+ cursor: pointer;+ z-index: 1;++ &.error {+ background-color: var(--bg-cherry-500);+ border-color: var(--bg-cherry-600);+ }++ &:hover {+ transform: translate(-50%, -50%) rotate(45deg) scale(1.5);+ }+ }+.span-line-text {position: relative;top: 40%;diff --git a/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx b/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.tsxindex 77ac514ca8..58345e51b9 100644--- a/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx+++ b/frontend/src/container/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx@@ -240,8 +240,33 @@ export function SpanDuration({left: `${leftOffset}%`,width: `${width}%`,backgroundColor: color,+ position: 'relative',}}- />+ >+ {span.event?.map((event) => {+ const eventTimeMs = event.timeUnixNano / 1e6;+ const eventOffsetPercent =+ ((eventTimeMs - span.timestamp) / (span.durationNano / 1e6)) * 100;+ const clampedOffset = Math.max(1, Math.min(eventOffsetPercent, 99));+ const { isError } = event;+ const { time, timeUnitName } = convertTimeToRelevantUnit(+ eventTimeMs - span.timestamp,+ );+ return (+ <Tooltip+ key={`${span.spanId}-event-${event.name}-${event.timeUnixNano}`}+ title={`${event.name} @ ${toFixed(time, 2)} ${timeUnitName}`}+ >+ <div+ className={`event-dot ${isError ? 'error' : ''}`}+ style={{+ left: `${clampedOffset}%`,+ }}+ />+ </Tooltip>+ );+ })}+ </div>{hasActionButtons && <SpanLineActionButtons span={span} />}<Tooltip title={`${toFixed(time, 2)} ${timeUnitName}`}><Typography.Textdiff --git a/frontend/src/types/api/trace/getTraceFlamegraph.ts b/frontend/src/types/api/trace/getTraceFlamegraph.tsindex df199dd4e5..8c7ea7af94 100644--- a/frontend/src/types/api/trace/getTraceFlamegraph.ts+++ b/frontend/src/types/api/trace/getTraceFlamegraph.ts@@ -7,6 +7,13 @@ export interface GetTraceFlamegraphPayloadProps {selectedSpanId: string;}+export interface Event {+ name: string;+ timeUnixNano: number;+ attributeMap: Record<string, string>;+ isError: boolean;+}+export interface FlamegraphSpan {timestamp: number;durationNano: number;@@ -17,6 +24,7 @@ export interface FlamegraphSpan {serviceName: string;name: string;level: number;+ event: Event[];}export interface GetTraceFlamegraphSuccessResponse {diff --git a/frontend/src/types/api/trace/getTraceV2.ts b/frontend/src/types/api/trace/getTraceV2.tsindex e11a662851..450ed830fd 100644--- a/frontend/src/types/api/trace/getTraceV2.ts+++ b/frontend/src/types/api/trace/getTraceV2.ts@@ -13,6 +13,7 @@ export interface Event {name: string;timeUnixNano: number;attributeMap: Record<string, string>;+ isError: boolean;}export interface Span {timestamp: number;@@ -27,7 +28,7 @@ export interface Span {name: string;references: any;tagMap: Record<string, string>;- event: string[];+ event: Event[];rootName: string;statusMessage: string;statusCodeString: string;diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.goindex c4dd8dbde1..763d3a34a6 100644--- a/pkg/query-service/app/clickhouseReader/reader.go+++ b/pkg/query-service/app/clickhouseReader/reader.go@@ -867,7 +867,7 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadataCache(ctx contexreturn cachedTraceData, nil}-func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetWaterfallSpansForTraceWithMetadataParams) (*model.GetWaterfallSpansForTraceWithMetadataResponse, *model.ApiError) {+func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetWaterfallSpansForTraceWithMetadataParams) (*model.GetWaterfallSpansForTraceWithMetadataResponse, error) {response := new(model.GetWaterfallSpansForTraceWithMetadataResponse)var startTime, endTime, durationNano, totalErrorSpans, totalSpans uint64var spanIdToSpanNodeMap = map[string]*model.Span{}@@ -916,7 +916,7 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Conerr := json.Unmarshal([]byte(item.References), &ref)if err != nil {zap.L().Error("getWaterfallSpansForTraceWithMetadata: error unmarshalling references", zap.Error(err), zap.String("traceID", traceID))- return nil, model.BadRequest(fmt.Errorf("getWaterfallSpansForTraceWithMetadata: error unmarshalling references %w", err))+ return nil, errorsV2.Newf(errorsV2.TypeInvalidInput, errorsV2.CodeInvalidInput, "getWaterfallSpansForTraceWithMetadata: error unmarshalling references %s", err.Error())}// merge attributes_number and attributes_bool to attributes_string@@ -930,6 +930,17 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Conitem.Attributes_string[k] = v}+ events := make([]model.Event, 0)+ for _, event := range item.Events {+ var eventMap model.Event+ err = json.Unmarshal([]byte(event), &eventMap)+ if err != nil {+ zap.L().Error("Error unmarshalling events", zap.Error(err))+ return nil, errorsV2.Newf(errorsV2.TypeInternal, errorsV2.CodeInternal, "getWaterfallSpansForTraceWithMetadata: error in unmarshalling events %s", err.Error())+ }+ events = append(events, eventMap)+ }+jsonItem := model.Span{SpanID: item.SpanID,TraceID: item.TraceID,@@ -942,7 +953,7 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.ConStatusCodeString: item.StatusCodeString,SpanKind: item.SpanKind,References: ref,- Events: item.Events,+ Events: events,TagMap: item.Attributes_string,Children: make([]*model.Span, 0),}@@ -998,6 +1009,7 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.ConStatusMessage: "",StatusCodeString: "",SpanKind: "",+ Events: make([]model.Event, 0),Children: make([]*model.Span, 0),}missingSpan.Children = append(missingSpan.Children, spanNode)@@ -1075,7 +1087,7 @@ func (r *ClickHouseReader) GetFlamegraphSpansForTraceCache(ctx context.Context,return cachedTraceData, nil}-func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetFlamegraphSpansForTraceParams) (*model.GetFlamegraphSpansForTraceResponse, *model.ApiError) {+func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetFlamegraphSpansForTraceParams) (*model.GetFlamegraphSpansForTraceResponse, error) {trace := new(model.GetFlamegraphSpansForTraceResponse)var startTime, endTime, durationNano uint64var spanIdToSpanNodeMap = map[string]*model.FlamegraphSpan{}@@ -1097,7 +1109,7 @@ func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgIDif err != nil {zap.L().Info("cache miss for getFlamegraphSpansForTrace", zap.String("traceID", traceID))- searchScanResponses, err := r.GetSpansForTrace(ctx, traceID, fmt.Sprintf("SELECT timestamp, duration_nano, span_id, trace_id, has_error,references, resource_string_service$$name, name FROM %s.%s WHERE trace_id=$1 and ts_bucket_start>=$2 and ts_bucket_start<=$3 ORDER BY timestamp ASC, name ASC", r.TraceDB, r.traceTableName))+ searchScanResponses, err := r.GetSpansForTrace(ctx, traceID, fmt.Sprintf("SELECT timestamp, duration_nano, span_id, trace_id, has_error,references, resource_string_service$$name, name, events FROM %s.%s WHERE trace_id=$1 and ts_bucket_start>=$2 and ts_bucket_start<=$3 ORDER BY timestamp ASC, name ASC", r.TraceDB, r.traceTableName))if err != nil {return nil, err}@@ -1111,7 +1123,18 @@ func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgIDerr := json.Unmarshal([]byte(item.References), &ref)if err != nil {zap.L().Error("Error unmarshalling references", zap.Error(err))- return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("error in unmarshalling references: %w", err)}+ return nil, errorsV2.Newf(errorsV2.TypeInternal, errorsV2.CodeInternal, "getFlamegraphSpansForTrace: error in unmarshalling references %s", err.Error())+ }++ events := make([]model.Event, 0)+ for _, event := range item.Events {+ var eventMap model.Event+ err = json.Unmarshal([]byte(event), &eventMap)+ if err != nil {+ zap.L().Error("Error unmarshalling events", zap.Error(err))+ return nil, errorsV2.Newf(errorsV2.TypeInternal, errorsV2.CodeInternal, "getFlamegraphSpansForTrace: error in unmarshalling events %s", err.Error())+ }+ events = append(events, eventMap)}jsonItem := model.FlamegraphSpan{@@ -1122,6 +1145,7 @@ func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgIDDurationNano: item.DurationNano,HasError: item.HasError,References: ref,+ Events: events,Children: make([]*model.FlamegraphSpan, 0),}@@ -1160,6 +1184,7 @@ func (r *ClickHouseReader) GetFlamegraphSpansForTrace(ctx context.Context, orgIDTimeUnixNano: spanNode.TimeUnixNano,DurationNano: spanNode.DurationNano,HasError: false,+ Events: make([]model.Event, 0),Children: make([]*model.FlamegraphSpan, 0),}missingSpan.Children = append(missingSpan.Children, spanNode)diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.goindex cf8eb47886..63711c8f7c 100644--- a/pkg/query-service/app/http_handler.go+++ b/pkg/query-service/app/http_handler.go@@ -1787,7 +1787,7 @@ func (aH *APIHandler) GetWaterfallSpansForTraceWithMetadata(w http.ResponseWriteresult, apiErr := aH.reader.GetWaterfallSpansForTraceWithMetadata(r.Context(), orgID, traceID, req)if apiErr != nil {- RespondError(w, apiErr, nil)+ render.Error(w, apiErr)return}@@ -1821,7 +1821,7 @@ func (aH *APIHandler) GetFlamegraphSpansForTrace(w http.ResponseWriter, r *http.result, apiErr := aH.reader.GetFlamegraphSpansForTrace(r.Context(), orgID, traceID, req)if apiErr != nil {- RespondError(w, apiErr, nil)+ render.Error(w, apiErr)return}diff --git a/pkg/query-service/interfaces/interface.go b/pkg/query-service/interfaces/interface.goindex f57ccc3b70..7a5ae50072 100644--- a/pkg/query-service/interfaces/interface.go+++ b/pkg/query-service/interfaces/interface.go@@ -42,8 +42,8 @@ type Reader interface {// Search InterfacesSearchTraces(ctx context.Context, params *model.SearchTracesParams) (*[]model.SearchSpansResult, error)- GetWaterfallSpansForTraceWithMetadata(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetWaterfallSpansForTraceWithMetadataParams) (*model.GetWaterfallSpansForTraceWithMetadataResponse, *model.ApiError)- GetFlamegraphSpansForTrace(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetFlamegraphSpansForTraceParams) (*model.GetFlamegraphSpansForTraceResponse, *model.ApiError)+ GetWaterfallSpansForTraceWithMetadata(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetWaterfallSpansForTraceWithMetadataParams) (*model.GetWaterfallSpansForTraceWithMetadataResponse, error)+ GetFlamegraphSpansForTrace(ctx context.Context, orgID valuer.UUID, traceID string, req *model.GetFlamegraphSpansForTraceParams) (*model.GetFlamegraphSpansForTraceResponse, error)// Setter InterfacesSetTTL(ctx context.Context, orgID string, ttlParams *model.TTLParams) (*model.SetTTLResponseItem, *model.ApiError)diff --git a/pkg/query-service/model/response.go b/pkg/query-service/model/response.goindex b54c85572c..18a23cedc8 100644--- a/pkg/query-service/model/response.go+++ b/pkg/query-service/model/response.go@@ -288,7 +288,7 @@ type Span struct {Name string `json:"name"`References []OtelSpanRef `json:"references,omitempty"`TagMap map[string]string `json:"tagMap"`- Events []string `json:"event"`+ Events []Event `json:"event"`RootName string `json:"rootName"`StatusMessage string `json:"statusMessage"`StatusCodeString string `json:"statusCodeString"`@@ -311,6 +311,7 @@ type FlamegraphSpan struct {ServiceName string `json:"serviceName"`Name string `json:"name"`Level int64 `json:"level"`+ Events []Event `json:"event"`References []OtelSpanRef `json:"references,omitempty"`Children []*FlamegraphSpan `json:"children"`}