@@ -149,6 +149,113 @@ describe('init()', () => {
149
149
150
150
expect ( client ) . toBeInstanceOf ( NodeClient ) ;
151
151
} ) ;
152
+
153
+ describe ( 'environment variable options' , ( ) => {
154
+ const originalProcessEnv = { ...process . env } ;
155
+
156
+ afterEach ( ( ) => {
157
+ process . env = originalProcessEnv ;
158
+ global . __SENTRY__ = { } ;
159
+ cleanupOtel ( ) ;
160
+ vi . clearAllMocks ( ) ;
161
+ } ) ;
162
+
163
+ it ( 'sets debug from `SENTRY_DEBUG` env variable' , ( ) => {
164
+ process . env . SENTRY_DEBUG = '1' ;
165
+
166
+ const client = init ( { dsn : PUBLIC_DSN } ) ;
167
+
168
+ expect ( client ?. getOptions ( ) ) . toEqual (
169
+ expect . objectContaining ( {
170
+ debug : true ,
171
+ } ) ,
172
+ ) ;
173
+ } ) ;
174
+
175
+ it ( 'prefers `debug` option over `SENTRY_DEBUG` env variable' , ( ) => {
176
+ process . env . SENTRY_DEBUG = '1' ;
177
+
178
+ const client = init ( { dsn : PUBLIC_DSN , debug : false } ) ;
179
+
180
+ expect ( client ?. getOptions ( ) ) . toEqual (
181
+ expect . objectContaining ( {
182
+ debug : false ,
183
+ } ) ,
184
+ ) ;
185
+ } ) ;
186
+
187
+ it ( 'sets tracesSampleRate from `SENTRY_TRACES_SAMPLE_RATE` env variable' , ( ) => {
188
+ process . env . SENTRY_TRACES_SAMPLE_RATE = '0.5' ;
189
+
190
+ const client = init ( { dsn : PUBLIC_DSN } ) ;
191
+
192
+ expect ( client ?. getOptions ( ) ) . toEqual (
193
+ expect . objectContaining ( {
194
+ tracesSampleRate : 0.5 ,
195
+ } ) ,
196
+ ) ;
197
+ } ) ;
198
+
199
+ it ( 'prefers `tracesSampleRate` option over `SENTRY_TRACES_SAMPLE_RATE` env variable' , ( ) => {
200
+ process . env . SENTRY_TRACES_SAMPLE_RATE = '0.5' ;
201
+
202
+ const client = init ( { dsn : PUBLIC_DSN , tracesSampleRate : 0.1 } ) ;
203
+
204
+ expect ( client ?. getOptions ( ) ) . toEqual (
205
+ expect . objectContaining ( {
206
+ tracesSampleRate : 0.1 ,
207
+ } ) ,
208
+ ) ;
209
+ } ) ;
210
+
211
+ it ( 'sets release from `SENTRY_RELEASE` env variable' , ( ) => {
212
+ process . env . SENTRY_RELEASE = '1.0.0' ;
213
+
214
+ const client = init ( { dsn : PUBLIC_DSN } ) ;
215
+
216
+ expect ( client ?. getOptions ( ) ) . toEqual (
217
+ expect . objectContaining ( {
218
+ release : '1.0.0' ,
219
+ } ) ,
220
+ ) ;
221
+ } ) ;
222
+
223
+ it ( 'prefers `release` option over `SENTRY_RELEASE` env variable' , ( ) => {
224
+ process . env . SENTRY_RELEASE = '1.0.0' ;
225
+
226
+ const client = init ( { dsn : PUBLIC_DSN , release : '2.0.0' } ) ;
227
+
228
+ expect ( client ?. getOptions ( ) ) . toEqual (
229
+ expect . objectContaining ( {
230
+ release : '2.0.0' ,
231
+ } ) ,
232
+ ) ;
233
+ } ) ;
234
+
235
+ it ( 'sets environment from `SENTRY_ENVIRONMENT` env variable' , ( ) => {
236
+ process . env . SENTRY_ENVIRONMENT = 'production' ;
237
+
238
+ const client = init ( { dsn : PUBLIC_DSN } ) ;
239
+
240
+ expect ( client ?. getOptions ( ) ) . toEqual (
241
+ expect . objectContaining ( {
242
+ environment : 'production' ,
243
+ } ) ,
244
+ ) ;
245
+ } ) ;
246
+
247
+ it ( 'prefers `environment` option over `SENTRY_ENVIRONMENT` env variable' , ( ) => {
248
+ process . env . SENTRY_ENVIRONMENT = 'production' ;
249
+
250
+ const client = init ( { dsn : PUBLIC_DSN , environment : 'staging' } ) ;
251
+
252
+ expect ( client ?. getOptions ( ) ) . toEqual (
253
+ expect . objectContaining ( {
254
+ environment : 'staging' ,
255
+ } ) ,
256
+ ) ;
257
+ } ) ;
258
+ } ) ;
152
259
} ) ;
153
260
154
261
describe ( 'validateOpenTelemetrySetup' , ( ) => {
0 commit comments