Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions plugins/sentry-cli/skills/sentry-cli/references/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Start the local dev server and tail events
- `-q, --quiet - Suppress per-envelope tail output`
- `-f, --filter <value>... - Only show items of this type (repeatable: error, transaction, log, ai)`
- `-F, --format <value> - Output format: human (default) or json (NDJSON) - (default: "human")`
- `-a, --attributes - Show a grouped attribute table (user vs SDK) under each transaction`

### `sentry local run <command...>`

Expand Down
38 changes: 32 additions & 6 deletions src/commands/local/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type LocalFlags = {
readonly quiet: boolean;
readonly filter: FilterValue[];
readonly format: FormatValue;
readonly attributes: boolean;
};

/**
Expand Down Expand Up @@ -407,6 +408,7 @@ type ConsumeSSEOptions = {
signal: AbortSignal;
quiet?: boolean;
useJson?: boolean;
showAttributes?: boolean;
};

/** Check whether an error is an abort signal. */
Expand Down Expand Up @@ -438,7 +440,14 @@ async function sleepUnlessAborted(
* using `Last-Event-ID` to resume from where the stream left off.
*/
async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
const { url, activeFilters, signal, quiet = false, useJson = false } = opts;
const {
url,
activeFilters,
signal,
quiet = false,
useJson = false,
showAttributes = false,
} = opts;
let lastEventId: string | undefined;
let retries = 0;
let retryDelay = SSE_INITIAL_RETRY_MS;
Expand All @@ -451,6 +460,7 @@ async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
signal,
quiet,
useJson,
showAttributes,
lastEventId,
onId: (id) => {
lastEventId = id;
Expand Down Expand Up @@ -528,6 +538,7 @@ type ConsumeSSEOnceOptions = {
signal: AbortSignal;
quiet: boolean;
useJson: boolean;
showAttributes: boolean;
lastEventId: string | undefined;
onId: (id: string) => void;
/** Called when the HTTP response is received (200 OK with body). */
Expand All @@ -546,6 +557,7 @@ async function consumeSSEOnce(opts: ConsumeSSEOnceOptions): Promise<boolean> {
signal,
quiet,
useJson,
showAttributes,
lastEventId,
onId,
onConnected,
Expand Down Expand Up @@ -582,7 +594,7 @@ async function consumeSSEOnce(opts: ConsumeSSEOnceOptions): Promise<boolean> {
onId(id);
}
if (type === SENTRY_CONTENT_TYPE) {
processSSEEvent(data, activeFilters, useJson);
processSSEEvent(data, activeFilters, useJson, showAttributes);
}
};

Expand All @@ -606,7 +618,8 @@ async function consumeSSEOnce(opts: ConsumeSSEOnceOptions): Promise<boolean> {
function processSSEEvent(
data: string,
activeFilters: ReadonlySet<FilterValue>,
useJson = false
useJson = false,
showAttributes = false
): void {
try {
const envelope = JSON.parse(data) as [
Expand All @@ -620,12 +633,13 @@ function processSSEEvent(
continue;
}
const lines = useJson
? formatItemJson(itemHeader.type, payload, header)
? formatItemJson(itemHeader.type, payload, header, showAttributes)
: formatItem(
itemHeader.type,
payload,
header,
itemHeader.type ?? "envelope"
itemHeader.type ?? "envelope",
showAttributes
);
for (const line of lines) {
logger.log(line);
Expand Down Expand Up @@ -682,13 +696,20 @@ export const serverCommand = buildCommand({
brief: "Output format: human (default) or json (NDJSON)",
default: "human",
},
attributes: {
kind: "boolean",
brief:
"Show a grouped attribute table (user vs SDK) under each transaction",
default: false,
},
},
aliases: {
p: "port",
H: "host",
q: "quiet",
f: "filter",
F: "format",
a: "attributes",
},
},
auth: false,
Expand All @@ -715,6 +736,7 @@ export const serverCommand = buildCommand({
signal: ac.signal,
quiet: flags.quiet,
useJson: flags.format === "json",
showAttributes: flags.attributes,
});
} catch (err: unknown) {
if (!(err instanceof DOMException && err.name === "AbortError")) {
Expand All @@ -735,7 +757,11 @@ export const serverCommand = buildCommand({
const formatFn = useJson ? formatEnvelopeLinesJson : formatEnvelopeLines;
buffer.subscribe((container) => {
try {
for (const line of formatFn(container, activeFilters)) {
for (const line of formatFn(
container,
activeFilters,
flags.attributes
)) {
logger.log(line);
}
} catch (err) {
Expand Down
Loading
Loading