sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Attachement added in `setBeforeSend` are not visible in Sentry.

Open rodolfoBee opened this issue 1 year ago • 1 comments

Integration

sentry-android

Build System

Gradle

AGP Version

4.11.0

Proguard

Disabled

Version

7.12.1 and 7.15.0

Steps to Reproduce

App is written in Kotlin, here is the code snippets used:

options.beforeSend =
     BeforeSendCallback { event: SentryEvent, hint: Hint ->
        try {
          val data = ByteArrayOutputStream()
          val zipOutputStream = ZipOutputStream(data)
          
          val file = ZipEntry("test.txt")
          
          zipOutputStream.putNextEntry(file)
          zipOutputStream.write("hello world".toByteArray(Charsets.UTF_8))
          zipOutputStream.closeEntry()
          zipOutputStream.close()
          
          hint.addAttachment(Attachment(data.toByteArray(), "test.zip"))
          
        } catch (e: Exception) {
          logger.error("error when attaching logs to the event", e)
          throw RuntimeException(e)
        }
   }

and

options.beforeSend =
     BeforeSendCallback { event: SentryEvent, hint: Hint ->
          try {
          hint.addAttachment(
            Attachment("test attachment string".toByteArray(), "test.zip")
          )
          } catch (e: Exception) {
            logger.error("error when attaching logs to the event", e)
            throw RuntimeException(e)
          }
}

A minimal reproduction app is currently not available. When creating a simple app with the suggested snippet the attachments are correctly added to events, but when adding it to the production app, no attachments are sent to Sentry.

More information is available in the internal ticket on this link (comment from 14.10).

Expected Result

The events in Sentry have attachment added to the hint in the beforeSend callback, as in the test app:

  • https://dev-curumas.sentry.io/issues/5990004349/events/21a5fa27209d4151bdc0b7aabdde4107/

Actual Result

No attachment on events. ~~Logs~~ The Stats page shows only attachments dropped due to size, but it has been tested with files a few KB large and the test event is correctly accepted.

rodolfoBee avatar Oct 14 '24 13:10 rodolfoBee

Thanks for reporting, we'll have a look into this. Since this is only happening in production builds: Do you apply any code obfuscation / minification tools like ProGuard / DexGuard / R8?

markushi avatar Oct 16 '24 12:10 markushi

hey @rodolfoBee The snippet seems to work fine. Can you give us some more information on how it is executed in the production app? Also, is there any custom event processor?

stefanosiano avatar Oct 25 '24 11:10 stefanosiano

@rodolfoBee any updates on this one? Otherwise we'll close this issue next week 😄

markushi avatar Nov 27 '24 14:11 markushi

no updates from the affected user. We can close it.

rodolfoBee avatar Nov 27 '24 16:11 rodolfoBee