Summary
Add a withTelemetry helper function to reduce boilerplate code when wrapping functions with Sentry spans.
Motivation
Currently, Sentry span instrumentation requires verbose boilerplate:
function myFunction(arg: string): Promise<Result> {
return Sentry.startSpan(
{
name: "myFunction",
op: "some.operation",
attributes: { "some.attr": arg },
onlyIfParent: true,
},
async (span) => {
try {
const result = await doWork(arg);
span.setStatus({ code: 1 });
return result;
} catch (error) {
span.setStatus({ code: 2 });
throw error;
}
}
);
}
Proposed Solution
Create a helper similar to Spotlight's withTelemetry:
function withTelemetry<T>(
name: string,
op: string,
fn: () => T | Promise<T>,
attributes?: Record<string, string | number | boolean>
): Promise<T> {
return Sentry.startSpan(
{ name, op, attributes, onlyIfParent: true },
async (span) => {
try {
const result = await fn();
span.setStatus({ code: 1 });
return result;
} catch (error) {
span.setStatus({ code: 2 });
throw error;
}
}
);
}
Files to Update
src/lib/dsn/code-scanner.ts - scanDirectory
src/lib/dsn/project-root.ts - withFsSpan, findProjectRoot
- Any other files with similar Sentry span patterns
References
Summary
Add a
withTelemetryhelper function to reduce boilerplate code when wrapping functions with Sentry spans.Motivation
Currently, Sentry span instrumentation requires verbose boilerplate:
Proposed Solution
Create a helper similar to Spotlight's withTelemetry:
Files to Update
src/lib/dsn/code-scanner.ts-scanDirectorysrc/lib/dsn/project-root.ts-withFsSpan,findProjectRootReferences