MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / constructor

Method constructor

packages/browser/src/client.ts:89–135  ·  view source on GitHub ↗

* Creates a new Browser SDK instance. * * @param options Configuration options for this SDK.

(options: BrowserClientOptions)

Source from the content-addressed store, hash-verified

87 * @param options Configuration options for this SDK.
88 */
89 public constructor(options: BrowserClientOptions) {
90 const opts = applyDefaultOptions(options);
91 const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();
92 applySdkMetadata(opts, 'browser', ['browser'], sdkSource);
93
94 super(opts);
95
96 const { userInfo } = this.getDataCollectionOptions();
97
98 if (opts._metadata?.sdk) {
99 opts._metadata.sdk.settings = {
100 // Only allow IP inferral by Relay if the user opted in via dataCollection
101 infer_ip: userInfo ? 'auto' : 'never',
102 // purposefully allowing already passed settings to override the default
103 ...opts._metadata.sdk.settings,
104 };
105 }
106
107 const { sendClientReports, enableLogs, _experiments, enableMetrics: enableMetricsOption } = this._options;
108
109 // todo(v11): Remove the experimental flag
110 // eslint-disable-next-line typescript/no-deprecated
111 const enableMetrics = enableMetricsOption ?? _experiments?.enableMetrics ?? true;
112
113 // Flush logs and metrics when page becomes hidden (e.g., tab switch, navigation)
114 // todo(v11): Remove the experimental flag
115 if (WINDOW.document && (sendClientReports || enableLogs || enableMetrics)) {
116 WINDOW.document.addEventListener('visibilitychange', () => {
117 if (WINDOW.document.visibilityState === 'hidden') {
118 if (sendClientReports) {
119 this._flushOutcomes();
120 }
121 if (enableLogs) {
122 _INTERNAL_flushLogsBuffer(this);
123 }
124
125 if (enableMetrics) {
126 _INTERNAL_flushMetricsBuffer(this);
127 }
128 }
129 });
130 }
131
132 if (userInfo) {
133 this.on('beforeSendSession', addAutoIpAddressToSession);
134 }
135 }
136
137 /**
138 * @inheritDoc

Callers

nothing calls this directly

Calls 7

applyDefaultOptionsFunction · 0.85
getSDKSourceFunction · 0.85
applySdkMetadataFunction · 0.85
addEventListenerMethod · 0.65
onMethod · 0.65

Tested by

no test coverage detected