Skip to content
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

add synchronous scope manager #1252

Merged
merged 1 commit into from May 19, 2021
Merged

add synchronous scope manager #1252

merged 1 commit into from May 19, 2021

Conversation

rochdev
Copy link
Member

@rochdev rochdev commented Feb 24, 2021

What does this PR do?

Add synchronous scope manager.

Motivation

Because of the issue with async_hooks, there are cases where it's not possible to track the asynchronous context. However, our auto-instrumentation expects to always be able to get the parent span from the scope manager, which makes the it unusable when scope management is completely disabled. This new scope manager works around this issue by allowing to manually re-activate a span on a synchronous scope to make it available when the integration starts its own span.

For example:

tracer.trace('parent', parent => {
  setImmediate(() => {
    // here `tracer.scope().active() is null instead of `parent`
    // calling for example `http.get` would result in a disconnected trace

    return tracer.scope().activate(parent, () => {
      // tracer.scope().active() is now `parent` so the `http` plugin will have access to it
      return http.get('some-url', res => {
        // here the correct scope is restored by the `http` plugin
      })
    })
  })
})

While the async_hooks issue should be fixed in a few months, in the meantime this allows to continue using auto-instrumentation by manually connecting spans from integrations together. The code is extremely simple so it also doesn't add unnecessary maintenance overhead after the fix will have landed.

@rochdev rochdev added enhancement New feature or request core labels Feb 24, 2021
@rochdev rochdev added this to the 0.32.0 milestone Feb 24, 2021
@rochdev rochdev requested a review from a team as a code owner February 24, 2021 17:07
@rochdev rochdev modified the milestones: 0.32.0, 0.34.0 May 19, 2021
@rochdev rochdev merged commit 38327b4 into master May 19, 2021
@rochdev rochdev deleted the sync-scope branch May 19, 2021 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants