Skip to content
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

feat: Add request and module details to context #544

Merged
merged 10 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/khaki-snails-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@spotlightjs/spotlight': minor
'@spotlightjs/overlay': minor
---

Add request and module details to context with JSONViewer
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dist-ssr
*.sln
*.sw?

.astro
.yalc
yalc.lock
.vite-inspect
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
73 changes: 73 additions & 0 deletions packages/overlay/src/components/JsonViewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { Envelope, EnvelopeItem } from '@sentry/types';
import ReactJson from 'react-json-view';
import type { RawEventContext } from '~/integrations/integration';

// Need this separately to fix Storybook 8 bundling
// See #419 and #420 for more context
const noop = () => {};

function shouldCollapse({ src, type }: { src: Array<unknown> | object; type: string }) {
if (type === 'object') return Object.keys(src).length > 10;
if (type === 'array') return (src as Array<unknown>).length > 10;
return false;
}

export default function JsonViewer({
data,
onUpdateData = noop,
editingEnabled = false,
clipboardEnabled = true,
displayDataTypes = false,
quotesOnKeys = false,
name = null,
collapseStringsAfterLength = 80,
}: {
data: Envelope[0] | EnvelopeItem | RawEventContext;
onUpdateData?: (value: unknown) => void;
editingEnabled?: boolean;
clipboardEnabled?: boolean;
displayDataTypes?: boolean;
quotesOnKeys?: boolean;
name?: string | null | false;
collapseStringsAfterLength?: number;
}) {
return (
<ReactJson
theme="bright"
displayDataTypes={displayDataTypes}
quotesOnKeys={quotesOnKeys}
shouldCollapse={shouldCollapse}
collapseStringsAfterLength={collapseStringsAfterLength}
name={name}
src={data}
enableClipboard={clipboardEnabled}
onEdit={
editingEnabled &&
(e => {
if (e.new_value === 'error') {
return false;
}
onUpdateData(e.updated_src);
})
}
onDelete={
editingEnabled &&
(e => {
if (e.new_value === 'error') {
return false;
}
onUpdateData(e.updated_src);
})
}
onAdd={
editingEnabled &&
(e => {
if (e.new_value === 'error') {
return false;
}
onUpdateData(e.updated_src);
})
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Envelope } from '@sentry/types';
import { useState } from 'react';
import type { RawEventContext } from '~/integrations/integration';
import SidePanel, { SidePanelHeader } from '~/ui/SidePanel';
import JsonViewer from './JsonViewer';
import JsonViewer from '../../../../components/JsonViewer';

export default function EnvelopeDetails({ data }: { data: { envelope: Envelope; rawEnvelope: RawEventContext } }) {
const [showRawJSON, setShowRawJSON] = useState<boolean>(false);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SentryEvent } from '../../types';
import JsonViewer from '../../../../components/JsonViewer';
import type { SentryEvent } from '../../types';
import Tags from '../Tags';

const EXAMPLE_CONTEXT = `Sentry.setContext("character", {
Expand All @@ -8,11 +9,18 @@ const EXAMPLE_CONTEXT = `Sentry.setContext("character", {
});`;

export default function EventContexts({ event }: { event: SentryEvent }) {
const contexts = { extra: event.extra, ...event.contexts };
const contextEntries = Object.entries({
request: event.request,
extra: {
modules: event.modules,
...(event.extra || {}),
},
...event.contexts,
}).filter(entry => entry[1]);

const tags = event.tags;
const { tags } = event;

if ((!contexts || !Object.values(contexts).some(v => v)) && !tags) {
if (contextEntries.length === 0 && !tags) {
return (
<div className="space-y-4 px-6">
<div className="text-primary-300">
Expand All @@ -31,29 +39,30 @@ export default function EventContexts({ event }: { event: SentryEvent }) {
</div>
)}
<div className="space-y-6">
{Object.entries(contexts).map(([ctxKey, ctxValues]) =>
ctxValues ? (
<div key={ctxKey}>
<h2 className="font-bold uppercase">{ctxKey}</h2>
<table className="w-full">
<tbody>
{Object.entries(ctxValues).map(([key, value]) => (
<tr key={key}>
{contextEntries.map(([ctxKey, ctxValues]) => (
<div key={ctxKey}>
<h2 className="font-bold uppercase">{ctxKey}</h2>
<table className="w-full">
<tbody>
{ctxValues &&
Object.entries(ctxValues).map(([key, value]) => (
<tr key={`${ctxKey}-${key}`}>
BYK marked this conversation as resolved.
Show resolved Hide resolved
<th className="text-primary-300 w-1/12 py-0.5 pr-4 text-left font-mono font-normal">
<div className="w-full truncate">{key}</div>
</th>
<td className="py-0.5">
<pre className="text-primary-300 whitespace-nowrap font-mono">
{JSON.stringify(value, undefined, 2)}
</pre>
{typeof value !== 'object' || !value ? (
<pre className="text-primary-300 whitespace-nowrap font-mono">value</pre>
) : (
BYK marked this conversation as resolved.
Show resolved Hide resolved
<JsonViewer key={`${ctxKey}-${key}`} data={value} />
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
) : null,
)}
</tbody>
</table>
</div>
))}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CardList from '../../../../components/CardList';
import TimeSince from '../../../../components/TimeSince';
import { useSentryEvents } from '../../data/useSentryEvents';
import { useSentryHelpers } from '../../data/useSentryHelpers';
import { SentryEvent } from '../../types';
import type { SentryEvent } from '../../types';
import HiddenItemsButton from '../HiddenItemsButton';
import PlatformIcon from '../PlatformIcon';
import { EventSummary } from './Event';
Expand Down
4 changes: 3 additions & 1 deletion packages/overlay/src/integrations/sentry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ type CommonEventAttrs = {
start_timestamp?: number;
contexts?: Contexts;
tags?: Tags;
extra?: { [key: string]: string | number };
extra?: Record<string, string | number>;
request?: Record<string, Record<string, string> | string>;
modules?: Record<string, string>;
sdk?: Sdk;
measurements?: Measurements;
};
Expand Down
Loading