From e041bfa62585e14d146a3797fc47dd47b8e2c81c Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 15 Sep 2023 09:49:12 +0200 Subject: [PATCH] ref(telemetry): Use new `startSpan` function (#459) - bump the Node SDK to the latest version - replace manual `startTransaction` call with `startSpan` in `withTelemetry` - replace `trace` (RIP) with `startSpan` in `traceStep` --- package.json | 2 +- src/telemetry.ts | 45 +++++++++++++++++++---------------- yarn.lock | 62 ++++++++++++++++++++++++------------------------ 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index ac1bd872..fae94dfb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@clack/core": "0.3.3", "@clack/prompts": "0.7.0", "@sentry/cli": "^1.72.0", - "@sentry/node": "^7.57.0", + "@sentry/node": "^7.69.0", "axios": "1.3.5", "chalk": "^2.4.1", "glob": "^7.1.3", diff --git a/src/telemetry.ts b/src/telemetry.ts index f8cb0a1e..9f6eaa86 100644 --- a/src/telemetry.ts +++ b/src/telemetry.ts @@ -6,7 +6,7 @@ import { makeNodeTransport, NodeClient, runWithAsyncContext, - trace, + startSpan, } from '@sentry/node'; import packageJson from '../package.json'; @@ -24,27 +24,32 @@ export async function withTelemetry( makeMain(sentryHub); - const transaction = sentryHub.startTransaction({ - name: 'sentry-wizard-execution', - status: 'ok', - op: 'wizard.flow', - }); - sentryHub.getScope().setSpan(transaction); const sentrySession = sentryHub.startSession(); sentryHub.captureSession(); - try { - return await runWithAsyncContext(() => callback()); - } catch (e) { - sentryHub.captureException('Error during wizard execution.'); - transaction.setStatus('internal_error'); - sentrySession.status = 'crashed'; - throw e; - } finally { - transaction.finish(); - sentryHub.endSession(); - await sentryClient.flush(3000); - } + return startSpan( + { + name: 'sentry-wizard-execution', + status: 'ok', + op: 'wizard.flow', + }, + async (span) => { + if (!span) { + return runWithAsyncContext(() => callback()); + } + try { + return await runWithAsyncContext(() => callback()); + } catch (e) { + sentryHub.captureException('Error during wizard execution.'); + span.setStatus('internal_error'); + sentrySession.status = 'crashed'; + throw e; + } finally { + sentryHub.endSession(); + await sentryClient.flush(3000); + } + }, + ); } function createSentryInstance(enabled: boolean, integration: string) { @@ -92,5 +97,5 @@ function createSentryInstance(enabled: boolean, integration: string) { } export function traceStep(step: string, callback: () => T): T { - return trace({ name: step, op: 'wizard.step' }, () => callback()); + return startSpan({ name: step, op: 'wizard.step' }, () => callback()); } diff --git a/yarn.lock b/yarn.lock index 915d8610..e7c318a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -747,14 +747,14 @@ dependencies: requireindex "~1.1.0" -"@sentry-internal/tracing@7.57.0": - version "7.57.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.57.0.tgz#cb761931b635f8f24c84be0eecfacb8516b20551" - integrity sha512-tpViyDd8AhQGYYhI94xi2aaDopXOPfL2Apwrtb3qirWkomIQ2K86W1mPmkce+B0cFOnW2Dxv/ZTFKz6ghjK75A== - dependencies: - "@sentry/core" "7.57.0" - "@sentry/types" "7.57.0" - "@sentry/utils" "7.57.0" +"@sentry-internal/tracing@7.69.0": + version "7.69.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.69.0.tgz#8d8eb740b72967b6ba3fdc0a5173aa55331b7d35" + integrity sha512-4BgeWZUj9MO6IgfO93C9ocP3+AdngqujF/+zB2rFdUe+y9S6koDyUC7jr9Knds/0Ta72N/0D6PwhgSCpHK8s0Q== + dependencies: + "@sentry/core" "7.69.0" + "@sentry/types" "7.69.0" + "@sentry/utils" "7.69.0" tslib "^2.4.1 || ^1.9.3" "@sentry-internal/typescript@7.48.0": @@ -774,40 +774,40 @@ progress "^2.0.3" proxy-from-env "^1.1.0" -"@sentry/core@7.57.0": - version "7.57.0" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.57.0.tgz#65093d739c04f320a54395a21be955fcbe326acb" - integrity sha512-l014NudPH0vQlzybtXajPxYFfs9w762NoarjObC3gu76D1jzBBFzhdRelkGpDbSLNTIsKhEDDRpgAjBWJ9icfw== +"@sentry/core@7.69.0": + version "7.69.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.69.0.tgz#ebbe01df573f438f8613107020a4e18eb9adca4d" + integrity sha512-V6jvK2lS8bhqZDMFUtvwe2XvNstFQf5A+2LMKCNBOV/NN6eSAAd6THwEpginabjet9dHsNRmMk7WNKvrUfQhZw== dependencies: - "@sentry/types" "7.57.0" - "@sentry/utils" "7.57.0" + "@sentry/types" "7.69.0" + "@sentry/utils" "7.69.0" tslib "^2.4.1 || ^1.9.3" -"@sentry/node@^7.57.0": - version "7.57.0" - resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.57.0.tgz#31052f5988ed4496d7f3ff925240cf9b02d09941" - integrity sha512-63mjyUVM6sfJFVQ5TGVRVGUsoEfESl5ABzIW1W0s9gUiQPaG8SOdaQJglb2VNrkMYxnRHgD8Q9LUh/qcmUyPGw== +"@sentry/node@^7.69.0": + version "7.69.0" + resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.69.0.tgz#938200095a17f41a2445fec168df293db7c24836" + integrity sha512-T0NgPcmDQvEuz5hy6aEhXghTHHTWsiP3IWoeEAakDBHAXmtpT6lYFQZgb5AiEOt9F5KO/G/1yH3YYdpDAnKhPw== dependencies: - "@sentry-internal/tracing" "7.57.0" - "@sentry/core" "7.57.0" - "@sentry/types" "7.57.0" - "@sentry/utils" "7.57.0" + "@sentry-internal/tracing" "7.69.0" + "@sentry/core" "7.69.0" + "@sentry/types" "7.69.0" + "@sentry/utils" "7.69.0" cookie "^0.4.1" https-proxy-agent "^5.0.0" lru_map "^0.3.3" tslib "^2.4.1 || ^1.9.3" -"@sentry/types@7.57.0": - version "7.57.0" - resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.57.0.tgz#4fdb80cbd49ba034dd8d9be0c0005a016d5db3ce" - integrity sha512-D7ifoUfxuVCUyktIr5Gc+jXUbtcUMmfHdTtTbf1XCZHua5mJceK9wtl3YCg3eq/HK2Ppd52BKnTzEcS5ZKQM+w== +"@sentry/types@7.69.0": + version "7.69.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.69.0.tgz#012b8d90d270a473cc2a5cf58a56870542739292" + integrity sha512-zPyCox0mzitzU6SIa1KIbNoJAInYDdUpdiA+PoUmMn2hFMH1llGU/cS7f4w/mAsssTlbtlBi72RMnWUCy578bw== -"@sentry/utils@7.57.0": - version "7.57.0" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.57.0.tgz#8253c6fcf35138b4c424234b8da1596e11b98ad8" - integrity sha512-YXrkMCiNklqkXctn4mKYkrzNCf/dfVcRUQrkXjeBC+PHXbcpPyaJgInNvztR7Skl8lE3JPGPN4v5XhLxK1bUUg== +"@sentry/utils@7.69.0": + version "7.69.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.69.0.tgz#b7594e4eb2a88b9b25298770b841dd3f81bd2aa4" + integrity sha512-4eBixe5Y+0EGVU95R4NxH3jkkjtkE4/CmSZD4In8SCkWGSauogePtq6hyiLsZuP1QHdpPb9Kt0+zYiBb2LouBA== dependencies: - "@sentry/types" "7.57.0" + "@sentry/types" "7.69.0" tslib "^2.4.1 || ^1.9.3" "@sinclair/typebox@^0.25.16":