Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(tracing): Move common tracing code to core#7339
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f4ad13ba6a1852c458fad6a1b85d87b44d8bc72cd4bf3e03f43d5df0e46eafb9f3719acd1cd375918343418f6b6c31d9a24879fab8f840e2df69823File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export { startIdleTransaction, addTracingExtensions } from './hubextensions'; | ||
| export { IdleTransaction, TRACING_DEFAULTS } from './idletransaction'; | ||
| export { Span, spanStatusfromHttpCode } from './span'; | ||
| export { Transaction } from './transaction'; | ||
| export { extractTraceparentData, getActiveTransaction, stripUrlQueryAndFragment, TRACEPARENT_REGEXP } from './utils'; | ||
| // eslint-disable-next-line deprecation/deprecation | ||
| export { SpanStatus } from './spanstatus'; | ||
| export type { SpanStatusType } from './span'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| import type { Hub } from '@sentry/core'; | ||
| import { DEFAULT_ENVIRONMENT, getCurrentHub } from '@sentry/core'; | ||
| import type { | ||
| Context, | ||
| Contexts, | ||
| @@ -13,6 +11,9 @@ import type { | ||
| } from '@sentry/types'; | ||
| import { dropUndefinedKeys, logger } from '@sentry/utils'; | ||
| import { DEFAULT_ENVIRONMENT } from '../constants'; | ||
| import type { Hub } from '../hub'; | ||
Comment on lines
+14
to
+15
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: Do we want to point these to the actual definitions instead of to index? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the imports to use Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope all good | ||
| import { getCurrentHub } from '../hub'; | ||
| import { Span as SpanClass, SpanRecorder } from './span'; | ||
| /** JSDoc */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import type { Hub } from '@sentry/core'; | ||
| import { getCurrentHub, hasTracingEnabled as _hasTracingEnabled } from '@sentry/core'; | ||
| import type { Options, Transaction } from '@sentry/types'; | ||
| import type { Transaction } from '@sentry/types'; | ||
| import type { Hub } from '../hub'; | ||
| import { getCurrentHub } from '../hub'; | ||
Comment on lines
+3
to
+4
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. | ||
| /** | ||
| * The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used | ||
| @@ -16,40 +17,12 @@ import type { Options, Transaction } from '@sentry/types'; | ||
| */ | ||
| export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils'; | ||
| /** | ||
| * Determines if tracing is currently enabled. | ||
| * | ||
| * Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config. | ||
| * @deprecated This export has moved to `@sentry/core`. This export will be removed from `@sentry/tracing` in v8. | ||
| */ | ||
| export function hasTracingEnabled( | ||
| maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler' | 'enableTracing'> | undefined, | ||
| ): boolean { | ||
| return _hasTracingEnabled(maybeOptions); | ||
| } | ||
| /** Grabs active transaction off scope, if any */ | ||
| export function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined { | ||
| const hub = maybeHub || getCurrentHub(); | ||
| const scope = hub.getScope(); | ||
| return scope && (scope.getTransaction() as T | undefined); | ||
| } | ||
| /** | ||
| * Converts from milliseconds to seconds | ||
| * @param time time in ms | ||
| */ | ||
| export function msToSec(time: number): number { | ||
| return time / 1000; | ||
| } | ||
| /** | ||
| * Converts from seconds to milliseconds | ||
| * @param time time in seconds | ||
| */ | ||
| export function secToMs(time: number): number { | ||
| return time * 1000; | ||
| } | ||
| // so it can be used in manual instrumentation without necessitating a hard dependency on @sentry/utils | ||
| export { stripUrlQueryAndFragment } from '@sentry/utils'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,6 +36,8 @@ export declare const ErrorBoundary: typeof clientSdk.ErrorBoundary; | ||
| export declare const showReportDialog: typeof clientSdk.showReportDialog; | ||
| export declare const withErrorBoundary: typeof clientSdk.withErrorBoundary; | ||
| export declare const Span: typeof edgeSdk.Span; | ||
AbhiPrasad marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * @deprecated Use `wrapApiHandlerWithSentry` instead | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| /* eslint-disable max-lines */ | ||
| import type { IdleTransaction, Transaction } from '@sentry/core'; | ||
| import { getActiveTransaction } from '@sentry/core'; | ||
| import type { Measurements } from '@sentry/types'; | ||
| import { browserPerformanceTimeOrigin, htmlTreeAsString, logger } from '@sentry/utils'; | ||
| import type { IdleTransaction } from '../../idletransaction'; | ||
| import type { Transaction } from '../../transaction'; | ||
| import { getActiveTransaction, msToSec } from '../../utils'; | ||
| import { WINDOW } from '../types'; | ||
| import { onCLS } from '../web-vitals/getCLS'; | ||
| import { onFID } from '../web-vitals/getFID'; | ||
| @@ -14,6 +13,14 @@ import { observe } from '../web-vitals/lib/observe'; | ||
| import type { NavigatorDeviceMemory, NavigatorNetworkInformation } from '../web-vitals/types'; | ||
| import { _startChild, isMeasurementValue } from './utils'; | ||
| /** | ||
| * Converts from milliseconds to seconds | ||
| * @param time time in ms | ||
| */ | ||
| function msToSec(time: number): number { | ||
| return time / 1000; | ||
| } | ||
AbhiPrasad marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| function getBrowserPerformanceAPI(): Performance | undefined { | ||
| return WINDOW && WINDOW.addEventListener && WINDOW.performance; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { addTracingExtensions, getMainCarrier } from '@sentry/core'; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the content of this file will be moved entirely to Node in the future, right? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it will! For now it should be completely tree-shaken out. | ||
| import type { Integration, IntegrationClass } from '@sentry/types'; | ||
| import { dynamicRequire, isNodeEnv, loadModule } from '@sentry/utils'; | ||
| import { registerErrorInstrumentation } from './errors'; | ||
| /** | ||
| * @private | ||
| */ | ||
| function _autoloadDatabaseIntegrations(): void { | ||
| const carrier = getMainCarrier(); | ||
| if (!carrier.__SENTRY__) { | ||
| return; | ||
| } | ||
| const packageToIntegrationMapping: Record<string, () => Integration> = { | ||
| mongodb() { | ||
| const integration = dynamicRequire(module, './integrations/node/mongo') as { | ||
| Mongo: IntegrationClass<Integration>; | ||
| }; | ||
| return new integration.Mongo(); | ||
| }, | ||
| mongoose() { | ||
| const integration = dynamicRequire(module, './integrations/node/mongo') as { | ||
| Mongo: IntegrationClass<Integration>; | ||
| }; | ||
| return new integration.Mongo({ mongoose: true }); | ||
| }, | ||
| mysql() { | ||
| const integration = dynamicRequire(module, './integrations/node/mysql') as { | ||
| Mysql: IntegrationClass<Integration>; | ||
| }; | ||
| return new integration.Mysql(); | ||
| }, | ||
| pg() { | ||
| const integration = dynamicRequire(module, './integrations/node/postgres') as { | ||
| Postgres: IntegrationClass<Integration>; | ||
| }; | ||
| return new integration.Postgres(); | ||
| }, | ||
| }; | ||
| const mappedPackages = Object.keys(packageToIntegrationMapping) | ||
| .filter(moduleName => !!loadModule(moduleName)) | ||
| .map(pkg => { | ||
| try { | ||
| return packageToIntegrationMapping[pkg](); | ||
| } catch (e) { | ||
| return undefined; | ||
| } | ||
| }) | ||
| .filter(p => p) as Integration[]; | ||
| if (mappedPackages.length > 0) { | ||
| carrier.__SENTRY__.integrations = [...(carrier.__SENTRY__.integrations || []), ...mappedPackages]; | ||
| } | ||
| } | ||
| /** | ||
| * This patches the global object and injects the Tracing extensions methods | ||
| */ | ||
| export function addExtensionMethods(): void { | ||
| addTracingExtensions(); | ||
| // Detect and automatically load specified integrations. | ||
| if (isNodeEnv()) { | ||
| _autoloadDatabaseIntegrations(); | ||
| } | ||
| // If an error happens globally, we should make sure transaction status is set to error. | ||
| registerErrorInstrumentation(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Can we mark this as deprecated out of caution. I think we wanna move to dependency injection rather than functions with side-effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this in a follow up PR since we should make the deprecations the final step after we've moved everything over.