-
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
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-scanDirectorysrc/lib/dsn/project-root.ts-withFsSpan,findProjectRoot- Any other files with similar Sentry span patterns
References
- PR feat(dsn): add project root detection for automatic DSN discovery #159 review comment requesting this improvement
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels