Skip to content

Commit 5c074bf

Browse files
authored
Merge branch 'develop' into metrics-summary
2 parents 34c6219 + 90b45f0 commit 5c074bf

File tree

65 files changed

+653
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+653
-377
lines changed

MIGRATION.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,45 @@ If you are using the `Hub` right now, see the following table on how to migrate
289289
| endSession() | `Sentry.endSession()` |
290290
| shouldSendDefaultPii() | REMOVED - The closest equivalent is `Sentry.getClient().getOptions().sendDefaultPii` |
291291

292+
The `Hub` constructor is also deprecated and will be removed in the next major version. If you are creating Hubs for
293+
multi-client use like so:
294+
295+
```ts
296+
// OLD
297+
const hub = new Hub();
298+
hub.bindClient(client);
299+
makeMain(hub);
300+
```
301+
302+
instead initialize the client as follows:
303+
304+
```ts
305+
// NEW
306+
Sentry.withIsolationScope(() => {
307+
Sentry.setCurrentClient(client);
308+
client.init();
309+
});
310+
```
311+
312+
If you are using the Hub to capture events like so:
313+
314+
```ts
315+
// OLD
316+
const client = new Client();
317+
const hub = new Hub(client);
318+
hub.captureException();
319+
```
320+
321+
instead capture isolated events as follows:
322+
323+
```ts
324+
// NEW
325+
const client = new Client();
326+
const scope = new Scope();
327+
scope.setClient(client);
328+
scope.captureException();
329+
```
330+
292331
## Deprecate `client.setupIntegrations()`
293332

294333
Instead, use the new `client.init()` method. You should probably not use this directly and instead use `Sentry.init()`,

dev-packages/browser-integration-tests/suites/replay/dsc/test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sentryTest(
3636

3737
await page.evaluate(() => {
3838
const scope = (window as unknown as TestWindow).Sentry.getCurrentScope();
39-
scope.setUser({ id: 'user123', segment: 'segmentB' });
39+
scope.setUser({ id: 'user123' });
4040
scope.addEventProcessor(event => {
4141
event.transaction = 'testTransactionDSC';
4242
return event;
@@ -53,7 +53,6 @@ sentryTest(
5353
expect(envHeader.trace).toBeDefined();
5454
expect(envHeader.trace).toEqual({
5555
environment: 'production',
56-
user_segment: 'segmentB',
5756
sample_rate: '1',
5857
trace_id: expect.any(String),
5958
public_key: 'public',
@@ -84,7 +83,7 @@ sentryTest(
8483

8584
await page.evaluate(() => {
8685
const scope = (window as unknown as TestWindow).Sentry.getCurrentScope();
87-
scope.setUser({ id: 'user123', segment: 'segmentB' });
86+
scope.setUser({ id: 'user123' });
8887
scope.addEventProcessor(event => {
8988
event.transaction = 'testTransactionDSC';
9089
return event;
@@ -101,7 +100,6 @@ sentryTest(
101100
expect(envHeader.trace).toBeDefined();
102101
expect(envHeader.trace).toEqual({
103102
environment: 'production',
104-
user_segment: 'segmentB',
105103
sample_rate: '1',
106104
trace_id: expect.any(String),
107105
public_key: 'public',
@@ -144,7 +142,7 @@ sentryTest(
144142

145143
await page.evaluate(() => {
146144
const scope = (window as unknown as TestWindow).Sentry.getCurrentScope();
147-
scope.setUser({ id: 'user123', segment: 'segmentB' });
145+
scope.setUser({ id: 'user123' });
148146
scope.addEventProcessor(event => {
149147
event.transaction = 'testTransactionDSC';
150148
return event;
@@ -162,7 +160,6 @@ sentryTest(
162160
expect(envHeader.trace).toBeDefined();
163161
expect(envHeader.trace).toEqual({
164162
environment: 'production',
165-
user_segment: 'segmentB',
166163
sample_rate: '1',
167164
trace_id: expect.any(String),
168165
public_key: 'public',
@@ -195,7 +192,7 @@ sentryTest(
195192

196193
await page.evaluate(async () => {
197194
const scope = (window as unknown as TestWindow).Sentry.getCurrentScope();
198-
scope.setUser({ id: 'user123', segment: 'segmentB' });
195+
scope.setUser({ id: 'user123' });
199196
scope.addEventProcessor(event => {
200197
event.transaction = 'testTransactionDSC';
201198
return event;
@@ -213,7 +210,6 @@ sentryTest(
213210
expect(envHeader.trace).toBeDefined();
214211
expect(envHeader.trace).toEqual({
215212
environment: 'production',
216-
user_segment: 'segmentB',
217213
sample_rate: '1',
218214
trace_id: expect.any(String),
219215
public_key: 'public',

dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Sentry.init({
1212
});
1313

1414
const scope = Sentry.getCurrentScope();
15-
scope.setUser({ id: 'user123', segment: 'segmentB' });
15+
scope.setUser({ id: 'user123' });
1616
scope.addEventProcessor(event => {
1717
event.transaction = 'testTransactionDSC';
1818
return event;

dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ sentryTest(
2222
expect(envHeader.trace).toBeDefined();
2323
expect(envHeader.trace).toEqual({
2424
environment: 'production',
25-
user_segment: 'segmentB',
2625
sample_rate: '1',
2726
transaction: expect.stringContaining('/index.html'),
2827
trace_id: expect.any(String),

dev-packages/browser-integration-tests/suites/tracing/envelope-header/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Sentry.init({
1212
});
1313

1414
const scope = Sentry.getCurrentScope();
15-
scope.setUser({ id: 'user123', segment: 'segmentB' });
15+
scope.setUser({ id: 'user123' });
1616
scope.addEventProcessor(event => {
1717
event.transaction = 'testTransactionDSC';
1818
return event;

dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ sentryTest(
2626
expect(envHeader.trace).toBeDefined();
2727
expect(envHeader.trace).toEqual({
2828
environment: 'production',
29-
user_segment: 'segmentB',
3029
sample_rate: '1',
3130
trace_id: expect.any(String),
3231
public_key: 'public',

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Sentry.init({
2020
transport: loggingTransport,
2121
});
2222

23-
Sentry.setUser({ id: 'user123', segment: 'SegmentA' });
23+
Sentry.setUser({ id: 'user123' });
2424

2525
app.use(Sentry.Handlers.requestHandler());
2626
app.use(Sentry.Handlers.tracingHandler());

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('should attach a baggage header to an outgoing request.', async () => {
1515
test_data: {
1616
host: 'somewhere.not.sentry',
1717
baggage:
18-
'sentry-environment=prod,sentry-release=1.0,sentry-user_segment=SegmentA,sentry-public_key=public' +
18+
'sentry-environment=prod,sentry-release=1.0,sentry-public_key=public' +
1919
',sentry-trace_id=86f39e84263a4de99c326acab3bfe3bd,sentry-sample_rate=1,sentry-transaction=GET%20%2Ftest%2Fexpress' +
2020
',sentry-sampled=true',
2121
},

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Sentry.init({
2424
transport: loggingTransport,
2525
});
2626

27-
Sentry.setUser({ id: 'user123', segment: 'SegmentA' });
27+
Sentry.setUser({ id: 'user123' });
2828

2929
app.use(Sentry.Handlers.requestHandler());
3030
app.use(Sentry.Handlers.tracingHandler());

packages/astro/src/server/meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function getTracingMetaTags(
4242
: dsc
4343
? dsc
4444
: client
45-
? getDynamicSamplingContextFromClient(traceId, client, scope)
45+
? getDynamicSamplingContextFromClient(traceId, client)
4646
: undefined;
4747

4848
const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);

packages/bun/test/integrations/bunserver.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Bun Serve Integration', () => {
1919
beforeEach(() => {
2020
const options = getDefaultBunClientOptions({ tracesSampleRate: 1, debug: true });
2121
client = new BunClient(options);
22+
// eslint-disable-next-line deprecation/deprecation
2223
hub = new Hub(client);
2324
// eslint-disable-next-line deprecation/deprecation
2425
makeMain(hub);

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
679679
...evt.contexts,
680680
};
681681

682-
const dynamicSamplingContext = dsc ? dsc : getDynamicSamplingContextFromClient(trace_id, this, scope);
682+
const dynamicSamplingContext = dsc ? dsc : getDynamicSamplingContextFromClient(trace_id, this);
683683

684684
evt.sdkProcessingMetadata = {
685685
dynamicSamplingContext,

packages/core/src/hub.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function createHub(...options: ConstructorParameters<typeof Hub>): Hub {
110110
return sentry.createHub(...options);
111111
}
112112

113+
// eslint-disable-next-line deprecation/deprecation
113114
return new Hub(...options);
114115
}
115116

@@ -132,6 +133,46 @@ export class Hub implements HubInterface {
132133
* @param client bound to the hub.
133134
* @param scope bound to the hub.
134135
* @param version number, higher number means higher priority.
136+
*
137+
* @deprecated Instantiation of Hub objects is deprecated and the constructor will be removed in version 8 of the SDK.
138+
*
139+
* If you are currently using the Hub for multi-client use like so:
140+
*
141+
* ```
142+
* // OLD
143+
* const hub = new Hub();
144+
* hub.bindClient(client);
145+
* makeMain(hub)
146+
* ```
147+
*
148+
* instead initialize the client as follows:
149+
*
150+
* ```
151+
* // NEW
152+
* Sentry.withIsolationScope(() => {
153+
* Sentry.setCurrentClient(client);
154+
* client.init();
155+
* });
156+
* ```
157+
*
158+
* If you are using the Hub to capture events like so:
159+
*
160+
* ```
161+
* // OLD
162+
* const client = new Client();
163+
* const hub = new Hub(client);
164+
* hub.captureException()
165+
* ```
166+
*
167+
* instead capture isolated events as follows:
168+
*
169+
* ```
170+
* // NEW
171+
* const client = new Client();
172+
* const scope = new Scope();
173+
* scope.setClient(client);
174+
* scope.captureException();
175+
* ```
135176
*/
136177
public constructor(
137178
client?: Client,

packages/core/src/scope.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ export class Scope implements ScopeInterface {
193193
email: undefined,
194194
id: undefined,
195195
ip_address: undefined,
196-
segment: undefined,
197196
username: undefined,
198197
};
199198

packages/core/src/server-runtime-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,6 @@ export class ServerRuntimeClient<
275275
return [dsc, traceContext];
276276
}
277277

278-
return [getDynamicSamplingContextFromClient(traceId, this, scope), traceContext];
278+
return [getDynamicSamplingContextFromClient(traceId, this), traceContext];
279279
}
280280
}

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { Client, DynamicSamplingContext, Scope, Span, Transaction } from '@sentry/types';
1+
import type { Client, DynamicSamplingContext, Span, Transaction } from '@sentry/types';
22
import { dropUndefinedKeys } from '@sentry/utils';
33

44
import { DEFAULT_ENVIRONMENT } from '../constants';
5-
import { getClient, getCurrentScope } from '../exports';
5+
import { getClient } from '../exports';
66
import { getRootSpan } from '../utils/getRootSpan';
77
import { spanIsSampled, spanToJSON } from '../utils/spanUtils';
88

@@ -11,22 +11,14 @@ import { spanIsSampled, spanToJSON } from '../utils/spanUtils';
1111
*
1212
* Dispatches the `createDsc` lifecycle hook as a side effect.
1313
*/
14-
export function getDynamicSamplingContextFromClient(
15-
trace_id: string,
16-
client: Client,
17-
scope?: Scope,
18-
): DynamicSamplingContext {
14+
export function getDynamicSamplingContextFromClient(trace_id: string, client: Client): DynamicSamplingContext {
1915
const options = client.getOptions();
2016

2117
const { publicKey: public_key } = client.getDsn() || {};
22-
// TODO(v8): Remove segment from User
23-
// eslint-disable-next-line deprecation/deprecation
24-
const { segment: user_segment } = (scope && scope.getUser()) || {};
2518

2619
const dsc = dropUndefinedKeys({
2720
environment: options.environment || DEFAULT_ENVIRONMENT,
2821
release: options.release,
29-
user_segment,
3022
public_key,
3123
trace_id,
3224
}) as DynamicSamplingContext;
@@ -55,7 +47,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
5547
}
5648

5749
// passing emit=false here to only emit later once the DSC is actually populated
58-
const dsc = getDynamicSamplingContextFromClient(spanToJSON(span).trace_id || '', client, getCurrentScope());
50+
const dsc = getDynamicSamplingContextFromClient(spanToJSON(span).trace_id || '', client);
5951

6052
// TODO (v8): Remove v7FrozenDsc as a Transaction will no longer have _frozenDynamicSamplingContext
6153
const txn = getRootSpan(span) as TransactionWithV7FrozenDsc | undefined;

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ type SpanWithScopes = Span & {
399399
[ISOLATION_SCOPE_ON_START_SPAN_FIELD]?: Scope;
400400
};
401401

402+
/** Store the scope & isolation scope for a span, which can the be used when it is finished. */
402403
function setCapturedScopesOnSpan(span: Span | undefined, scope: Scope, isolationScope: Scope): void {
403404
if (span) {
404405
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('BaseClient', () => {
119119
const options = getDefaultTestClientOptions({});
120120
const client = new TestClient(options);
121121
const scope = new Scope();
122+
// eslint-disable-next-line deprecation/deprecation
122123
const hub = new Hub(client, scope);
123124

124125
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -134,6 +135,7 @@ describe('BaseClient', () => {
134135
const options = getDefaultTestClientOptions({});
135136
const client = new TestClient(options);
136137
const scope = new Scope();
138+
// eslint-disable-next-line deprecation/deprecation
137139
const hub = new Hub(client, scope);
138140

139141
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -149,6 +151,7 @@ describe('BaseClient', () => {
149151
const options = getDefaultTestClientOptions({ maxBreadcrumbs: 1 });
150152
const client = new TestClient(options);
151153
const scope = new Scope();
154+
// eslint-disable-next-line deprecation/deprecation
152155
const hub = new Hub(client, scope);
153156

154157
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -165,6 +168,7 @@ describe('BaseClient', () => {
165168
const options = getDefaultTestClientOptions({});
166169
const client = new TestClient(options);
167170
const scope = new Scope();
171+
// eslint-disable-next-line deprecation/deprecation
168172
const hub = new Hub(client, scope);
169173

170174
scope.addBreadcrumb({ message: 'hello' });
@@ -181,6 +185,7 @@ describe('BaseClient', () => {
181185
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
182186
const client = new TestClient(options);
183187
const scope = new Scope();
188+
// eslint-disable-next-line deprecation/deprecation
184189
const hub = new Hub(client, scope);
185190

186191
// eslint-disable-next-line deprecation/deprecation
@@ -196,6 +201,7 @@ describe('BaseClient', () => {
196201
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
197202
const client = new TestClient(options);
198203
const scope = new Scope();
204+
// eslint-disable-next-line deprecation/deprecation
199205
const hub = new Hub(client, scope);
200206

201207
// eslint-disable-next-line deprecation/deprecation
@@ -211,6 +217,7 @@ describe('BaseClient', () => {
211217
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
212218
const client = new TestClient(options);
213219
const scope = new Scope();
220+
// eslint-disable-next-line deprecation/deprecation
214221
const hub = new Hub(client, scope);
215222

216223
// eslint-disable-next-line deprecation/deprecation
@@ -226,6 +233,7 @@ describe('BaseClient', () => {
226233
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
227234
const client = new TestClient(options);
228235
const scope = new Scope();
236+
// eslint-disable-next-line deprecation/deprecation
229237
const hub = new Hub(client, scope);
230238

231239
// eslint-disable-next-line deprecation/deprecation
@@ -620,6 +628,7 @@ describe('BaseClient', () => {
620628
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, maxBreadcrumbs: 1 });
621629
const client = new TestClient(options);
622630
const scope = new Scope();
631+
// eslint-disable-next-line deprecation/deprecation
623632
const hub = new Hub(client, scope);
624633
// eslint-disable-next-line deprecation/deprecation
625634
hub.addBreadcrumb({ message: '1' });

0 commit comments

Comments
 (0)