Skip to content

Commit 605555b

Browse files
authored
feat(nextjs): add connectivity check to example page (#951)
1 parent e36505b commit 605555b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

33
## Unreleased
4-
54
- test(react-native): Add E2E Tests for React Native and Expo projects ([#884](https://github.com/getsentry/sentry-wizard/pull/884))
5+
- feat(nextjs): Add connectivity check to example page([#951](https://github.com/getsentry/sentry-wizard/pull/951))
6+
67

78
## 4.7.0
89

src/nextjs/templates.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,19 @@ export function getSentryExamplePageContents(options: {
233233
options.useClient ? '"use client";\n\n' : ''
234234
}import Head from "next/head";
235235
import * as Sentry from "@sentry/nextjs";
236-
import { useState } from "react";
236+
import { useState, useEffect } from "react";
237237
238238
export default function Page() {
239239
const [hasSentError, setHasSentError] = useState(false);
240+
const [isConnected, setIsConnected] = useState(true);
241+
242+
useEffect(() => {
243+
async function checkConnectivity() {
244+
const result = await Sentry.diagnoseSdkConnectivity();
245+
setIsConnected(result !== 'sentry-unreachable');
246+
}
247+
checkConnectivity();
248+
}, []);
240249
241250
return (
242251
<div>
@@ -283,11 +292,16 @@ export default function Page() {
283292
<p className="success">
284293
Sample error was sent to Sentry.
285294
</p>
295+
) : !isConnected ? (
296+
<div className="connectivity-error">
297+
<p>The Sentry SDK is not able to reach Sentry right now - this may be due to an adblocker. For more information, see <a target="_blank" href="https://docs.sentry.io/platforms/javascript/guides/nextjs/troubleshooting/#the-sdk-is-not-sending-any-data">the troubleshooting guide</a>.</p>
298+
</div>
286299
) : (
287300
<div className="success_placeholder" />
288301
)}
289302
290303
<div className="flex-spacer" />
304+
291305
<p className="description">
292306
Adblockers will prevent errors from being sent to Sentry.
293307
</p>
@@ -388,6 +402,22 @@ export default function Page() {
388402
.success_placeholder {
389403
height: 46px;
390404
}
405+
406+
.connectivity-error {
407+
padding: 12px 16px;
408+
background-color: #E50045;
409+
border-radius: 8px;
410+
width: 500px;
411+
color: #FFFFFF;
412+
border: 1px solid #A80033;
413+
text-align: center;
414+
margin: 0;
415+
}
416+
417+
.connectivity-error a {
418+
color: #FFFFFF;
419+
text-decoration: underline;
420+
}
391421
\`}</style>
392422
</div>
393423
);

0 commit comments

Comments
 (0)