Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(logs): match related errors on span and trace (#115339)

Jon McCallumef49a18a3e3b
diff --git a/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx b/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx
index 81e2647767d0..49891582dc9a 100644
--- a/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx
@@ -58,7 +58,8 @@ interface LogDetailsModalProps {
}
export function LogDetailsModal({ timezone }: LogDetailsModalProps): JSX.Element | null {
- const { isLogDetailsOpen, selectedLog, jsonParseAllFields, activeTab, sessionId } = useValues(logDetailsModalLogic)
+ const { isLogDetailsOpen, selectedLog, jsonParseAllFields, activeTab, sessionId, relatedErrorsInitialScope } =
+ useValues(logDetailsModalLogic)
const { closeLogDetails, setJsonParseAllFields, setActiveTab } = useActions(logDetailsModalLogic)
const { addFilter, copyLinkToLog } = useActions(logsViewerLogic)
@@ -199,9 +200,9 @@ export function LogDetailsModal({ timezone }: LogDetailsModalProps): JSX.Element
label: 'Related errors',
content: (
<RelatedErrorsTab
- logUuid={selectedLog.uuid}
- logTimestamp={selectedLog.timestamp}
+ log={selectedLog}
sessionId={sessionId}
+ initialScope={relatedErrorsInitialScope}
/>
),
},
diff --git a/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/RelatedErrorsTab.tsx b/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/RelatedErrorsTab.tsx
index 696181340c35..1dae89195678 100644
--- a/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/RelatedErrorsTab.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/RelatedErrorsTab.tsx
@@ -1,103 +1,124 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { LemonBanner, LemonSkeleton } from '@posthog/lemon-ui'
+import { LemonSegmentedButton } from '@posthog/lemon-ui'
import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'
-import { pluralize } from 'lib/utils/strings'
-import { MaxErrorTrackingIssuePreview } from '~/queries/schema/schema-assistant-error-tracking'
-
-import { ErrorTrackingIssueCard } from 'products/error_tracking/frontend/ErrorTrackingIssueCard'
+import { ParsedLogMessage } from 'products/logs/frontend/types'
+import { parseLogTimestamp } from 'products/logs/frontend/utils'
+import { ErrorIssuesList } from 'products/tracing/frontend/components/TraceDrawer/ErrorIssuesList'
+import {
+ TraceErrorsLogicProps,
+ TraceErrorsScope,
+ traceErrorsLogic,
+} from 'products/tracing/frontend/components/TraceDrawer/traceErrorsLogic'
+import { SESSION_ERRORS_WINDOW_HOURS } from 'products/tracing/frontend/errorCorrelation'
+
+const SCOPE_ORDER: TraceErrorsScope[] = ['span', 'trace', 'session']
+
+const SCOPES: Record<
+ TraceErrorsScope,
+ { label: string; where: string; emptyTitle: string; emptyBody: string; missingId: string }
+> = {
+ span: {
+ label: 'This span',
+ where: "in this log's span",
+ emptyTitle: 'No errors in this span',
+ emptyBody: "No exceptions reported this log's span as the place they were thrown.",
+ missingId: 'This log has no span ID',
+ },
+ trace: {
+ label: 'This trace',
+ where: "in this log's trace",
+ emptyTitle: 'No errors in this trace',
+ emptyBody: "No exceptions reported this log's trace as the request they happened in.",
+ missingId: 'This log has no trace ID',
+ },
+ session: {
+ label: 'This session',
+ where: 'in this session',
+ emptyTitle: 'No errors in this session',
+ emptyBody: `No exceptions were found in this session within ${SESSION_ERRORS_WINDOW_HOURS} hours of this log.`,
+ missingId: 'This log has no session ID. Add one to see errors from the same session.',
+ },
+}
-import { RelatedErrorsLogicProps, relatedErrorsLogic } from './relatedErrorsLogic'
+// A span ID is only unique inside its trace, so the span scope also needs the trace ID. A log with
+// a span ID and no trace ID must name the trace ID as the missing one.
+function missingIdReason(scope: TraceErrorsScope, availableScopes: TraceErrorsScope[]): string {
+ const missingScope = scope === 'span' && !availableScopes.includes('trace') ? 'trace' : scope
+ return SCOPES[missingScope].missingId
+}
export interface RelatedErrorsTabProps {
- logUuid: string
- logTimestamp: string
+ log: ParsedLogMessage
sessionId: string | null
+ initialScope: TraceErrorsScope | null
}
-export function RelatedErrorsTab({ logUuid, logTimestamp, sessionId }: RelatedErrorsTabProps): JSX.Element {
- if (!sessionId) {
- return (
- <div className="flex justify-center w-full py-8">
- <EmptyMessage
- title="No session ID found"
- description="To see related errors, link your logs to session replay by including a session ID."
- buttonText="Learn more"
- buttonTo="https://posthog.com/docs/logs/link-session-replay"
- size="small"
- />
- </div>
- )
+export function RelatedErrorsTab({ log, sessionId, initialScope }: RelatedErrorsTabProps): JSX.Element {
+ // Some pipelines send epoch timestamps, which the logic's window would read as an invalid date.
+ const timestamp = parseLogTimestamp(log.timestamp)
+ const logicProps: TraceErrorsLogicProps = {
+ traceId: log.trace_id,
+ spanId: log.span_id || null,
+ timestamp: timestamp.isValid() ? timestamp.toISOString() : null,
+ sessionId,
+ initialScope,
}
- const logicProps: RelatedErrorsLogicProps = { logUuid, logTimestamp, sessionId }
-
return (
- <BindLogic logic={relatedErrorsLogic} props={logicProps}>
+ <BindLogic logic={traceErrorsLogic} props={logicProps}>
<RelatedErrorsTabContent />
</BindLogic>
)
}
function RelatedErrorsTabContent(): JSX.Element {
- const { relatedIssues, relatedIssuesLoading, relatedIssuesError } = useValues(relatedErrorsLogic)
- const { loadRelatedIssues } = useActions(relatedErrorsLogic)
-
- if (relatedIssuesLoading) {
- return <LoadingState />
- }
+ const { issues, issuesLoading, issuesFailed, availableScopes, effectiveScope } = useValues(traceErrorsLogic)
+ const { loadIssues, setScope } = useActions(traceErrorsLogic)
- if (relatedIssuesError) {
+ if (!effectiveScope) {
return (
- <LemonBanner type="error" action={{ children: 'Retry', onClick: loadRelatedIssues }}>
- Failed to load related errors
- </LemonBanner>
+ <div className="flex justify-center w-full py-8">
+ <EmptyMessage
+ title="No trace or session ID found"
+ description="To see related errors, include a trace ID or link your logs to session replay with a session ID."
+ buttonText="Learn more"
+ buttonTo="https://posthog.com/docs/logs/link-session-replay"
+ size="small"
+ />
+ </div>
)
}
- if (relatedIssues.length === 0) {
- return <EmptyState />
- }
-
- return <RelatedIssuesList issues={relatedIssues} />
-}
-
-function LoadingState(): JSX.Element {
- return (
- <div className="flex flex-col gap-3">
- <LemonSkeleton className="h-16 w-full" />
- <LemonSkeleton className="h-16 w-full" />
- <LemonSkeleton className="h-16 w-full" />
- </div>
- )
-}
-
-function EmptyState(): JSX.Element {
- return (
- <EmptyMessage
- title="No related errors"
- description="No exceptions were found in this session within 6 hours of this log."
- size="small"
- />
- )
-}
-
-interface RelatedIssuesListProps {
- issues: MaxErrorTrackingIssuePreview[]
-}
-
-function RelatedIssuesList({ issues }: RelatedIssuesListProps): JSX.Element {
- const totalOccurrences = issues.reduce((sum, issue) => sum + issue.occurrences, 0)
return (
- <div className="flex flex-col">
- <p className="text-muted text-sm mb-2">
- {pluralize(issues.length, 'issue')} with {pluralize(totalOccurrences, 'occurrence')} in this session
- </p>
- {issues.map((issue) => (
- <ErrorTrackingIssueCard key={issue.id} issue={issue} showUserCount={false} />
- ))}
+ <div className="flex flex-col gap-2">
+ <div className="flex">
+ <LemonSegmentedButton
+ size="small"
+ value={effectiveScope}
+ onChange={(scope) => setScope(scope)}
+ options={SCOPE_ORDER.map((scope) => ({
+ value: scope,
+ label: SCOPES[scope].label,
+ disabledReason: availableScopes.includes(scope)
+ ? undefined
+ : missingIdReason(scope, availableScopes),
+ 'data-attr': `logs-related-errors-scope-${scope}`,
+ }))}
+ />
+ </div>
+ <ErrorIssuesList
+ issues={issues}
+ loading={issuesLoading}
+ failed={issuesFailed}
+ onRetry={loadIssues}
+ failedMessage="Failed to load related errors"
+ emptyTitle={SCOPES[effectiveScope].emptyTitle}
+ emptyDescription={SCOPES[effectiveScope].emptyBody}
+ where={SCOPES[effectiveScope].where}
+ />
</div>
)
}
diff --git a/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/relatedErrorsLogic.ts b/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/relatedErrorsLogic.ts
deleted file mode 100644
index a85070c87ee1..000000000000
--- a/products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/RelatedErrors/relatedErrorsLogic.ts
+++ /dev/null
@@ -1,140 +0,0 @@
-import { MakeLogicType, afterMount, kea, key, path, props, reducers } from 'kea'
-import { loaders } from 'kea-loaders'
-
-import api from 'lib/api'
-
-import { MaxErrorTrackingIssuePreview } from '~/queries/schema/schema-assistant-error-tracking'
-import { ErrorTrackingIssue, ErrorTrackingQuery, NodeKind } from '~/queries/schema/schema-general'
-import { FilterLogicalOperator, PropertyFilterType, PropertyOperator } from '~/types'
-
-import { RELATED_ERRORS_WINDOW_HOURS, parseLogTimestamp } from 'products/logs/frontend/utils'
-
-export interface RelatedErrorsLogicProps {
- logUuid: string
- logTimestamp: string
- sessionId: string
-}
-
-// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
-export interface relatedErrorsLogicValues {
- relatedIssues: MaxErrorTrackingIssuePreview[]
- relatedIssuesError: string | null
- relatedIssuesLoading: boolean
-}
-
-// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
-export interface relatedErrorsLogicActions {
- loadRelatedIssues: () => any
- loadRelatedIssuesFailure: (
- error: string,
- errorObject?: any
- ) => {
- error: string
- errorObject?: any
- }
- loadRelatedIssuesSuccess: (
- relatedIssues: MaxErrorTrackingIssuePreview[],
- payload?: any
- ) => {
- relatedIssues: MaxErrorTrackingIssuePreview[]
- payload?: any
- }
-}
-
-// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
-export interface relatedErrorsLogicMeta {
- key: string
-}
-
-export type relatedErrorsLogicType = MakeLogicType<
- relatedErrorsLogicValues,
- relatedErrorsLogicActions,
- RelatedErrorsLogicProps,
- relatedErrorsLogicMeta
->
-
-export const relatedErrorsLogic = kea<relatedErrorsLogicType>([
- props({} as RelatedErrorsLogicProps),
- key((props) => props.logUuid),
- path((key) => [
- 'products',
- 'logs',
- 'frontend',
- 'components',
- 'LogsViewer',
- 'LogDetailsModal',
- 'Tabs',
- 'RelatedErrors',
- 'relatedErrorsLogic',
- key,
- ]),
-
- loaders(({ props }) => ({
- relatedIssues: {
- __default: [] as MaxErrorTrackingIssuePreview[],
- loadRelatedIssues: async (): Promise<MaxErrorTrackingIssuePreview[]> => {
- const timestamp = parseLogTimestamp(props.logTimestamp)
-
- const query: ErrorTrackingQuery = {
- kind: NodeKind.ErrorTrackingQuery,
- orderBy: 'last_seen',
- dateRange: {
- date_from: timestamp.subtract(RELATED_ERRORS_WINDOW_HOURS, 'hours').toISOString(),
- date_to: timestamp.add(RELATED_ERRORS_WINDOW_HOURS, 'hours').toISOString(),
- },
- filterGroup: {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: PropertyFilterType.Event,
- key: '$session_id',
- value: props.sessionId,
- operator: PropertyOperator.Exact,
- },
- ],
- },
- ],
- },
- volumeResolution: 0,
- withAggregations: true,
- limit: 100,
- }
-
- const response = await api.query(query)
- const issues = response.results as ErrorTrackingIssue[]
-
- return issues.map(
- (issue): MaxErrorTrackingIssuePreview => ({
- id: issue.id,
- name: issue.name,
- description: issue.description,
- library: issue.library,
- status: issue.status,
- occurrences: issue.aggregations?.occurrences ?? 0,
- sessions: issue.aggregations?.sessions ?? 0,
- users: issue.aggregations?.users ?? 0,
- first_seen: issue.first_seen,
- last_seen: issue.last_seen,
- })
- )
- },
- },
- })),
-
- reducers({
- relatedIssuesError: [
- null as string | null,
- {
- loadRelatedIssues: () => null,
- loadRelatedIssuesFailure: (_, { error }) => error || 'Failed to load related errors',
- },
- ],
- }),
-
- afterMount(({ actions }) => {
- actions.loadRelatedIssues()
- }),
-])
diff --git a/products/logs/frontend/components/LogsViewer/LogDetailsModal/logDetailsModalLogic.ts b/products/logs/frontend/components/LogsViewer/LogDetailsModal/logDetailsModalLogic.ts
index ec73347b5b26..c0833389ab1d 100644
--- a/products/logs/frontend/components/LogsViewer/LogDetailsModal/logDetailsModalLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/LogDetailsModal/logDetailsModalLogic.ts
@@ -5,6 +5,7 @@ import posthog from 'posthog-js'
import { logsConfigLogic } from 'products/logs/frontend/logsConfigLogic'
import { ParsedLogMessage } from 'products/logs/frontend/types'
import { getSessionIdFromLogAttributes } from 'products/logs/frontend/utils'
+import type { ErrorScope } from 'products/tracing/frontend/errorCorrelation'
export type LogDetailsTab = 'details' | 'raw' | 'explore-ai' | 'comments' | 'related-errors'
@@ -19,6 +20,7 @@ export interface logDetailsModalLogicValues {
hasSessionId: boolean
isLogDetailsOpen: boolean
jsonParseAllFields: boolean
+ relatedErrorsInitialScope: ErrorScope | null
selectedLog: ParsedLogMessage | null
sessionId: string | null
}
@@ -31,6 +33,13 @@ export interface logDetailsModalLogicActions {
openLogDetails: (log: ParsedLogMessage) => {
log: ParsedLogMessage
}
+ openLogRelatedErrors: (
+ log: ParsedLogMessage,
+ scope: ErrorScope
+ ) => {
+ log: ParsedLogMessage
+ scope: ErrorScope
+ }
setActiveTab: (tab: LogDetailsTab) => {
tab: LogDetailsTab
}
@@ -66,6 +75,7 @@ export const logDetailsModalLogic = kea<logDetailsModalLogicType>([
actions({
openLogDetails: (log: ParsedLogMessage) => ({ log }),
+ openLogRelatedErrors: (log: ParsedLogMessage, scope: ErrorScope) => ({ log, scope }),
closeLogDetails: true,
setJsonParseAllFields: (enabled: boolean) => ({ enabled }),
setActiveTab: (tab: LogDetailsTab) => ({ tab }),
@@ -75,6 +85,9 @@ export const logDetailsModalLogic = kea<logDetailsModalLogicType>([
setActiveTab: ({ tab }) => {
posthog.capture('logs details tab changed', { tab })
},
+ openLogRelatedErrors: () => {
+ posthog.capture('logs details tab changed', { tab: 'related-errors' })
+ },
})),
subscriptions(() => ({
@@ -90,6 +103,7 @@ export const logDetailsModalLogic = kea<logDetailsModalLogicType>([
null as ParsedLogMessage | null,
{
openLogDetails: (_, { log }) => log,
+ openLogRelatedErrors: (_, { log }) => log,
closeLogDetails: () => null,
},
],
@@ -97,6 +111,7 @@ export const logDetailsModalLogic = kea<logDetailsModalLogicType>([
false,
{
openLogDetails: () => true,
+ openLogRelatedErrors: () => true,
closeLogDetails: () => false,
},
],
@@ -106,10 +121,21 @@ export const logDetailsModalLogic = kea<logDetailsModalLogicType>([
setJsonParseAllFields: (_, { enabled }) => enabled,
},
],
+ relatedErrorsInitialScope: [
+ null as ErrorScope | null,
+ {
+ openLogRelatedErrors: (_, { scope }) => scope,
+ // Cleared once the user leaves the tab, so a remount does not undo a scope they picked.
+ setActiveTab: () => null,
+ openLogDetails: () => null,
+ closeLogDetails: () => null,
+ },
+ ],
activeTab: [
'details' as LogDetailsTab,
{
setActiveTab: (_, { tab }) => tab,
+ openLogRelatedErrors: () => 'related-errors',
openLogDetails: () => 'details',
closeLogDetails: () => 'details',
},
diff --git a/products/logs/frontend/components/VirtualizedLogsList/cells/SessionErrorsCell.tsx b/products/logs/frontend/components/VirtualizedLogsList/cells/SessionErrorsCell.tsx
index d182a18c9ad6..07cd522a513a 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/cells/SessionErrorsCell.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/cells/SessionErrorsCell.tsx
@@ -12,7 +12,7 @@ import { getSessionIdFromLogAttributes } from 'products/logs/frontend/utils'
// page as counts arrive.
export function SessionErrorsCell({ log }: { log: ParsedLogMessage }): JSX.Element {
const { sessionErrorCounts } = useValues(logsViewerLogic)
- const { openLogDetails, setActiveTab } = useActions(logDetailsModalLogic)
+ const { openLogRelatedErrors } = useActions(logDetailsModalLogic)
const { configuredSessionIdKeys } = useValues(logsConfigLogic)
const sessionId = getSessionIdFromLogAttributes(log.attributes, log.resource_attributes, configuredSessionIdKeys)
@@ -23,15 +23,7 @@ export function SessionErrorsCell({ log }: { log: ParsedLogMessage }): JSX.Eleme
return (
<div className="flex items-center justify-center shrink-0" style={{ width: SESSION_ERRORS_WIDTH }}>
{errorCount > 0 && (
- <SessionErrorsBadge
- errorCount={errorCount}
- onClick={() => {
- // openLogDetails resets the drawer to its Details tab, so the tab selection
- // has to follow it.
- openLogDetails(log)
- setActiveTab('related-errors')
- }}
- />
+ <SessionErrorsBadge errorCount={errorCount} onClick={() => openLogRelatedErrors(log, 'session')} />
)}
</div>
)
diff --git a/products/tracing/frontend/components/TraceDrawer/ErrorIssuesList.tsx b/products/tracing/frontend/components/TraceDrawer/ErrorIssuesList.tsx
new file mode 100644
index 000000000000..b66c91a3572c
--- /dev/null
+++ b/products/tracing/frontend/components/TraceDrawer/ErrorIssuesList.tsx
@@ -0,0 +1,67 @@
+import { LemonBanner, LemonSkeleton } from '@posthog/lemon-ui'
+
+import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'
+import { pluralize } from 'lib/utils/strings'
+
+import { MaxErrorTrackingIssuePreview } from '~/queries/schema/schema-assistant-error-tracking'
+
+import { ErrorTrackingIssueCard } from 'products/error_tracking/frontend/ErrorTrackingIssueCard'
+
+export interface ErrorIssuesListProps {
+ issues: MaxErrorTrackingIssuePreview[]
+ loading: boolean
+ failed: boolean
+ onRetry: () => void
+ failedMessage: string
+ emptyTitle: string
+ emptyDescription: string
+ /** Ends the summary line, for example "in this span". */
+ where: string
+}
+
+export function ErrorIssuesList({
+ issues,
+ loading,
+ failed,
+ onRetry,
+ failedMessage,
+ emptyTitle,
+ emptyDescription,
+ where,
+}: ErrorIssuesListProps): JSX.Element {
+ if (loading) {
+ return (
+ <div className="flex flex-col gap-3">
+ <LemonSkeleton className="h-16 w-full" repeat={3} />
+ </div>
+ )
+ }
+
+ if (failed) {
+ return (
+ <LemonBanner type="error" action={{ children: 'Retry', onClick: onRetry }}>
+ {failedMessage}
+ </LemonBanner>
+ )
+ }
+
+ if (issues.length === 0) {
+ return (
+ <div className="flex justify-center w-full py-8">
+ <EmptyMessage title={emptyTitle} description={emptyDescription} size="small" />
+ </div>
+ )
+ }
+
+ const totalOccurrences = issues.reduce((sum, issue) => sum + issue.occurrences, 0)
+ return (
+ <div className="flex flex-col">
+ <p className="text-muted text-sm mb-2">
+ {pluralize(issues.length, 'issue')} with {pluralize(totalOccurrences, 'occurrence')} {where}
+ </p>
+ {issues.map((issue) => (
+ <ErrorTrackingIssueCard key={issue.id} issue={issue} showUserCount={false} />
+ ))}
+ </div>
+ )
+}
diff --git a/products/tracing/frontend/components/TraceDrawer/TraceErrorsTab.tsx b/products/tracing/frontend/components/TraceDrawer/TraceErrorsTab.tsx
index a3466720b68d..8965590db3bd 100644
--- a/products/tracing/frontend/components/TraceDrawer/TraceErrorsTab.tsx
+++ b/products/tracing/frontend/components/TraceDrawer/TraceErrorsTab.tsx
@@ -1,16 +1,12 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { LemonBanner, LemonSegmentedButton, LemonSkeleton } from '@posthog/lemon-ui'
+import { LemonSegmentedButton, LemonSkeleton } from '@posthog/lemon-ui'
import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'
-import { pluralize } from 'lib/utils/strings'
-
-import { MaxErrorTrackingIssuePreview } from '~/queries/schema/schema-assistant-error-tracking'
-
-import { ErrorTrackingIssueCard } from 'products/error_tracking/frontend/ErrorTrackingIssueCard'
import { SESSION_ERRORS_WINDOW_HOURS } from '../../errorCorrelation'
import { TRACING_DOCS_URL } from '../../traceLinks'
+import { ErrorIssuesList } from './ErrorIssuesList'
import { TraceErrorsLogicProps, TraceErrorsScope, traceErrorsLogic } from './traceErrorsLogic'
// Every string a scope needs, so adding one is a single entry and the Record keeps it exhaustive.
@@ -107,64 +103,20 @@ function TraceErrorsTabContent(): JSX.Element {
/>
</div>
)}
- <TraceErrorsList
+ <ErrorIssuesList
issues={issues}
loading={issuesLoading}
failed={issuesFailed}
- scope={effectiveScope}
onRetry={loadIssues}
+ failedMessage="Could not load the errors for this trace."
+ emptyTitle={SCOPES[effectiveScope].emptyTitle}
+ emptyDescription={SCOPES[effectiveScope].emptyBody}
+ where={SCOPES[effectiveScope].where}
/>
</div>
)
}
-function TraceErrorsList({
- issues,
- loading,
- failed,
- scope,
- onRetry,
-}: {
- issues: MaxErrorTrackingIssuePreview[]
- loading: boolean
- failed: boolean
- scope: TraceErrorsScope
- onRetry: () => void
-}): JSX.Element {
- if (loading) {
- return <LoadingState />
- }
-
- if (failed) {
- return (
- <LemonBanner type="error" action={{ children: 'Retry', onClick: onRetry }}>
- Could not load the errors for this trace.
- </LemonBanner>
- )
- }
-
- if (issues.length === 0) {
- return (
- <div className="flex justify-center w-full py-8">
- <EmptyMessage title={SCOPES[scope].emptyTitle} description={SCOPES[scope].emptyBody} size="small" />
- </div>
- )
- }
-
- const totalOccurrences = issues.reduce((sum, issue) => sum + issue.occurrences, 0)
- return (
- <div className="flex flex-col">
- <p className="text-muted text-sm mb-2">
- {pluralize(issues.length, 'issue')} with {pluralize(totalOccurrences, 'occurrence')}{' '}
- {SCOPES[scope].where}
- </p>
- {issues.map((issue) => (
- <ErrorTrackingIssueCard key={issue.id} issue={issue} showUserCount={false} />
- ))}
- </div>
- )
-}
-
function LoadingState(): JSX.Element {
return (
<div className="flex flex-col gap-3">
diff --git a/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.test.ts b/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.test.ts
index c96e7d503cd9..fdad18d7f202 100644
--- a/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.test.ts
+++ b/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.test.ts
@@ -120,6 +120,26 @@ describe('traceErrorsLogic', () => {
expect(lastQuery().dateRange).toEqual({ date_from, date_to })
})
+ // A slow answer for the scope the user left must not replace the answer for the scope they picked.
+ it('keeps the issues of the current scope when an older scope answers last', async () => {
+ const pending: ((value: unknown) => void)[] = []
+ querySpy.mockImplementation(() => new Promise((resolve) => pending.push(resolve)))
+ const issue = (id: string): Record<string, unknown> => ({ id, name: id, aggregations: { occurrences: 1 } })
+
+ logic = traceErrorsLogic(ALL_IDS)
+ logic.mount()
+ logic.actions.setScope('session')
+ expect(pending).toHaveLength(2)
+
+ pending[1]({ results: [issue('session-issue')] })
+ pending[0]({ results: [issue('span-issue')] })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.effectiveScope).toBe('session')
+ expect(logic.values.issues.map((i) => i.id)).toEqual(['session-issue'])
+ expect(logic.values.issuesLoading).toBe(false)
+ })
+
it('asks nothing when the trace offers no scope', async () => {
await mount({ traceId: '', spanId: null, sessionId: null })
diff --git a/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.ts b/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.ts
index b2823d362b9c..72415c978bb1 100644
--- a/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.ts
+++ b/products/tracing/frontend/components/TraceDrawer/traceErrorsLogic.ts
@@ -44,7 +44,7 @@ export interface traceErrorsLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface traceErrorsLogicActions {
- loadIssues: () => any
+ loadIssues: (_: void) => void
loadIssuesFailure: (
error: string,
errorObject?: any
@@ -54,10 +54,10 @@ export interface traceErrorsLogicActions {
}
loadIssuesSuccess: (
issues: MaxErrorTrackingIssuePreview[],
- payload?: any
+ payload?: void
) => {
issues: MaxErrorTrackingIssuePreview[]
- payload?: any
+ payload?: void
}
setScope: (scope: TraceErrorsScope) => {
scope: ErrorScope
@@ -115,7 +115,7 @@ export const traceErrorsLogic = kea<traceErrorsLogicType>([
loaders(({ props, values }) => ({
issues: {
__default: [] as MaxErrorTrackingIssuePreview[],
- loadIssues: async (): Promise<MaxErrorTrackingIssuePreview[]> => {
+ loadIssues: async (_: void, breakpoint): Promise<MaxErrorTrackingIssuePreview[]> => {
const scope = values.effectiveScope
if (!scope) {
return []
@@ -164,6 +164,7 @@ export const traceErrorsLogic = kea<traceErrorsLogicType>([
}
const response = await api.query(query)
+ breakpoint()
return response.results.map(
(issue): MaxErrorTrackingIssuePreview => ({