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

ref(replay): Send SDK's name in replay event #6514

Merged
merged 4 commits into from
Dec 14, 2022
Merged

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Dec 13, 2022

This PR replaces the sentry.javascript.integration.replay name in event.sdk.name with the actual Sentry SDK name (e.g. sentry.javascript.browser), analogously to how we send SDK metadata in other event types.

Going forward, we can can also use this information e.g. for data analysis to filter replay events by SDK

ref #6366

@Lms24 Lms24 requested review from billyvg and mydea December 13, 2022 13:41
@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.72 KB (-0.02% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.13 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.51 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 54.66 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.28 KB (0%)
@sentry/browser - Webpack (minified) 66.33 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.3 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.5 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.69 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.14 KB (0%)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 41.72 KB (+0.02% 🔺)
@sentry/replay - Webpack (gzipped + minified) 37.98 KB (0%)

return createEnvelope(
{
event_id: replayId,
sent_at: new Date().toISOString(),
sdk: REPLAY_SDK_INFO,
sdk: { name, version },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Should we maybe just pass sdk: replayEvent.sdk here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For envelopes in the SDK, we only send name and version in the header:

/** Extract sdk info from from the API metadata */
function getSdkMetadataForEnvelopeHeader(metadata?: SdkMetadata): SdkInfo | undefined {
if (!metadata || !metadata.sdk) {
return;
}
const { name, version } = metadata.sdk;
return { name, version };
}

According to the dev spec, we can send the entire sdk object though, so we could change it... I think for now we should go with SDK consistency, WDYT? Keeps the envelope a little smaller if we don't pass the integrations array twice for instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, ok, I see. Sorry, this was/is a bit confusing for me, what goes on the event vs. what goes on the envelope 😅

// extract the SDK name because `client._prepareEvent` doesn't add it to the event
const metadata = client.getOptions() && client.getOptions()._metadata;
const { name } = (metadata && metadata.sdk) || {};

preparedEvent.sdk = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: IMHO we don't need to overwrite this like that, as it will never be set. I'd just do:

preparedEvent.sdk = {
  name, 
  version: 'xxx'
}

Or, maybe export the getSdkMetadataForEnvelopeHeader function or similar from core and use that somehow (but I'd say that's optional).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use the ...preparedEvent.sdk spread, we don't add the entire SDK metadata to the event. For instance, the integrations array won't be added. I think it's fine to omit it in the envelope header but I don't know if we should remove it from the event.

getSdkMetadataForEnvelopeHeader would only make sense for constructing the envelope header. I'll take a look if this reduces bundle size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can use getSdkMetadataForEnvelopeHeader. Will do this in a follow-up PR though, as it involves moving stuff around.

@Lms24 Lms24 mentioned this pull request Dec 13, 2022
3 tasks
@Lms24 Lms24 merged commit e04d2fc into master Dec 14, 2022
@Lms24 Lms24 deleted the lms-replay-ref-sdkname branch December 14, 2022 10:24
Lms24 added a commit that referenced this pull request Dec 16, 2022
)

As outlined in #6539, we were previosuly not sending the `dsn` key in the replay event [envelope header](https://develop.sentry.dev/sdk/envelopes/#envelope-headers), thereby not including the necessary information to forward the event to Sentry. 

This patch fixes that by extracting the `createEventEnvelopeHeaders` function to utils so that we can use it in Replay (analogously to #6514), as well as using this function to create all headers. 

We tested the change with NextJS' `tunnelRoute` as well as with the conventional `tunnel` option and everything seems to work now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants