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

feat(js-sdk): use js transport #2563

Draft
wants to merge 23 commits into
base: feat/js-sdk-integration
Choose a base branch
from

Conversation

buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Jan 8, 2025

📜 Description

Uses js sendEnvelope from the JS SDK transport

💡 Motivation and Context

Part of JS SDK Integration

💚 How did you test it?

Unit test, Integration test, manual

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

#skip-changelog

@buenaflor buenaflor changed the base branch from main to feat/js-sdk-integration January 8, 2025 15:35
Copy link
Contributor

github-actions bot commented Jan 8, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against bfcac4d

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 87.09%. Comparing base (be08651) to head (bfcac4d).
Report is 84 commits behind head on feat/js-sdk-integration.

Files with missing lines Patch % Lines
flutter/lib/src/native/sentry_native_channel.dart 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##           feat/js-sdk-integration    #2563       +/-   ##
============================================================
+ Coverage                    70.98%   87.09%   +16.10%     
============================================================
  Files                           17      265      +248     
  Lines                          579     9258     +8679     
============================================================
+ Hits                           411     8063     +7652     
- Misses                         168     1195     +1027     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -104,6 +104,11 @@ class SentryNative with SentryNativeSafeInvoker implements SentryNativeBinding {
throw UnsupportedError('$SentryNative.captureEnvelope() is not supported');
}

@override
FutureOr<void> captureEnvelopeObject(SentryEnvelope envelope) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a particular reason why it's called captureEnvelopeObject instead of just captureEnvelope?

Copy link
Contributor Author

@buenaflor buenaflor Jan 9, 2025

Choose a reason for hiding this comment

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

captureEnvelope already exists which only takes Uint8List and dart sadly doesnt support method overloading, we could theoretically use captureEnvelope but then we would have to convert it back to an envelope object which is unnecessary so that's why I added another captureEnvelope that is supposed to use the actual envelope object and not any other data structure

Copy link
Contributor Author

@buenaflor buenaflor Jan 9, 2025

Choose a reason for hiding this comment

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

other options is to just add another parameter SentryEnvelope envelope to the existing captureEnvelope but imo I'd prefer to have a second function since we dont have union types in dart, maybe in Dart 3 with sealed classes

// options aren't available until after the options callback executes.
if (!options.platformChecker.isWeb) {
options.transport = FileSystemTransport(_native!, options);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to set options.transport = JavascriptTransport(_web, options); in the else path here? Then i'd would be in the same place for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not possible here since this is happening within SentryFlutter.init where the option is not yet evaluated and we only use the JS SDK if enableSentryJs = true (it's false by default) so the options callback is not evaluated and it will always be false here

I added the comment above that, maybe the comment can be improved to clarify this better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will be possible for v9 where we use the JS SDK by default

tryCatchAsync('captureEnvelopeObject', () async {
final List<dynamic> envelopeItems = [];

for (final item in envelope.items) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

SentryEnvelopeItemPayload is there because we need the actual json object and not the data, right?

Right now we have some redundancy with dataFactory, maybe we can refactor this so we use the same API both here and in SentryEvent.envelopeStream?

Maybe it also makes sense to make originalObject non-optional?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The captureEnvelopeObject method does not have attachment size filtering, not sure if we need to include it here or this should be handled by the JS SDK. If we do it here, we don't have to call the JS side with data that will get dropped anyway.

// Only attachments should be filtered according to
// SentryOptions.maxAttachmentSize
if (item.header.type == SentryItemType.attachment &&
    data.length > options.maxAttachmentSize) {
  continue;
}

Copy link
Contributor Author

@buenaflor buenaflor Jan 9, 2025

Choose a reason for hiding this comment

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

SentryEnvelopeItemPayload is there because we need the actual json object and not the data, right?

not necessarily only the json, for example attachments should be bytes.

Right now we have some redundancy with dataFactory, maybe we can refactor this so we use the same API both here and in SentryEvent.envelopeStream?

We could do that, by default the factory methods encode the json into utf-8.

what we could do one of these:

  • decode it in captureEnvelope back to json -> dunno about the performance impact
  • add or adjust the factory methods to not encode for JS

The captureEnvelopeObject method does not have attachment size filtering

true 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on second look I think it's fine we keep the envelope items encoded in utf-8

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.

2 participants