Skip to content
  • Sponsor getsentry/sentry-javascript

  • Notifications You must be signed in to change notification settings
  • Fork 1.7k

Commit 53d814b

Browse files
authoredMay 22, 2024··
ref: Fix circular dependency checks & setup (#12159)
I noticed we were getting some build warnings for circular dependency issues, which indicated that madge was not correctly capturing all issues. So I went ahead and updated madge to latest, and aligned the setup, which actually surfaced problems again more correctly. I also fixed all the circular dep issues that were raised there. We still have a bunch of types-related circular deps but these are hard to solve, so let's ignore this for now.
1 parent 772269a commit 53d814b

24 files changed

+338
-403
lines changed
 

‎.madgerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"detectiveOptions": {
3+
"ts": {
4+
"skipTypeImports": true
5+
}
6+
}
7+
}

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"jest-environment-node": "^27.5.1",
115115
"jsdom": "^21.1.2",
116116
"lerna": "7.1.1",
117-
"madge": "4.0.2",
117+
"madge": "7.0.0",
118118
"nodemon": "^2.0.16",
119119
"npm-run-all": "^4.1.5",
120120
"prettier": "^3.1.1",

‎packages/bun/package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,5 @@
7676
"volta": {
7777
"extends": "../../package.json"
7878
},
79-
"sideEffects": false,
80-
"madge": {
81-
"detectiveOptions": {
82-
"ts": {
83-
"skipTypeImports": true
84-
}
85-
}
86-
}
79+
"sideEffects": false
8780
}

‎packages/core/package.json

-7
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,5 @@
6969
"volta": {
7070
"extends": "../../package.json"
7171
},
72-
"madge": {
73-
"detectiveOptions": {
74-
"ts": {
75-
"skipTypeImports": true
76-
}
77-
}
78-
},
7972
"sideEffects": false
8073
}

‎packages/core/src/asyncContext/stackStrategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Client, Scope as ScopeInterface } from '@sentry/types';
22
import { isThenable } from '@sentry/utils';
3-
import { getDefaultCurrentScope, getDefaultIsolationScope } from '../currentScopes';
3+
import { getDefaultCurrentScope, getDefaultIsolationScope } from '../defaultScopes';
44
import { Scope } from '../scope';
55

66
import { getMainCarrier, getSentryCarrier } from './../carrier';

‎packages/core/src/currentScopes.ts

-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import { getAsyncContextStrategy } from './asyncContext';
55
import { getMainCarrier } from './carrier';
66
import { Scope as ScopeClass } from './scope';
77

8-
/** Get the default current scope. */
9-
export function getDefaultCurrentScope(): Scope {
10-
return getGlobalSingleton('defaultCurrentScope', () => new ScopeClass());
11-
}
12-
13-
/** Get the default isolation scope. */
14-
export function getDefaultIsolationScope(): Scope {
15-
return getGlobalSingleton('defaultIsolationScope', () => new ScopeClass());
16-
}
17-
188
/**
199
* Get the currently active scope.
2010
*/

‎packages/core/src/defaultScopes.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Scope } from '@sentry/types';
2+
import { getGlobalSingleton } from '@sentry/utils';
3+
import { Scope as ScopeClass } from './scope';
4+
5+
/** Get the default current scope. */
6+
export function getDefaultCurrentScope(): Scope {
7+
return getGlobalSingleton('defaultCurrentScope', () => new ScopeClass());
8+
}
9+
10+
/** Get the default isolation scope. */
11+
export function getDefaultIsolationScope(): Scope {
12+
return getGlobalSingleton('defaultIsolationScope', () => new ScopeClass());
13+
}

‎packages/core/src/envelope.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
getSdkMetadataForEnvelopeHeader,
2323
} from '@sentry/utils';
2424
import { createSpanEnvelopeItem } from '@sentry/utils';
25-
import { type SentrySpan, getDynamicSamplingContextFromSpan } from './tracing';
25+
import { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';
26+
import type { SentrySpan } from './tracing/sentrySpan';
2627
import { spanToJSON } from './utils/spanUtils';
2728

2829
/**

‎packages/core/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export {
3838
withScope,
3939
withIsolationScope,
4040
getClient,
41+
} from './currentScopes';
42+
export {
4143
getDefaultCurrentScope,
4244
getDefaultIsolationScope,
43-
} from './currentScopes';
45+
} from './defaultScopes';
4446
export { setAsyncContextStrategy } from './asyncContext';
4547
export { getMainCarrier } from './carrier';
4648
export { makeSession, closeSession, updateSession } from './session';
@@ -69,7 +71,6 @@ export { handleCallbackErrors } from './utils/handleCallbackErrors';
6971
export { parameterize } from './utils/parameterize';
7072
export {
7173
spanToTraceHeader,
72-
spanToBaggageHeader,
7374
spanToJSON,
7475
spanIsSampled,
7576
spanToTraceContext,

‎packages/core/src/tracing/dynamicSamplingContext.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { Client, DynamicSamplingContext, Span } from '@sentry/types';
2-
import { addNonEnumerableProperty, dropUndefinedKeys } from '@sentry/utils';
2+
import {
3+
addNonEnumerableProperty,
4+
dropUndefinedKeys,
5+
dynamicSamplingContextToSentryBaggageHeader,
6+
} from '@sentry/utils';
37

48
import { DEFAULT_ENVIRONMENT } from '../constants';
59
import { getClient } from '../currentScopes';
@@ -93,3 +97,11 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
9397

9498
return dsc;
9599
}
100+
101+
/**
102+
* Convert a Span to a baggage header.
103+
*/
104+
export function spanToBaggageHeader(span: Span): string | undefined {
105+
const dsc = getDynamicSamplingContextFromSpan(span);
106+
return dynamicSamplingContextToSentryBaggageHeader(dsc);
107+
}

‎packages/core/src/tracing/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export {
1818
withActiveSpan,
1919
suppressTracing,
2020
} from './trace';
21-
export { getDynamicSamplingContextFromClient, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
21+
export {
22+
getDynamicSamplingContextFromClient,
23+
getDynamicSamplingContextFromSpan,
24+
spanToBaggageHeader,
25+
} from './dynamicSamplingContext';
2226
export { setMeasurement, timedEventsToMeasurements } from './measurement';
2327
export { sampleSpan } from './sampling';
2428
export { logSpanEnd, logSpanStart } from './logSpans';

‎packages/core/src/utils/spanUtils.ts

-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
import {
1313
addNonEnumerableProperty,
1414
dropUndefinedKeys,
15-
dynamicSamplingContextToSentryBaggageHeader,
1615
generateSentryTraceHeader,
1716
timestampInSeconds,
1817
} from '@sentry/utils';
@@ -22,7 +21,6 @@ import { getCurrentScope } from '../currentScopes';
2221
import { getMetricSummaryJsonForSpan, updateMetricSummaryOnSpan } from '../metrics/metric-summary';
2322
import type { MetricType } from '../metrics/types';
2423
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
25-
import { getDynamicSamplingContextFromSpan } from '../tracing';
2624
import type { SentrySpan } from '../tracing/sentrySpan';
2725
import { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus';
2826
import { _getSpanForScope } from './spanOnScope';
@@ -70,14 +68,6 @@ export function spanToTraceHeader(span: Span): string {
7068
return generateSentryTraceHeader(traceId, spanId, sampled);
7169
}
7270

73-
/**
74-
* Convert a Span to a baggage header.
75-
*/
76-
export function spanToBaggageHeader(span: Span): string | undefined {
77-
const dsc = getDynamicSamplingContextFromSpan(span);
78-
return dynamicSamplingContextToSentryBaggageHeader(dsc);
79-
}
80-
8171
/**
8272
* Convert a span time input intp a timestamp in seconds.
8373
*/

‎packages/deno/package.json

-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@
6363
"extends": "../../package.json"
6464
},
6565
"sideEffects": false,
66-
"madge": {
67-
"detectiveOptions": {
68-
"ts": {
69-
"skipTypeImports": true
70-
}
71-
}
72-
},
7366
"nx": {
7467
"targets": {
7568
"build:transpile": {

‎packages/node/src/integrations/anr/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as inspector from 'node:inspector';
22
import { Worker } from 'node:worker_threads';
3-
import { defineIntegration, mergeScopeData } from '@sentry/core';
3+
import { defineIntegration, getCurrentScope, getGlobalScope, getIsolationScope, mergeScopeData } from '@sentry/core';
44
import type { Contexts, Event, EventHint, Integration, IntegrationFn, ScopeData } from '@sentry/types';
55
import { GLOBAL_OBJ, logger } from '@sentry/utils';
6-
import { getCurrentScope, getGlobalScope, getIsolationScope } from '../..';
76
import { NODE_VERSION } from '../../nodeVersion';
87
import type { NodeClient } from '../../sdk/client';
98
import type { AnrIntegrationOptions, WorkerStartData } from './common';

‎packages/node/src/sdk/init.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ import { spotlightIntegration } from '../integrations/spotlight';
3737
import { getAutoPerformanceIntegrations } from '../integrations/tracing';
3838
import { makeNodeTransport } from '../transports';
3939
import type { NodeClientOptions, NodeOptions } from '../types';
40+
import { isCjs } from '../utils/commonjs';
4041
import { defaultStackParser, getSentryRelease } from './api';
4142
import { NodeClient } from './client';
4243
import { initOpenTelemetry } from './initOtel';
4344

44-
/** Detect CommonJS. */
45-
export function isCjs(): boolean {
46-
return typeof require !== 'undefined';
47-
}
48-
4945
function getCjsOnlyIntegrations(): Integration[] {
5046
return isCjs() ? [modulesIntegration()] : [];
5147
}

‎packages/node/src/utils/commonjs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** Detect CommonJS. */
2+
export function isCjs(): boolean {
3+
return typeof require !== 'undefined';
4+
}

‎packages/node/src/utils/ensureIsWrapped.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isWrapped } from '@opentelemetry/core';
22
import { hasTracingEnabled, isEnabled } from '@sentry/core';
33
import { consoleSandbox } from '@sentry/utils';
4-
import { isCjs } from '../sdk/init';
4+
import { isCjs } from './commonjs';
55

66
/**
77
* Checks and warns if a framework isn't wrapped by opentelemetry.

‎packages/types/src/event.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { Thread } from './thread';
1616
import type { TransactionSource } from './transaction';
1717
import type { User } from './user';
1818

19-
/** JSDoc */
19+
/** An event to be sent to Sentry. */
2020
export interface Event {
2121
event_id?: string;
2222
message?: string;

‎packages/types/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from
121121
export type { PropagationContext, TracePropagationTargets } from './tracing';
122122
export type { StartSpanOptions } from './startSpanOptions';
123123
export type {
124-
CustomSamplingContext,
125-
SamplingContext,
126124
TraceparentData,
127125
TransactionSource,
128126
} from './transaction';
127+
export type { CustomSamplingContext, SamplingContext } from './samplingcontext';
129128
export type {
130129
DurationUnit,
131130
InformationUnit,

‎packages/types/src/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
22
import type { ErrorEvent, EventHint, TransactionEvent } from './event';
33
import type { Integration } from './integration';
4+
import type { SamplingContext } from './samplingcontext';
45
import type { CaptureContext } from './scope';
56
import type { SdkMetadata } from './sdkmetadata';
67
import type { SpanJSON } from './span';
78
import type { StackLineParser, StackParser } from './stacktrace';
89
import type { TracePropagationTargets } from './tracing';
9-
import type { SamplingContext } from './transaction';
1010
import type { BaseTransportOptions, Transport } from './transport';
1111

1212
export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOptions> {

‎packages/types/src/samplingcontext.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { ExtractedNodeRequestData, WorkerLocation } from './misc';
2+
import type { SpanAttributes } from './span';
3+
4+
/**
5+
* Context data passed by the user when starting a transaction, to be used by the tracesSampler method.
6+
*/
7+
export interface CustomSamplingContext {
8+
[key: string]: any;
9+
}
10+
11+
/**
12+
* Data passed to the `tracesSampler` function, which forms the basis for whatever decisions it might make.
13+
*
14+
* Adds default data to data provided by the user. See {@link Hub.startTransaction}
15+
*/
16+
export interface SamplingContext extends CustomSamplingContext {
17+
/**
18+
* Context data with which transaction being sampled was created.
19+
* @deprecated This is duplicate data and will be removed eventually.
20+
*/
21+
transactionContext: {
22+
name: string;
23+
parentSampled?: boolean | undefined;
24+
};
25+
26+
/**
27+
* Sampling decision from the parent transaction, if any.
28+
*/
29+
parentSampled?: boolean;
30+
31+
/**
32+
* Object representing the URL of the current page or worker script. Passed by default when using the `BrowserTracing`
33+
* integration.
34+
*/
35+
location?: WorkerLocation;
36+
37+
/**
38+
* Object representing the incoming request to a node server. Passed by default when using the TracingHandler.
39+
*/
40+
request?: ExtractedNodeRequestData;
41+
42+
/** The name of the span being sampled. */
43+
name: string;
44+
45+
/** Initial attributes that have been passed to the span being sampled. */
46+
attributes?: SpanAttributes;
47+
}

‎packages/types/src/transaction.ts

-48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type { ExtractedNodeRequestData, WorkerLocation } from './misc';
2-
import type { SpanAttributes } from './span';
3-
41
/**
52
* Data pulled from a `sentry-trace` header
63
*/
@@ -21,51 +18,6 @@ export interface TraceparentData {
2118
parentSampled?: boolean | undefined;
2219
}
2320

24-
/**
25-
* Context data passed by the user when starting a transaction, to be used by the tracesSampler method.
26-
*/
27-
export interface CustomSamplingContext {
28-
[key: string]: any;
29-
}
30-
31-
/**
32-
* Data passed to the `tracesSampler` function, which forms the basis for whatever decisions it might make.
33-
*
34-
* Adds default data to data provided by the user. See {@link Hub.startTransaction}
35-
*/
36-
export interface SamplingContext extends CustomSamplingContext {
37-
/**
38-
* Context data with which transaction being sampled was created.
39-
* @deprecated This is duplicate data and will be removed eventually.
40-
*/
41-
transactionContext: {
42-
name: string;
43-
parentSampled?: boolean | undefined;
44-
};
45-
46-
/**
47-
* Sampling decision from the parent transaction, if any.
48-
*/
49-
parentSampled?: boolean;
50-
51-
/**
52-
* Object representing the URL of the current page or worker script. Passed by default when using the `BrowserTracing`
53-
* integration.
54-
*/
55-
location?: WorkerLocation;
56-
57-
/**
58-
* Object representing the incoming request to a node server. Passed by default when using the TracingHandler.
59-
*/
60-
request?: ExtractedNodeRequestData;
61-
62-
/** The name of the span being sampled. */
63-
name: string;
64-
65-
/** Initial attributes that have been passed to the span being sampled. */
66-
attributes?: SpanAttributes;
67-
}
68-
6921
/**
7022
* Contains information about how the name of the transaction was determined. This will be used by the server to decide
7123
* whether or not to scrub identifiers from the transaction name, or replace the entire name with a placeholder.

‎packages/vercel-edge/package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,5 @@
7373
"volta": {
7474
"extends": "../../package.json"
7575
},
76-
"sideEffects": false,
77-
"madge": {
78-
"detectiveOptions": {
79-
"ts": {
80-
"skipTypeImports": true
81-
}
82-
}
83-
}
76+
"sideEffects": false
8477
}

‎yarn.lock

+234-286
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.