@@ -11,6 +11,48 @@ import { useEffect } from 'react';
1111let initialized = false ;
1212const enabled = ! import . meta. env . DEV && ! isLocalStudio ;
1313
14+ /**
15+ * Reaching an instance can legitimately fail when it's down, restarting, or the
16+ * user lacks Fabric Connect — these are expected states, not Studio bugs, and they
17+ * otherwise flood Error Tracking. Drop connectivity-class errors (timeouts, network
18+ * failures) against instance/cluster operation endpoints so they don't create issues.
19+ *
20+ * Returning false discards the event entirely.
21+ */
22+ function discardExpectedInstanceErrors (
23+ event : { type : string ; error ?: { message ?: string ; source ?: string ; resource ?: { url ?: string } } } ,
24+ ) {
25+ if ( event . type !== 'error' ) {
26+ return true ;
27+ }
28+ const message = event . error ?. message ?? '' ;
29+ const source = event . error ?. source ;
30+
31+ // Aborted requests are client-initiated cancellations (navigating away, a
32+ // component unmounting, React Query cancelling an in-flight query) — not failures.
33+ // Safe to drop globally regardless of endpoint.
34+ if ( / R e q u e s t a b o r t e d / i. test ( message ) ) {
35+ return false ;
36+ }
37+
38+ // Belt-and-suspenders: any stray "Fabric Connect not established" breadcrumb.
39+ if ( message . includes ( 'Fabric Connect not established' ) ) {
40+ return false ;
41+ }
42+
43+ // Network failures (timeouts, connection refused) against an instance/cluster.
44+ const url = event . error ?. resource ?. url ?? '' ;
45+ const isInstanceEndpoint = / \/ ( H D B I n s t a n c e | C l u s t e r ) \/ [ ^ / ] + \/ o p e r a t i o n / . test ( url ) ;
46+ const isConnectivityFailure = / t i m e o u t o f \d + m s e x c e e d e d / i. test ( message )
47+ || / N e t w o r k E r r o r / i. test ( message )
48+ || source === 'network' ;
49+ if ( isInstanceEndpoint && isConnectivityFailure ) {
50+ return false ;
51+ }
52+
53+ return true ;
54+ }
55+
1456export function useDatadog ( ) {
1557 useEffect ( ( ) => {
1658 if ( initialized ) {
@@ -32,6 +74,8 @@ export function useDatadog() {
3274 trackViewsManually : true ,
3375 trackUserInteractions : true ,
3476
77+ beforeSend : discardExpectedInstanceErrors ,
78+
3579 sessionSampleRate : 100 ,
3680 sessionReplaySampleRate : 0 ,
3781 defaultPrivacyLevel : 'mask' ,
0 commit comments