Skip to content

Commit 97c6851

Browse files
authored
feat: Ensure we use the same default environment everywhere (#7327)
1 parent 697f95b commit 97c6851

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

packages/browser/src/profiling/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEFAULT_ENVIRONMENT } from '@sentry/core';
12
import type {
23
DsnComponents,
34
DynamicSamplingContext,
@@ -222,7 +223,7 @@ export function createProfilingEventEnvelope(
222223
platform: 'javascript',
223224
version: '1',
224225
release: event.release || '',
225-
environment: event.environment || '',
226+
environment: event.environment || DEFAULT_ENVIRONMENT,
226227
runtime: {
227228
name: 'javascript',
228229
version: WINDOW.navigator.userAgent,

packages/core/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DEFAULT_ENVIRONMENT = 'production';

packages/core/src/hub.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
uuid4,
3131
} from '@sentry/utils';
3232

33+
import { DEFAULT_ENVIRONMENT } from './constants';
3334
import { Scope } from './scope';
3435
import { closeSession, makeSession, updateSession } from './session';
3536

@@ -409,7 +410,7 @@ export class Hub implements HubInterface {
409410
*/
410411
public startSession(context?: SessionContext): Session {
411412
const { scope, client } = this.getStackTop();
412-
const { release, environment } = (client && client.getOptions()) || {};
413+
const { release, environment = DEFAULT_ENVIRONMENT } = (client && client.getOptions()) || {};
413414

414415
// Will fetch userAgent if called from browser sdk
415416
const { userAgent } = GLOBAL_OBJ.navigator || {};

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export { getIntegrationsToSetup } from './integration';
3131
export { FunctionToString, InboundFilters } from './integrations';
3232
export { prepareEvent } from './utils/prepareEvent';
3333
export { hasTracingEnabled } from './utils/hasTracingEnabled';
34+
export { DEFAULT_ENVIRONMENT } from './constants';
3435

3536
import * as Integrations from './integrations';
3637

packages/core/src/utils/prepareEvent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ClientOptions, Event, EventHint, StackParser } from '@sentry/types';
22
import { dateTimestampInSeconds, GLOBAL_OBJ, normalize, resolvedSyncPromise, truncate, uuid4 } from '@sentry/utils';
33

4+
import { DEFAULT_ENVIRONMENT } from '../constants';
45
import { Scope } from '../scope';
56

67
/**
@@ -87,7 +88,7 @@ function applyClientOptions(event: Event, options: ClientOptions): void {
8788
const { environment, release, dist, maxValueLength = 250 } = options;
8889

8990
if (!('environment' in event)) {
90-
event.environment = 'environment' in options ? environment : 'production';
91+
event.environment = 'environment' in options ? environment : DEFAULT_ENVIRONMENT;
9192
}
9293

9394
if (event.release === undefined && release !== undefined) {

packages/tracing/src/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Hub } from '@sentry/core';
2-
import { getCurrentHub } from '@sentry/core';
2+
import { DEFAULT_ENVIRONMENT, getCurrentHub } from '@sentry/core';
33
import type {
44
Context,
55
Contexts,
@@ -260,7 +260,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
260260
const transaction = source && source !== 'url' ? this.name : undefined;
261261

262262
const dsc = dropUndefinedKeys({
263-
environment,
263+
environment: environment || DEFAULT_ENVIRONMENT,
264264
release,
265265
transaction,
266266
user_segment,

0 commit comments

Comments
 (0)