-
-
Notifications
You must be signed in to change notification settings - Fork 451
Attachments can be manipulated via hints #2046
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
Attachments can be manipulated via hints #2046
Conversation
@@ -80,6 +80,11 @@ private boolean shouldApplyScopeData( | |||
hints = new Hints(); | |||
} | |||
|
|||
// TODO what does cached etc mean for devs manipulating hints in beforeSend and eventProcessor? | |||
if (shouldApplyScopeData(event, hints)) { |
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.
Do we have to prevent manipulation of attachments if !shouldApplyScopeData
?
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.
What you did makes sense to only get the attachments from the scope into the hints with this condition.
If we're not applying the scope to the event/hint, an attachment still could show up in the hint because the user added it directly while calling capture. And that's totally fine.
} | ||
|
||
@Test | ||
fun `passing attachments via hint into breadcrumb ignores them`() { |
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.
This test case and the one after it show that attachments in hints have no effect on breadcrumbs. I assume this is what we want. Correct?
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.
h
: Why do we have a hint in setBeforeBreadcrumb
? I don't get this. This might be frankly confusing. You could do addAttachment
in setBeforeBreadcrumb
, and nothing would happen.
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.
@marandaneto to answer both I guess 😄
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.
The hint for crumbs are only for filtering, they are not part of the event processing pipeline, I'd say that we don't even need this test.
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.
Is there anything we need to change here? Like passing a different Interface that doesn't have the attachment manipulation methods instead of Hints
? Or is it ok if these are basically NOOP for breadcrumbs?
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 like where this is going, but I have a few major items to discuss about the API.
public static @NotNull Hints withAttachment(@Nullable Attachment attachment) { | ||
@NotNull final Hints hints = new Hints(); | ||
hints.getAttachmentContainer().add(attachment); | ||
return hints; | ||
} | ||
|
||
public static @NotNull Hints withAttachments(@Nullable List<Attachment> attachments) { | ||
@NotNull final Hints hints = new Hints(); | ||
hints.getAttachmentContainer().addAll(attachments); | ||
return hints; | ||
} |
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.
m
: I'm not sure if we really need to add these convenience methods. The user saves one line of code and we have to add two methods for that. I would rather keep it simple.
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.
My intention was to make it as easy as possible to pass an attachment to the captureX()
methods.
Co-authored-by: Philipp Hofmann <[email protected]>
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.
The indirection to access the attachments from the Hint IMHO could be dropped in favor of methods hanging straight from the Hints class.
Other than that, LGTM
@@ -80,6 +80,11 @@ private boolean shouldApplyScopeData( | |||
hints = new Hints(); | |||
} | |||
|
|||
// TODO what does cached etc mean for devs manipulating hints in beforeSend and eventProcessor? | |||
if (shouldApplyScopeData(event, hints)) { |
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.
What you did makes sense to only get the attachments from the scope into the hints with this condition.
If we're not applying the scope to the event/hint, an attachment still could show up in the hint because the user added it directly while calling capture. And that's totally fine.
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 will give this another full pass later today.
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.
Only the setBeforeBreadcrumb
issue concerns me. Otherwise, I like this. Good job.
@@ -1282,7 +1283,7 @@ class SentryClientTest { | |||
fun `screenshot is added to the envelope from the hint`() { | |||
val sut = fixture.getSut() | |||
val attachment = Attachment.fromScreenshot(byteArrayOf()) | |||
val hints = Hints().also { it.set(SENTRY_SCREENSHOT, attachment) } |
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.
The new API is way nicer 👏 .
} | ||
|
||
@Test | ||
fun `passing attachments via hint into breadcrumb ignores them`() { |
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.
h
: Why do we have a hint in setBeforeBreadcrumb
? I don't get this. This might be frankly confusing. You could do addAttachment
in setBeforeBreadcrumb
, and nothing would happen.
} | ||
|
||
@Test | ||
fun `passing attachments via hint into breadcrumb ignores them`() { |
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.
@marandaneto to answer both I guess 😄
public void remove(@NotNull String hintType) { | ||
internalStorage.remove(hintType); | ||
public Hints() { | ||
primitiveMappings = new HashMap<>(); |
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.
can this be done in a static
block (and can it be a static map)? Not sure how many instances of HInts
we'll have during the lifetime of an app.
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.
Updated
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class Hints { | ||
|
||
private final @NotNull Map<String, Object> internalStorage = new HashMap<String, Object>(); | ||
private final @NotNull List<Attachment> attachments = new CopyOnWriteArrayList<>(); | ||
private @Nullable Attachment screenshot = null; |
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.
do we need some kind of synchronization around this field (looking at attachments
- it's CopyOnWriteArrayList
)
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.
Ah no, I don't think it needs to be synchronized, can replace with a different implementation.
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.
Updated
…EventProcessor as @NotNull Hints object (#2045) * Replace hint Map with Hints object * Add changelog * Fix typo in changelog * Fix link in changelog * Attachments can be manipulated via hints (#2046) * Store attachments in hints and allow manipulation in beforeSend and eventProcessor * Add changelog * Add tests for breadcrumbs and attachments via hints * Update CHANGELOG.md Co-authored-by: Philipp Hofmann <[email protected]> * Rename AttachmentContainer to Attachments * Use long for test * Move attachments into Hints * Fix kotlin/java interop for Hints * Convert screenshot from map entry to property * Rename hint name param * Rename clear to clearAttachments * Use kotlin short version access for getScreenshot * Move AttachmentsTest into HintsTest; add param names * Make primitiveMapping table static * Use ArrayList as there should not be a synchronization issue for hints Co-authored-by: Philipp Hofmann <[email protected]> * Rename Hints to Hint * Remove commented out code * Code Review * Rename SentryFallbackConsumer as it is Hints specific Co-authored-by: Philipp Hofmann <[email protected]>
📜 Description
Attachments can now be manipulated via hints
💡 Motivation and Context
This builds on top of #2045 to enable use cases mentioned in getsentry/sentry-javascript#5036
Closes #1467
💚 How did you test it?
Unit Tests
📝 Checklist
🔮 Next steps
Update docs