Skip to content

Commit 4dd82e8

Browse files
authored
fix: Several fixes (#1671)
1 parent d67ad66 commit 4dd82e8

File tree

10 files changed

+36
-119
lines changed

10 files changed

+36
-119
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
- [core]: Invert logger logic the explicitly enable it.
6+
- [hub]: Require `domain` in `getCurrentHub` in try/catch - Fixed #1670
7+
- [hub]: Removed exposed getter on the Scope.
8+
59
## 4.2.0
610

711
- [browser] fix: Make `addBreadcrumb` sync internally, `beforeBreadcrumb` is now only sync

packages/core/src/integrations/dedupe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
22
import { Integration, SentryEvent, SentryException, StackFrame } from '@sentry/types';
3+
import { logger } from '@sentry/utils/logger';
34
import { getEventDescription } from '@sentry/utils/misc';
4-
import { logger } from '../logger';
55

66
/** Deduplication filter */
77
export class Dedupe implements Integration {

packages/core/src/logger.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

packages/core/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface ClientClass<F extends Client, O extends Options> {
1616
* @returns The installed and bound client instance.
1717
*/
1818
export function initAndBind<F extends Client, O extends Options>(clientClass: ClientClass<F, O>, options: O): void {
19-
if (!options.debug) {
20-
logger.disable();
19+
if (options.debug === true) {
20+
logger.enable();
2121
}
2222

2323
if (getCurrentHub().getClient()) {

packages/core/test/lib/base.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,65 +101,65 @@ describe('BaseClient', () => {
101101
const scope = new Scope();
102102
scope.addBreadcrumb({ message: 'hello' }, 100);
103103
client.addBreadcrumb({ message: 'world' }, undefined, scope);
104-
expect(scope.getBreadcrumbs()[1].message).toBe('world');
104+
expect((scope as any).breadcrumbs[1].message).toBe('world');
105105
});
106106

107107
test('adds a timestamp to new breadcrumbs', () => {
108108
const client = new TestClient({});
109109
const scope = new Scope();
110110
scope.addBreadcrumb({ message: 'hello' }, 100);
111111
client.addBreadcrumb({ message: 'world' }, undefined, scope);
112-
expect(scope.getBreadcrumbs()[1].timestamp).toBeGreaterThan(1);
112+
expect((scope as any).breadcrumbs[1].timestamp).toBeGreaterThan(1);
113113
});
114114

115115
test('discards breadcrumbs beyond maxBreadcrumbs', () => {
116116
const client = new TestClient({ maxBreadcrumbs: 1 });
117117
const scope = new Scope();
118118
scope.addBreadcrumb({ message: 'hello' }, 100);
119119
client.addBreadcrumb({ message: 'world' }, undefined, scope);
120-
expect(scope.getBreadcrumbs().length).toBe(1);
121-
expect(scope.getBreadcrumbs()[0].message).toBe('world');
120+
expect((scope as any).breadcrumbs.length).toBe(1);
121+
expect((scope as any).breadcrumbs[0].message).toBe('world');
122122
});
123123

124124
test('allows concurrent updates', () => {
125125
const client = new TestClient({});
126126
const scope = new Scope();
127127
client.addBreadcrumb({ message: 'hello' }, undefined, scope);
128128
client.addBreadcrumb({ message: 'world' }, undefined, scope);
129-
expect(scope.getBreadcrumbs()).toHaveLength(2);
129+
expect((scope as any).breadcrumbs).toHaveLength(2);
130130
});
131131

132132
test('calls beforeBreadcrumb and adds the breadcrumb without any changes', () => {
133133
const beforeBreadcrumb = jest.fn(breadcrumb => breadcrumb);
134134
const client = new TestClient({ beforeBreadcrumb });
135135
const scope = new Scope();
136136
client.addBreadcrumb({ message: 'hello' }, undefined, scope);
137-
expect(scope.getBreadcrumbs()[0].message).toBe('hello');
137+
expect((scope as any).breadcrumbs[0].message).toBe('hello');
138138
});
139139

140140
test('calls beforeBreadcrumb and uses the new one', () => {
141141
const beforeBreadcrumb = jest.fn(() => ({ message: 'changed' }));
142142
const client = new TestClient({ beforeBreadcrumb });
143143
const scope = new Scope();
144144
client.addBreadcrumb({ message: 'hello' }, undefined, scope);
145-
expect(scope.getBreadcrumbs()[0].message).toBe('changed');
145+
expect((scope as any).breadcrumbs[0].message).toBe('changed');
146146
});
147147

148148
test('calls beforeBreadcrumb and discards the breadcrumb when returned null', () => {
149149
const beforeBreadcrumb = jest.fn(() => null);
150150
const client = new TestClient({ beforeBreadcrumb });
151151
const scope = new Scope();
152152
client.addBreadcrumb({ message: 'hello' }, undefined, scope);
153-
expect(scope.getBreadcrumbs().length).toBe(0);
153+
expect((scope as any).breadcrumbs.length).toBe(0);
154154
});
155155

156156
test('calls beforeBreadcrumb gets an access to a hint as a second argument', () => {
157157
const beforeBreadcrumb = jest.fn((breadcrumb, hint) => ({ ...breadcrumb, data: hint.data }));
158158
const client = new TestClient({ beforeBreadcrumb });
159159
const scope = new Scope();
160160
client.addBreadcrumb({ message: 'hello' }, { data: 'someRandomThing' }, scope);
161-
expect(scope.getBreadcrumbs()[0].message).toBe('hello');
162-
expect(scope.getBreadcrumbs()[0].data).toBe('someRandomThing');
161+
expect((scope as any).breadcrumbs[0].message).toBe('hello');
162+
expect((scope as any).breadcrumbs[0].data).toBe('someRandomThing');
163163
});
164164
});
165165

packages/hub/src/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '@sentry/types';
1010
import { logger } from '@sentry/utils/logger';
1111
import { getGlobalObject, uuid4 } from '@sentry/utils/misc';
12-
import * as domain from 'domain';
1312
import { Carrier, Layer } from './interfaces';
1413
import { Scope } from './scope';
1514

@@ -335,6 +334,7 @@ export function getCurrentHub(): Hub {
335334

336335
// Prefer domains over global if they are there
337336
try {
337+
const domain = require('domain');
338338
const activeDomain = domain.active;
339339

340340
// If there no active domain, just return global hub

packages/hub/src/scope.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,36 +148,6 @@ export class Scope {
148148
return newScope;
149149
}
150150

151-
/** Returns tags. */
152-
public getTags(): { [key: string]: string } {
153-
return this.tags;
154-
}
155-
156-
/** Returns extra. */
157-
public getExtra(): { [key: string]: any } {
158-
return this.extra;
159-
}
160-
161-
/** Returns extra. */
162-
public getUser(): User {
163-
return this.user;
164-
}
165-
166-
/** Returns fingerprint. */
167-
public getFingerprint(): string[] | undefined {
168-
return this.fingerprint;
169-
}
170-
171-
/** Returns breadcrumbs. */
172-
public getBreadcrumbs(): Breadcrumb[] {
173-
return this.breadcrumbs;
174-
}
175-
176-
/** Returns level. */
177-
public getLevel(): Severity | undefined {
178-
return this.level;
179-
}
180-
181151
/** Clears the current scope and resets its properties. */
182152
public clear(): void {
183153
this.breadcrumbs = [];

packages/hub/test/hub.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Hub', () => {
7676
hub.pushScope();
7777
expect(hub.getStack()).toHaveLength(2);
7878
expect(hub.getStack()[1].scope).not.toBe(localScope);
79-
expect((hub.getStack()[1].scope as Scope).getExtra()).toEqual({ a: 'b' });
79+
expect(((hub.getStack()[1].scope as Scope) as any).extra).toEqual({ a: 'b' });
8080
});
8181

8282
test('pushScope inherit client', () => {
@@ -241,7 +241,7 @@ describe('Hub', () => {
241241
localScope.setExtra('a', 'b');
242242
const hub = new Hub({ a: 'b' }, localScope);
243243
hub.configureScope(confScope => {
244-
expect(confScope.getExtra()).toEqual({ a: 'b' });
244+
expect((confScope as any).extra).toEqual({ a: 'b' });
245245
});
246246
});
247247

packages/hub/test/scope.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,59 @@ describe('Scope', () => {
1010
test('fingerprint', () => {
1111
const scope = new Scope();
1212
scope.setFingerprint(['abcd']);
13-
expect(scope.getFingerprint()).toEqual(['abcd']);
13+
expect((scope as any).fingerprint).toEqual(['abcd']);
1414
});
1515

1616
test('extra', () => {
1717
const scope = new Scope();
1818
scope.setExtra('a', 1);
19-
expect(scope.getExtra()).toEqual({ a: 1 });
19+
expect((scope as any).extra).toEqual({ a: 1 });
2020
});
2121

2222
test('tags', () => {
2323
const scope = new Scope();
2424
scope.setTag('a', 'b');
25-
expect(scope.getTags()).toEqual({ a: 'b' });
25+
expect((scope as any).tags).toEqual({ a: 'b' });
2626
});
2727

2828
test('user', () => {
2929
const scope = new Scope();
3030
scope.setUser({ id: '1' });
31-
expect(scope.getUser()).toEqual({ id: '1' });
31+
expect((scope as any).user).toEqual({ id: '1' });
3232
});
3333

3434
test('breadcrumbs', () => {
3535
const scope = new Scope();
3636
scope.addBreadcrumb({ message: 'test' }, 100);
37-
expect(scope.getBreadcrumbs()).toEqual([{ message: 'test' }]);
37+
expect((scope as any).breadcrumbs).toEqual([{ message: 'test' }]);
3838
});
3939

4040
test('level', () => {
4141
const scope = new Scope();
4242
scope.setLevel(Severity.Critical);
43-
expect(scope.getLevel()).toEqual(Severity.Critical);
43+
expect((scope as any).level).toEqual(Severity.Critical);
4444
});
4545

4646
test('chaining', () => {
4747
const scope = new Scope();
4848
scope.setLevel(Severity.Critical).setUser({ id: '1' });
49-
expect(scope.getLevel()).toEqual(Severity.Critical);
50-
expect(scope.getUser()).toEqual({ id: '1' });
49+
expect((scope as any).level).toEqual(Severity.Critical);
50+
expect((scope as any).user).toEqual({ id: '1' });
5151
});
5252

5353
test('basic inheritance', () => {
5454
const parentScope = new Scope();
5555
parentScope.setExtra('a', 1);
5656
const scope = Scope.clone(parentScope);
57-
expect(parentScope.getExtra()).toEqual(scope.getExtra());
57+
expect((parentScope as any).extra).toEqual((scope as any).extra);
5858
});
5959

6060
test('parent changed inheritance', () => {
6161
const parentScope = new Scope();
6262
const scope = Scope.clone(parentScope);
6363
parentScope.setExtra('a', 2);
64-
expect(scope.getExtra()).toEqual({});
65-
expect(parentScope.getExtra()).toEqual({ a: 2 });
64+
expect((scope as any).extra).toEqual({});
65+
expect((parentScope as any).extra).toEqual({ a: 2 });
6666
});
6767

6868
test('child override inheritance', () => {
@@ -71,8 +71,8 @@ describe('Scope', () => {
7171

7272
const scope = Scope.clone(parentScope);
7373
scope.setExtra('a', 2);
74-
expect(parentScope.getExtra()).toEqual({ a: 1 });
75-
expect(scope.getExtra()).toEqual({ a: 2 });
74+
expect((parentScope as any).extra).toEqual({ a: 1 });
75+
expect((scope as any).extra).toEqual({ a: 2 });
7676
});
7777

7878
test('listeners', () => {
@@ -142,9 +142,9 @@ describe('Scope', () => {
142142
scope.setUser({ id: '1' });
143143
scope.setFingerprint(['abcd']);
144144
scope.addBreadcrumb({ message: 'test' }, 100);
145-
expect(scope.getExtra()).toEqual({ a: 2 });
145+
expect((scope as any).extra).toEqual({ a: 2 });
146146
scope.clear();
147-
expect(scope.getExtra()).toEqual({});
147+
expect((scope as any).extra).toEqual({});
148148
});
149149

150150
test('addEventProcessor', async done => {

packages/utils/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Logger {
1010

1111
/** JSDoc */
1212
public constructor() {
13-
this.enabled = true;
13+
this.enabled = false;
1414
}
1515

1616
/** JSDoc */

0 commit comments

Comments
 (0)