Skip to content

Commit

Permalink
skip contextLinesProvider without sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Aug 21, 2024
1 parent 0ec320d commit 2881819
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-rivers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/overlay': patch
---

fix(overlay): Skip contextLines lookup if sidecar is empty
36 changes: 21 additions & 15 deletions packages/overlay/src/integrations/sentry/data/sentryDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SentryDataCache {

protected subscribers: Map<string, Subscription> = new Map();

protected contextLinesProvider: string = new URL(DEFAULT_SIDECAR_URL).origin + CONTEXT_LINES_ENDPOINT;
protected contextLinesProvider: string | null = new URL(DEFAULT_SIDECAR_URL).origin + CONTEXT_LINES_ENDPOINT;

constructor(
initial: (SentryEvent & {
Expand All @@ -45,6 +45,10 @@ class SentryDataCache {
}

setSidecarUrl(url: string) {
if (!url) {
this.contextLinesProvider = null;
}

const { origin } = new URL(url);
this.contextLinesProvider = origin + CONTEXT_LINES_ENDPOINT;
}
Expand Down Expand Up @@ -295,21 +299,23 @@ class SentryDataCache {
}
exception.stacktrace.frames.reverse();

try {
const makeFetch = getNativeFetchImplementation();
const stackTraceWithContextResponse = await makeFetch(this.contextLinesProvider, {
method: 'PUT',
body: JSON.stringify(exception.stacktrace),
});

if (!stackTraceWithContextResponse.ok || stackTraceWithContextResponse.status !== 200) {
return;
if (this.contextLinesProvider) {
try {
const makeFetch = getNativeFetchImplementation();
const stackTraceWithContextResponse = await makeFetch(this.contextLinesProvider, {
method: 'PUT',
body: JSON.stringify(exception.stacktrace),
});

if (!stackTraceWithContextResponse.ok || stackTraceWithContextResponse.status !== 200) {
return;
}

const stackTraceWithContext = await stackTraceWithContextResponse.json();
exception.stacktrace = stackTraceWithContext;
} catch {
// Something went wrong, for now we just ignore it.
}

const stackTraceWithContext = await stackTraceWithContextResponse.json();
exception.stacktrace = stackTraceWithContext;
} catch {
// Something went wrong, for now we just ignore it.
}
}),
);
Expand Down

0 comments on commit 2881819

Please sign in to comment.