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(core): Finish spans when CLI commands fail #136

Merged
merged 1 commit into from
Nov 25, 2022
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
72 changes: 46 additions & 26 deletions packages/bundler-plugin-core/src/sentry/releasePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export async function createNewRelease(
): Promise<void> {
const span = addSpanToTransaction(ctx, "function.plugin.create_release");

await ctx.cli.releases.new(releaseName);
try {
await ctx.cli.releases.new(releaseName);
} finally {
span?.finish();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really need a top level span method...

}

ctx.logger.info("Successfully created release.");
span?.finish();
}

export async function cleanArtifacts(
Expand All @@ -36,10 +39,13 @@ export async function cleanArtifacts(

const span = addSpanToTransaction(ctx, "function.plugin.clean_artifacts");

await ctx.cli.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
try {
await ctx.cli.releases.execute(["releases", "files", releaseName, "delete", "--all"], true);
} finally {
span?.finish();
}
Comment on lines 40 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we put span onto the scope in addSpanToTransaction? In case we do, can we finish the span in the try/catch/finally that wraps the entire release creation pipeline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that before but it felt very blanket-approachy. I like this more because it is more explicit (though admittedly repetitive).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, was just a thought 😅


ctx.logger.info("Successfully cleaned previous artifacts.");
span?.finish();
}

export async function uploadSourceMaps(
Expand All @@ -52,10 +58,13 @@ export async function uploadSourceMaps(

// Since our internal include entries contain all top-level sourcemaps options,
// we only need to pass the include option here.
await ctx.cli.releases.uploadSourceMaps(releaseName, { include: options.include });
try {
await ctx.cli.releases.uploadSourceMaps(releaseName, { include: options.include });
} finally {
span?.finish();
}

ctx.logger.info("Successfully uploaded Sourcemaps.");
span?.finish();
}

export async function setCommits(
Expand All @@ -71,17 +80,21 @@ export async function setCommits(
const span = addSpanToTransaction(ctx, "function.plugin.set_commits");

const { auto, repo, commit, previousCommit, ignoreMissing, ignoreEmpty } = options.setCommits;
await ctx.cli.releases.setCommits(releaseName, {
commit,
previousCommit,
repo,
auto,
ignoreMissing,
ignoreEmpty,
});

try {
await ctx.cli.releases.setCommits(releaseName, {
commit,
previousCommit,
repo,
auto,
ignoreMissing,
ignoreEmpty,
});
} finally {
span?.finish();
}

ctx.logger.info("Successfully set commits.");
span?.finish();
}

export async function finalizeRelease(
Expand All @@ -96,10 +109,13 @@ export async function finalizeRelease(

const span = addSpanToTransaction(ctx, "function.plugin.finalize_release");

await ctx.cli.releases.finalize(releaseName);
try {
await ctx.cli.releases.finalize(releaseName);
} finally {
span?.finish();
}

ctx.logger.info("Successfully finalized release.");
span?.finish();
}

export async function addDeploy(
Expand All @@ -115,15 +131,19 @@ export async function addDeploy(
const span = addSpanToTransaction(ctx, "function.plugin.deploy");

const { env, started, finished, time, name, url } = options.deploy;
await ctx.cli.releases.newDeploy(releaseName, {
env,
started,
finished,
time,
name,
url,
});

try {
await ctx.cli.releases.newDeploy(releaseName, {
env,
started,
finished,
time,
name,
url,
});
} finally {
span?.finish();
}

ctx.logger.info("Successfully added deploy.");
span?.finish();
}