envelop icon indicating copy to clipboard operation
envelop copied to clipboard

Adds the root sentry span to a resolver's context

Open orta opened this issue 2 years ago β€’ 12 comments

Description

Hello folks, I was going through Sentry tracing, and I needed access to set my parent span on a transaction. Now, this is reasonably easy to do via:

const opScope = Sentry.getCurrentHub().getScope()?.getSpan()

But relying on a bunch of globals feels a little bit off for me, when context is really what this sort of thing is for (IMO.) So, this PR adds span into the operation context. I've scoped it into a sentry object - in case there more things added further down the line.

Type of change

Please delete options that are not relevant.

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] This change requires a documentation update (maybe?)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [x] Tests

Checklist:

  • [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented on my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [x] Any dependent changes have been merged and published in downstream modules

orta avatar Jan 07 '23 17:01 orta

πŸ¦‹ Changeset detected

Latest commit: 01624ef17666bdcc90e6c86c3118acf4cc7dfedf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@envelop/sentry Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jan 07 '23 17:01 changeset-bot[bot]

FAIL packages/plugins/sentry/__tests__/sentry.spec.ts
  ● sentry β€Ί report unexpected error

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

It seems surprising that my code would change the error handling? Is it known to be flaky?

orta avatar Jan 07 '23 17:01 orta

@orta can you add a changeset?

saihaj avatar Jan 13 '23 16:01 saihaj

Looks like just need to run prettier @orta

saihaj avatar Jan 21 '23 09:01 saihaj

on the markdown that gets thrown away? That should be in the exceptions

orta avatar Jan 21 '23 14:01 orta

@n1ru4l @saihaj Can we get this merged? πŸ™πŸ»

jeengbe avatar Feb 08 '23 19:02 jeengbe

CI is failing :/

ardatan avatar Feb 08 '23 19:02 ardatan

CI is failing :/

Rerun it? All but one appear fineπŸ˜„

And Orta is right with Prettier; .changeset shouldn't be linted

jeengbe avatar Feb 08 '23 19:02 jeengbe

@jeengbe Unit tests are failing :)

ardatan avatar Feb 08 '23 19:02 ardatan

@jeengbe Unit tests are failing :)

Run it once more, it worked locally on the second attempt πŸ™‚

jeengbe avatar Feb 08 '23 19:02 jeengbe

@ardatan @orta See https://github.com/orta/envelop/pull/1

jeengbe avatar Feb 08 '23 19:02 jeengbe

In response to https://github.com/getsentry/sentry-javascript/discussions/7083#discussioncomment-4918660, this might actually be the wrong solution to this problem. Instead, a PR that integrates this domain thing would probably be the better solution as that would truly ensure all child spans are set correctly.

jeengbe avatar Feb 09 '23 13:02 jeengbe