-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(core): Add withIsolationScope
#10141
Changes from 5 commits
690ab9a
f7198a3
23bc6f3
fcc7507
00a1d01
16ed40c
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sent | |
import { DEFAULT_ENVIRONMENT } from './constants'; | ||
import { DEBUG_BUILD } from './debug-build'; | ||
import type { Hub } from './hub'; | ||
import { runWithAsyncContext } from './hub'; | ||
import { getCurrentHub, getIsolationScope } from './hub'; | ||
import type { Scope } from './scope'; | ||
import { closeSession, makeSession, updateSession } from './session'; | ||
|
@@ -208,6 +209,15 @@ export function withScope<T>( | |
return getCurrentHub().withScope(rest[0]); | ||
} | ||
|
||
/** | ||
* TODO | ||
*/ | ||
export function withIsolationScope<T>(callback: (isolationScope: Scope) => T): T { | ||
return runWithAsyncContext(() => { | ||
return callback(getIsolationScope()); | ||
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. to sanity check: 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. Technically the answer to your question is no. (Side note: This is also the reason why I didn't add any forking tests in the core package, simply because we cannot make this assumption.) 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. Right sorry, it's the async context strategy that takes care of it. |
||
}); | ||
} | ||
|
||
/** | ||
* Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ export { | |
setTags, | ||
setUser, | ||
withScope, | ||
withIsolationScope, | ||
getClient, | ||
getCurrentScope, | ||
startSession, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { getCurrentHub, runWithAsyncContext } from '../../src'; | ||
|
||
describe('runWithAsyncContext()', () => { | ||
it('without strategy hubs should be equal', () => { | ||
runWithAsyncContext(() => { | ||
const hub1 = getCurrentHub(); | ||
runWithAsyncContext(() => { | ||
const hub2 = getCurrentHub(); | ||
expect(hub1).toBe(hub2); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
I think there's still something missing 😅
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.
Thank you!