-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add logs table row buttons (filters, copy as json etc.) #97545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
57328fe
254b151
45bf302
ef87a9e
76dd8f4
550569f
4d4897f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,19 @@ import type {ComponentProps, SyntheticEvent} from 'react'; | |
import {Fragment, memo, useCallback, useLayoutEffect, useRef, useState} from 'react'; | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {Button} from 'sentry/components/core/button'; | ||
import {EmptyStreamWrapper} from 'sentry/components/emptyStateWarning'; | ||
import LoadingIndicator from 'sentry/components/loadingIndicator'; | ||
import {IconWarning} from 'sentry/icons'; | ||
import {IconAdd, IconJson, IconSubtract, IconWarning} from 'sentry/icons'; | ||
import {IconChevron} from 'sentry/icons/iconChevron'; | ||
import {t} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
import {defined} from 'sentry/utils'; | ||
import {trackAnalytics} from 'sentry/utils/analytics'; | ||
import type {TableDataRow} from 'sentry/utils/discover/discoverQuery'; | ||
import type {EventsMetaType} from 'sentry/utils/discover/eventView'; | ||
import {FieldValueType} from 'sentry/utils/fields'; | ||
import useCopyToClipboard from 'sentry/utils/useCopyToClipboard'; | ||
import {useLocation} from 'sentry/utils/useLocation'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
import useProjectFromId from 'sentry/utils/useProjectFromId'; | ||
|
@@ -27,10 +30,9 @@ import { | |
useSetLogsAutoRefresh, | ||
} from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext'; | ||
import { | ||
useLogsAddSearchFilter, | ||
useLogsAnalyticsPageSource, | ||
useLogsFields, | ||
useLogsSearch, | ||
useSetLogsSearch, | ||
} from 'sentry/views/explore/contexts/logs/logsPageParams'; | ||
import { | ||
DEFAULT_TRACE_ITEM_HOVER_TIMEOUT, | ||
|
@@ -50,6 +52,8 @@ import { | |
DetailsWrapper, | ||
getLogColors, | ||
LogAttributeTreeWrapper, | ||
LogDetailTableActionsButtonBar, | ||
LogDetailTableActionsCell, | ||
LogDetailTableBodyCell, | ||
LogFirstCellContent, | ||
LogsTableBodyFirstCell, | ||
|
@@ -70,6 +74,7 @@ import { | |
adjustAliases, | ||
getLogRowItem, | ||
getLogSeverityLevel, | ||
ourlogToJson, | ||
} from 'sentry/views/explore/logs/utils'; | ||
|
||
type LogsRowProps = { | ||
|
@@ -123,8 +128,6 @@ export const LogRowContent = memo(function LogRowContent({ | |
const location = useLocation(); | ||
const organization = useOrganization(); | ||
const fields = useLogsFields(); | ||
const search = useLogsSearch(); | ||
const setLogsSearch = useSetLogsSearch(); | ||
const autorefreshEnabled = useLogsAutoRefreshEnabled(); | ||
const setAutorefresh = useSetLogsAutoRefresh(); | ||
const measureRef = useRef<HTMLTableRowElement>(null); | ||
|
@@ -185,22 +188,7 @@ export const LogRowContent = memo(function LogRowContent({ | |
} | ||
}, [isExpanded, onExpandHeight, dataRow]); | ||
|
||
const addSearchFilter = useCallback( | ||
({ | ||
key, | ||
value, | ||
negated, | ||
}: { | ||
key: string; | ||
value: string | number | boolean; | ||
negated?: boolean; | ||
}) => { | ||
const newSearch = search.copy(); | ||
newSearch.addFilterValue(`${negated ? '!' : ''}${key}`, String(value)); | ||
setLogsSearch(newSearch); | ||
}, | ||
[setLogsSearch, search] | ||
); | ||
const addSearchFilter = useLogsAddSearchFilter(); | ||
const theme = useTheme(); | ||
|
||
const severityNumber = dataRow[OurLogKnownFieldKey.SEVERITY_NUMBER]; | ||
|
@@ -380,6 +368,7 @@ function LogRowDetails({ | |
}) { | ||
const location = useLocation(); | ||
const organization = useOrganization(); | ||
const addSearchFilter = useLogsAddSearchFilter(); | ||
const project = useProjectFromId({ | ||
project_id: '' + dataRow[OurLogKnownFieldKey.PROJECT_ID], | ||
}); | ||
|
@@ -401,6 +390,19 @@ function LogRowDetails({ | |
enabled: !missingLogId, | ||
}); | ||
|
||
const {onClick: betterCopyToClipboard} = useCopyToClipboard({ | ||
text: isPending || isError ? '' : ourlogToJson(data), | ||
onCopy: () => { | ||
trackAnalytics('logs.table.row_copied_as_json', { | ||
log_id: String(dataRow[OurLogKnownFieldKey.ID]), | ||
organization, | ||
}); | ||
}, | ||
|
||
successMessage: t('Copied!'), | ||
errorMessage: t('Failed to copy'), | ||
}); | ||
|
||
const theme = useTheme(); | ||
const logColors = getLogColors(level, theme); | ||
const attributes = | ||
|
@@ -470,6 +472,62 @@ function LogRowDetails({ | |
</Fragment> | ||
)} | ||
</LogDetailTableBodyCell> | ||
{!isPending && data && ( | ||
<LogDetailTableActionsCell | ||
colSpan={colSpan} | ||
style={{ | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
flexDirection: 'row', | ||
}} | ||
> | ||
<LogDetailTableActionsButtonBar> | ||
<Button | ||
priority="link" | ||
size="sm" | ||
borderless | ||
onClick={() => { | ||
addSearchFilter({ | ||
key: OurLogKnownFieldKey.MESSAGE, | ||
value: dataRow[OurLogKnownFieldKey.MESSAGE], | ||
}); | ||
}} | ||
> | ||
<IconAdd size="md" style={{paddingRight: space(0.5)}} /> | ||
{t('Add to filter')} | ||
</Button> | ||
<Button | ||
priority="link" | ||
size="sm" | ||
borderless | ||
onClick={() => { | ||
addSearchFilter({ | ||
key: OurLogKnownFieldKey.MESSAGE, | ||
value: dataRow[OurLogKnownFieldKey.MESSAGE], | ||
negated: true, | ||
}); | ||
}} | ||
> | ||
<IconSubtract size="md" style={{paddingRight: space(0.5)}} /> | ||
{t('Exclude from filter')} | ||
</Button> | ||
</LogDetailTableActionsButtonBar> | ||
|
||
<LogDetailTableActionsButtonBar> | ||
<Button | ||
priority="link" | ||
size="sm" | ||
borderless | ||
onClick={() => { | ||
betterCopyToClipboard(); | ||
}} | ||
> | ||
<IconJson size="md" style={{paddingRight: space(0.5)}} /> | ||
{t('Copy as JSON')} | ||
</Button> | ||
</LogDetailTableActionsButtonBar> | ||
</LogDetailTableActionsCell> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Table Rendering Issues and Button CrashesThe expanded log row ( Additionally, clicking the "View Trace" button crashes for logs without a Finally, the |
||
</DetailsWrapper> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,12 @@ import { | |
import {LOGS_SORT_BYS_KEY} from 'sentry/views/explore/contexts/logs/sortBys'; | ||
import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode'; | ||
import {SavedQuery} from 'sentry/views/explore/hooks/useGetSavedQueries'; | ||
import type {TraceItemResponseAttribute} from 'sentry/views/explore/hooks/useTraceItemDetails'; | ||
import type { | ||
TraceItemDetailsResponse, | ||
TraceItemResponseAttribute, | ||
} from 'sentry/views/explore/hooks/useTraceItemDetails'; | ||
import { | ||
DeprecatedLogDetailFields, | ||
LogAttributesHumanLabel, | ||
LOGS_GRID_SCROLL_MIN_ITEM_THRESHOLD, | ||
} from 'sentry/views/explore/logs/constants'; | ||
|
@@ -445,3 +449,48 @@ export function getLogsUrlFromSavedQueryUrl({ | |
}, | ||
}); | ||
} | ||
|
||
export function ourlogToJson(ourlog: TraceItemDetailsResponse | undefined): string { | ||
if (!ourlog) { | ||
warn(fmt`cannot copy undefined ourlog`); | ||
return ''; | ||
} | ||
|
||
const copy: Record<string, string | number | boolean> = { | ||
...ourlog.attributes.reduce((it, {name, value}) => ({...it, [name]: value}), {}), | ||
id: ourlog.itemId, | ||
}; | ||
let warned = false; | ||
const warnAttributeOnce = (key: string) => { | ||
if (!warned) { | ||
warned = true; | ||
warn( | ||
fmt`Found sentry. prefix in ${key} while copying [project_id: ${copy.project_id ?? 'unknown'}, user_email: ${copy['user.email'] ?? 'unknown'}]` | ||
); | ||
} | ||
}; | ||
|
||
// Trimming any sentry. prefixes | ||
for (const key in copy) { | ||
if (DeprecatedLogDetailFields.includes(key)) { | ||
continue; | ||
} | ||
if (key.startsWith('sentry.')) { | ||
const value = copy[key]; | ||
if (value !== undefined) { | ||
warnAttributeOnce(key); | ||
delete copy[key]; | ||
copy[key.replace('sentry.', '')] = value; | ||
} | ||
} | ||
if (key.startsWith('tags[sentry.')) { | ||
const value = copy[key]; | ||
if (value !== undefined) { | ||
warnAttributeOnce(key); | ||
delete copy[key]; | ||
copy[key.replace('tags[sentry.', 'tags[')] = value; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Log Attribute Cleanup and PII Logging IssueThe |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Data Overwrite and Iteration IssuesThe
|
||
return JSON.stringify(copy, null, 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would user expect we return formatted json here? I'd just return Also this can throw, but I guess we can just rely on the error sentry captures to report back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: PII Leakage and Data Overwrite in JSON ConversionThe |
||
} |
Uh oh!
There was an error while loading. Please reload this page.