Skip to content

Commit

Permalink
Traces: link to related resources (#7700)
Browse files Browse the repository at this point in the history
## Summary
Allow users to see the related session, errors, and logs with a trace
from the trace view. These buttons will link the user to the page with
the correct filter, but the user can also view errors and logs in the
tabs below (for now). These tabs are planned to be removed in exchange
for side panel views.

## How did you test this change?
1) View the traces and click on a traces
- [ ] View errors button is disabled if no errors
- [ ] Clicking view errors button links to errors page with correct
filters
- [ ] View session button is disabled if no session
- [ ] Clicking view session button links to session with correct
absolute time
- [ ] View logs is enabled
- [ ] Clicking on view logs button links to logs page with correct
filters


https://www.loom.com/share/217973d784c748a198151ff7d0dbfdfa?sid=50831ec3-3e35-43c1-9b71-c59d87a05a92

## Are there any deployment considerations?
N/A

## Does this work require review from our design team?
N/A
  • Loading branch information
SpennyNDaJets committed Feb 13, 2024
1 parent 9ec938d commit b96a82d
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 58 deletions.
96 changes: 51 additions & 45 deletions frontend/src/__generated/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// src/pages/Traces/RelatedResourceButtons/style.css.ts
var tagLink = "_1fmffum0";
export {
tagLink
};
129 changes: 129 additions & 0 deletions frontend/src/pages/Traces/RelatedResourceButtons/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {
Box,
IconSolidLightningBolt,
IconSolidLogs,
IconSolidPlayCircle,
Tag,
} from '@highlight-run/ui/components'
import moment from 'moment'
import { createSearchParams } from 'react-router-dom'

import { Link } from '@/components/Link'
import { useProjectId } from '@/hooks/useProjectId'

import * as styles from './style.css'

const TAG_PROPS = {
size: 'medium',
kind: 'secondary',
emphasis: 'medium',
} as const

type Props = {
traceId?: string
secureSessionId?: string
disableErrors: boolean
startDate: Date
endDate: Date
}

const getErrorsLink = (
projectId: string,
traceId: string,
startDate: Date,
endDate: Date,
) => {
const params = createSearchParams({
query: `and||error-field_trace_id,is,${traceId}`,
start_date: moment(startDate).subtract(5, 'minutes').toISOString(),
end_date: moment(endDate).add(5, 'minutes').toISOString(),
})

return `/${projectId}/errors?${params}`
}

const getSessionLink = (
projectId: string,
secureSessionId: string,
startDate: Date,
) => {
const params = createSearchParams({
tsAbs: startDate.toISOString(),
})

return `/${projectId}/sessions/${secureSessionId}?${params}`
}

const getLogsLink = (
projectId: string,
traceId: string,
startDate: Date,
endDate: Date,
) => {
const params = createSearchParams({
query: `trace_id=${traceId}`,
start_date: moment(startDate).subtract(5, 'minutes').toISOString(),
end_date: moment(endDate).add(5, 'minutes').toISOString(),
})

return `/${projectId}/logs?${params}`
}

export const RelatedResourceButtons: React.FC<Props> = ({
traceId,
secureSessionId,
disableErrors,
startDate,
endDate,
}) => {
const { projectId } = useProjectId()
const errorLinkDisabled = !traceId || disableErrors
const sessionLinkDisabled = !traceId || !secureSessionId
const logsLinkDisabled = !traceId

const errorLink = errorLinkDisabled
? ''
: getErrorsLink(projectId, traceId, startDate, endDate)
const sessionLink = sessionLinkDisabled
? ''
: getSessionLink(projectId, secureSessionId, startDate)

const logsLink = logsLinkDisabled
? ''
: getLogsLink(projectId, traceId, startDate, endDate)

return (
<Box>
<Link to={errorLink} className={styles.tagLink} reloadDocument>
<Tag
{...TAG_PROPS}
shape="leftBasic"
iconLeft={<IconSolidLightningBolt />}
disabled={errorLinkDisabled}
>
View errors
</Tag>
</Link>
<Link to={sessionLink} className={styles.tagLink}>
<Tag
{...TAG_PROPS}
shape="square"
iconLeft={<IconSolidPlayCircle />}
disabled={sessionLinkDisabled}
>
View session
</Tag>
</Link>
<Link to={logsLink} className={styles.tagLink}>
<Tag
{...TAG_PROPS}
shape="rightBasic"
iconLeft={<IconSolidLogs />}
disabled={logsLinkDisabled}
>
View logs
</Tag>
</Link>
</Box>
)
}
11 changes: 11 additions & 0 deletions frontend/src/pages/Traces/RelatedResourceButtons/style.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { globalStyle, style } from '@vanilla-extract/css'

export const tagLink = style({})

globalStyle(`${tagLink}:first-of-type > button`, {
borderRight: 'none',
})

globalStyle(`${tagLink}:last-of-type > button`, {
borderLeft: 'none',
})
Loading

0 comments on commit b96a82d

Please sign in to comment.