11import { getCurrentHub , initAndBind , Integrations as CoreIntegrations } from '@sentry/core' ;
2- import { addInstrumentationHandler , getGlobalObject , logger , resolvedSyncPromise } from '@sentry/utils' ;
2+ import { Hub } from '@sentry/types' ;
3+ import { addInstrumentationHandler , getGlobalObject , isDebugBuild , logger , resolvedSyncPromise } from '@sentry/utils' ;
34
45import { BrowserOptions } from './backend' ;
56import { BrowserClient } from './client' ;
@@ -161,7 +162,9 @@ export function flush(timeout?: number): PromiseLike<boolean> {
161162 if ( client ) {
162163 return client . flush ( timeout ) ;
163164 }
164- logger . warn ( 'Cannot flush events. No client defined.' ) ;
165+ if ( isDebugBuild ( ) ) {
166+ logger . warn ( 'Cannot flush events. No client defined.' ) ;
167+ }
165168 return resolvedSyncPromise ( false ) ;
166169}
167170
@@ -178,7 +181,9 @@ export function close(timeout?: number): PromiseLike<boolean> {
178181 if ( client ) {
179182 return client . close ( timeout ) ;
180183 }
181- logger . warn ( 'Cannot flush events and disable SDK. No client defined.' ) ;
184+ if ( isDebugBuild ( ) ) {
185+ logger . warn ( 'Cannot flush events and disable SDK. No client defined.' ) ;
186+ }
182187 return resolvedSyncPromise ( false ) ;
183188}
184189
@@ -194,6 +199,11 @@ export function wrap(fn: (...args: any) => any): any {
194199 return internalWrap ( fn ) ( ) ;
195200}
196201
202+ function startSessionOnHub ( hub : Hub ) : void {
203+ hub . startSession ( { ignoreDuration : true } ) ;
204+ hub . captureSession ( ) ;
205+ }
206+
197207/**
198208 * Enable automatic Session Tracking for the initial page load.
199209 */
@@ -202,7 +212,9 @@ function startSessionTracking(): void {
202212 const document = window . document ;
203213
204214 if ( typeof document === 'undefined' ) {
205- logger . warn ( 'Session tracking in non-browser environment with @sentry/browser is not supported.' ) ;
215+ if ( isDebugBuild ( ) ) {
216+ logger . warn ( 'Session tracking in non-browser environment with @sentry/browser is not supported.' ) ;
217+ }
206218 return ;
207219 }
208220
@@ -214,24 +226,21 @@ function startSessionTracking(): void {
214226 // https://github.com/getsentry/sentry-javascript/issues/3207 and
215227 // https://github.com/getsentry/sentry-javascript/issues/3234 and
216228 // https://github.com/getsentry/sentry-javascript/issues/3278.
217- if ( typeof hub . startSession !== 'function' || typeof hub . captureSession !== 'function' ) {
229+ if ( ! hub . captureSession ) {
218230 return ;
219231 }
220232
221233 // The session duration for browser sessions does not track a meaningful
222234 // concept that can be used as a metric.
223235 // Automatically captured sessions are akin to page views, and thus we
224236 // discard their duration.
225- hub . startSession ( { ignoreDuration : true } ) ;
226- hub . captureSession ( ) ;
237+ startSessionOnHub ( hub ) ;
227238
228239 // We want to create a session for every navigation as well
229240 addInstrumentationHandler ( 'history' , ( { from, to } ) => {
230241 // Don't create an additional session for the initial route or if the location did not change
231- if ( from === undefined || from === to ) {
232- return ;
242+ if ( ! ( from === undefined || from === to ) ) {
243+ startSessionOnHub ( getCurrentHub ( ) ) ;
233244 }
234- hub . startSession ( { ignoreDuration : true } ) ;
235- hub . captureSession ( ) ;
236245 } ) ;
237246}
0 commit comments