Skip to content

feat: Ensure we use the same default environment everywhere #7327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/browser/src/profiling/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_ENVIRONMENT } from '@sentry/core';
import type {
DsnComponents,
DynamicSamplingContext,
Expand Down Expand Up @@ -222,7 +223,7 @@ export function createProfilingEventEnvelope(
platform: 'javascript',
version: '1',
release: event.release || '',
environment: event.environment || '',
environment: event.environment || DEFAULT_ENVIRONMENT,
runtime: {
name: 'javascript',
version: WINDOW.navigator.userAgent,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_ENVIRONMENT = 'production';
3 changes: 2 additions & 1 deletion packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
uuid4,
} from '@sentry/utils';

import { DEFAULT_ENVIRONMENT } from './constants';
import { Scope } from './scope';
import { closeSession, makeSession, updateSession } from './session';

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

// Will fetch userAgent if called from browser sdk
const { userAgent } = GLOBAL_OBJ.navigator || {};
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { getIntegrationsToSetup } from './integration';
export { FunctionToString, InboundFilters } from './integrations';
export { prepareEvent } from './utils/prepareEvent';
export { hasTracingEnabled } from './utils/hasTracingEnabled';
export { DEFAULT_ENVIRONMENT } from './constants';

import * as Integrations from './integrations';

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/prepareEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ClientOptions, Event, EventHint, StackParser } from '@sentry/types';
import { dateTimestampInSeconds, GLOBAL_OBJ, normalize, resolvedSyncPromise, truncate, uuid4 } from '@sentry/utils';

import { DEFAULT_ENVIRONMENT } from '../constants';
import { Scope } from '../scope';

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

if (!('environment' in event)) {
event.environment = 'environment' in options ? environment : 'production';
event.environment = 'environment' in options ? environment : DEFAULT_ENVIRONMENT;
}

if (event.release === undefined && release !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions packages/tracing/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Hub } from '@sentry/core';
import { getCurrentHub } from '@sentry/core';
import { DEFAULT_ENVIRONMENT, getCurrentHub } from '@sentry/core';
import type {
Context,
Contexts,
Expand Down Expand Up @@ -260,7 +260,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
const transaction = source && source !== 'url' ? this.name : undefined;

const dsc = dropUndefinedKeys({
environment,
environment: environment || DEFAULT_ENVIRONMENT,
release,
transaction,
user_segment,
Expand Down