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

fix: no sentry DSN #27272

Merged
merged 2 commits into from
Sep 19, 2024
Merged
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
47 changes: 44 additions & 3 deletions shared/lib/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function traceCallback<T>(request: TraceRequest, fn: TraceCallback<T>): T {
};

return startSpan(request, (spanOptions) =>
globalThis.sentry.startSpan(spanOptions, callback),
sentryStartSpan(spanOptions, callback),
);
}

Expand All @@ -138,7 +138,7 @@ function startTrace(request: TraceRequest): TraceContext {
};

return startSpan(request, (spanOptions) =>
globalThis.sentry.startSpanManual(spanOptions, callback),
sentryStartSpanManual(spanOptions, callback),
);
}

Expand All @@ -157,7 +157,7 @@ function startSpan<T>(
startTime,
};

return globalThis.sentry.withIsolationScope((scope: Sentry.Scope) => {
return sentryWithIsolationScope((scope: Sentry.Scope) => {
scope.setTags(tags as Record<string, Primitive>);

return callback(spanOptions);
Expand Down Expand Up @@ -207,3 +207,44 @@ function tryCatchMaybePromise<T>(

return undefined;
}

function sentryStartSpan<T>(
spanOptions: StartSpanOptions,
callback: (span: Sentry.Span | null) => T,
): T {
const actual = globalThis.sentry?.startSpan;

if (!actual) {
return callback(null);
}

return actual(spanOptions, callback);
}

function sentryStartSpanManual<T>(
spanOptions: StartSpanOptions,
callback: (span: Sentry.Span | null) => T,
): T {
const actual = globalThis.sentry?.startSpanManual;

if (!actual) {
return callback(null);
}

return actual(spanOptions, callback);
}

function sentryWithIsolationScope<T>(callback: (scope: Sentry.Scope) => T): T {
const actual = globalThis.sentry?.withIsolationScope;

if (!actual) {
const scope = {
// eslint-disable-next-line no-empty-function
setTags: () => {},
} as unknown as Sentry.Scope;

return callback(scope);
}

return actual(callback);
}