-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
f4ad13b
a6a1852
c458fad
6a1b85d
87b44d8
bc72cd4
bf3e03f
43d5df0
e46eafb
9f3719a
cd1cd37
5918343
418f6b6
c31d9a2
4879fab
8f840e2
df69823
File filter
Filter by extension
Conversations
Jump to
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
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? 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 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { addTracingExtensions, getMainCarrier } from '@sentry/core'; | ||
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? 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(); | ||
} |
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.