Skip to content

Commit

Permalink
fix(nextjs,sveltekit): Replace deprecated Sentry API calls in example…
Browse files Browse the repository at this point in the history
… page templates (#520)

use `startSpan` instead of `configureScope` and `startTranscation`
  • Loading branch information
Lms24 authored Dec 22, 2023
1 parent a16b3cd commit 9c70a94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- fix(nextjs): Replace deprecated Sentry API calls in example page templates (#520)
- fix(sveltekit): Replace deprecated Sentry API calls in example page templates (#520)

## 3.20.0

- feat(nextjs): Ask for confirmation before creating example page (#515)
Expand Down
19 changes: 6 additions & 13 deletions src/nextjs/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,16 @@ export default function Page() {
fontSize: "14px",
margin: "18px",
}}
onClick={async () => {
const transaction = Sentry.startTransaction({
name: "Example Frontend Transaction",
});
Sentry.configureScope((scope) => {
scope.setSpan(transaction);
});
try {
onClick={() => {
Sentry.startSpan({
name: 'Example Frontend Span',
op: 'test'
}, async () => {
const res = await fetch("/api/sentry-example-api");
if (!res.ok) {
throw new Error("Sentry Example Frontend Error");
}
} finally {
transaction.finish();
}
});
}}
>
Throw error!
Expand Down
2 changes: 1 addition & 1 deletion src/sveltekit/sveltekit-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function runSvelteKitWizardWithTelemetry(
}

const shouldCreateExamplePage = await askShouldCreateExamplePage(
'sentry-example',
'/sentry-example',
);

if (shouldCreateExamplePage) {
Expand Down
19 changes: 6 additions & 13 deletions src/sveltekit/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,16 @@ Feel free to delete this file and the entire sentry route.
<script>
import * as Sentry from '@sentry/sveltekit';
async function getSentryData() {
const transaction = Sentry.startTransaction({
name: 'Example Frontend Transaction'
});
Sentry.configureScope((scope) => {
scope.setSpan(transaction);
});
try {
function getSentryData() {
Sentry.startSpan({
name: 'Example Frontend Span',
op: 'test',
}, async () => {
const res = await fetch('/sentry-example');
if (!res.ok) {
throw new Error('Sentry Example Frontend Error');
}
} finally {
transaction.finish();
}
});
}
</script>
Expand Down

0 comments on commit 9c70a94

Please sign in to comment.