Skip to content

Commit beb25ca

Browse files
committed
add op's to the spans
1 parent e73cfba commit beb25ca

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

packages/bundler-plugin-core/src/sentry/telemetry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ export function telemetryPlugin({
152152
"Sending telemetry data on issues and performance to Codecov. To disable telemetry, set `options.telemetry` to `false`.",
153153
);
154154
startSpan(
155-
{ name: "Codecov Bundler Plugin execution", scope: sentryScope },
155+
{
156+
name: "Codecov Bundler Plugin execution",
157+
op: "bundler-plugin-startup",
158+
scope: sentryScope,
159+
},
156160
() => {
157161
//
158162
},

packages/bundler-plugin-core/src/utils/Output.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ class Output {
163163
const inputs: ProviderUtilInputs = { envs, args };
164164

165165
const provider = await startSpan(
166-
{ name: "output.write.detectProvider", scope: this.sentryScope },
166+
{
167+
name: "Detect Provider",
168+
op: "output.write.detectProvider",
169+
scope: this.sentryScope,
170+
},
167171
async () => {
168172
let detectedProvider;
169173
try {
@@ -206,7 +210,8 @@ class Output {
206210

207211
const slug = provider.slug ?? "";
208212
const repoIndex = slug.lastIndexOf("/") + 1;
209-
const owner = slug.substring(0, repoIndex).trimEnd();
213+
// -1 to trim the trailing slash
214+
const owner = slug.substring(0, repoIndex - 1).trimEnd();
210215
if (owner.length > 0) {
211216
this.sentryScope.setTag("owner", owner);
212217
}
@@ -219,7 +224,11 @@ class Output {
219224

220225
let url = "";
221226
await startSpan(
222-
{ name: "output.write.getPreSignedURL", scope: this.sentryScope },
227+
{
228+
name: "Get Pre-Signed URL",
229+
op: "output.write.getPreSignedURL",
230+
scope: this.sentryScope,
231+
},
223232
async () => {
224233
try {
225234
url = await getPreSignedURL({
@@ -260,7 +269,11 @@ class Output {
260269
);
261270

262271
await startSpan(
263-
{ name: "output.write.uploadStats", scope: this.sentryScope },
272+
{
273+
name: "Upload Stats",
274+
op: "output.write.uploadStats",
275+
scope: this.sentryScope,
276+
},
264277
async () => {
265278
try {
266279
await uploadStats({

packages/bundler-plugin-core/src/utils/__tests__/Output.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,59 @@ describe("Output", () => {
431431
});
432432
});
433433

434+
describe("successful detection of provider", () => {
435+
it("sets the owner and repo tags", async () => {
436+
setup({});
437+
const sentryClient = {
438+
captureMessage: vi.fn(),
439+
} as unknown as Client;
440+
441+
const sentryScope = {
442+
getClient: vi.fn(),
443+
setTag: vi.fn(),
444+
addBreadcrumb: vi.fn(),
445+
} as unknown as Scope;
446+
447+
const output = new Output(
448+
{
449+
apiUrl: "http://localhost",
450+
bundleName: "output-test",
451+
debug: false,
452+
dryRun: false,
453+
enableBundleAnalysis: true,
454+
retryCount: 1,
455+
uploadToken: "token",
456+
telemetry: false,
457+
},
458+
{ sentryClient, sentryScope },
459+
);
460+
461+
output.start();
462+
output.end();
463+
464+
await output.write();
465+
466+
// eslint-disable-next-line @typescript-eslint/unbound-method
467+
expect(sentryScope.setTag).toHaveBeenNthCalledWith(
468+
1,
469+
"service",
470+
"github",
471+
);
472+
// eslint-disable-next-line @typescript-eslint/unbound-method
473+
expect(sentryScope.setTag).toHaveBeenNthCalledWith(
474+
2,
475+
"owner",
476+
"codecov",
477+
);
478+
// eslint-disable-next-line @typescript-eslint/unbound-method
479+
expect(sentryScope.setTag).toHaveBeenNthCalledWith(
480+
3,
481+
"repo",
482+
"codecov-javascript-bundler-plugins",
483+
);
484+
});
485+
});
486+
434487
describe("fails to fetch pre-signed URL", () => {
435488
it("immediately returns", async () => {
436489
setup({ urlSendError: true });

0 commit comments

Comments
 (0)