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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ A few operations send a query parameter by default to skip expensive work most c
| Operation | Default | Effect |
| --- | --- | --- |
| `getOrganizationIssueEvent` | `collapse: ["adjacentEvents"]` | Skips the next/previous event lookups; `nextEventID` and `previousEventID` are `null` |
| `getProjectEvent` | `collapse: ["adjacentEvents"]` | Skips the next/previous event lookups; `nextEventID` and `previousEventID` are `null` |

The default applies only when the parameter is omitted or `undefined`. Any value you pass replaces it, and an empty list sends nothing:

Expand Down
17 changes: 11 additions & 6 deletions lib/query-defaults.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
*/
import ts from "typescript";

// Skips the next/previous-event Snuba queries. No known SDK consumer reads the
// adjacent IDs; pass `collapse: []` to get them.
const SKIP_ADJACENT_EVENTS = {
query: { collapse: ["adjacentEvents"] },
effect: "skips looking up the neighboring events (`nextEventID` and `previousEventID` are `null`)",
};

/**
* Keyed by `${METHOD} ${path}`. Each value must be in the parameter's enum.
* `effect` completes "By default, the SDK sends `…`, which …" in the JSDoc.
*/
export const QUERY_DEFAULTS = new Map([
// getsentry/sentry#129094: skips the next/previous-event Snuba queries. No
// known SDK consumer reads the adjacent IDs; pass `collapse: []` to get them.
["GET /api/0/organizations/{organization_id_or_slug}/issues/{issue_id}/events/{event_id}/", {
query: { collapse: ["adjacentEvents"] },
effect: "skips looking up the neighboring events (`nextEventID` and `previousEventID` are `null`)",
}],
// getsentry/sentry#129094
["GET /api/0/organizations/{organization_id_or_slug}/issues/{issue_id}/events/{event_id}/", SKIP_ADJACENT_EVENTS],
// getsentry/sentry#129123
["GET /api/0/projects/{organization_id_or_slug}/{project_id_or_slug}/events/{event_id}/", SKIP_ADJACENT_EVENTS],
]);

/** Fail the build when the schema no longer documents a configured default. */
Expand Down
7 changes: 7 additions & 0 deletions test/client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ async function operationArguments(sentry: SentryClient) {
await sentry.getOrganizationIssueEvent({ ...event, query: { collapse: [] } });
// @ts-expect-error Query defaults do not widen the documented enum.
await sentry.getOrganizationIssueEvent({ ...event, query: { collapse: ["everything"] } });
const projectEvent = {
path: { organization_id_or_slug: "example", project_id_or_slug: "example", event_id: "a".repeat(32) },
};
await sentry.getProjectEvent(projectEvent);
await sentry.getProjectEvent({ ...projectEvent, query: { collapse: [] } });
// @ts-expect-error Query defaults do not widen the documented enum.
await sentry.getProjectEvent({ ...projectEvent, query: { collapse: ["everything"] } });
}

async function responseAndThrowingTypes(sentry: SentryClient, throwOnError: boolean) {
Expand Down
28 changes: 24 additions & 4 deletions test/query-defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { describe, expect, test } from "bun:test";
import {
createSentryClient,
getOrganizationIssueEvent,
getProjectEvent,
narrowError_getOrganizationIssueEvent,
narrowError_getProjectEvent,
type Config,
type GetOrganizationIssueEventQueryCollapse,
} from "@sentry/api";
Expand All @@ -22,6 +24,9 @@ function recordingClient() {
}

const event = { path: { organization_id_or_slug: "org", issue_id: "1", event_id: "latest" as const } };
const projectEvent = {
path: { organization_id_or_slug: "org", project_id_or_slug: "project", event_id: "a".repeat(32) },
};
// The server also honors values the schema does not document yet, such as
// fullRelease. JavaScript callers can pass them; TypeScript callers need a cast.
const fullRelease = "fullRelease" as GetOrganizationIssueEventQueryCollapse;
Expand All @@ -47,6 +52,24 @@ describe("client-side query defaults", () => {
]);
});

test("skips adjacent-event lookups on project events unless the caller sets collapse", async () => {
const { queries, fetch, sentry } = recordingClient();

await sentry.getProjectEvent(projectEvent);
await sentry.getProjectEvent({ ...projectEvent, query: { environment: ["prod"] } });
await getProjectEvent({ ...projectEvent, baseUrl: "https://example.test", fetch });
await narrowError_getProjectEvent({ ...projectEvent, client: sentry.client });
await sentry.getProjectEvent({ ...projectEvent, query: { collapse: [] } });

expect(queries).toEqual([
"?collapse=adjacentEvents",
"?environment=prod&collapse=adjacentEvents",
"?collapse=adjacentEvents",
"?collapse=adjacentEvents",
"",
]);
});

test("lets callers replace, combine, or opt out of the default", async () => {
const { queries, sentry } = recordingClient();
const query = { collapse: [] as GetOrganizationIssueEventQueryCollapse[], environment: ["prod"] };
Expand All @@ -67,13 +90,10 @@ describe("client-side query defaults", () => {
test("leaves other operations unchanged", async () => {
const { queries, sentry } = recordingClient();

await sentry.getProjectEvent({
path: { organization_id_or_slug: "org", project_id_or_slug: "project", event_id: "a".repeat(32) },
});
await sentry.listOrganizationIssueEvents({ path: { organization_id_or_slug: "org", issue_id: "1" } });
await sentry.listOrganizations({ query: { owner: true } });

expect(queries).toEqual(["", "", "?owner=true"]);
expect(queries).toEqual(["", "?owner=true"]);
});
});

Expand Down
Loading