diff --git a/src/includes/configuration/before-send-fingerprint/java.spring-boot.mdx b/src/includes/configuration/before-send-fingerprint/java.spring-boot.mdx index c921d90eb11b9..64a2bb2ab7948 100644 --- a/src/includes/configuration/before-send-fingerprint/java.spring-boot.mdx +++ b/src/includes/configuration/before-send-fingerprint/java.spring-boot.mdx @@ -1,12 +1,13 @@ ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { + public SentryEvent execute(SentryEvent event, Hint hint) { if (event.getThrowable() instanceof SQLException) { event.setFingerprints(Arrays.asList("database-connection-error")); } @@ -18,11 +19,12 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { if (event.throwable is SQLException) { event.fingerprints = listOf("database-connection-error") } diff --git a/src/includes/configuration/before-send-fingerprint/java.spring.mdx b/src/includes/configuration/before-send-fingerprint/java.spring.mdx index c921d90eb11b9..64a2bb2ab7948 100644 --- a/src/includes/configuration/before-send-fingerprint/java.spring.mdx +++ b/src/includes/configuration/before-send-fingerprint/java.spring.mdx @@ -1,12 +1,13 @@ ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { + public SentryEvent execute(SentryEvent event, Hint hint) { if (event.getThrowable() instanceof SQLException) { event.setFingerprints(Arrays.asList("database-connection-error")); } @@ -18,11 +19,12 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { if (event.throwable is SQLException) { event.fingerprints = listOf("database-connection-error") } diff --git a/src/includes/configuration/before-send-hint/java.spring-boot.mdx b/src/includes/configuration/before-send-hint/java.spring-boot.mdx index 88a9e609c050b..c5782d60ddc9d 100644 --- a/src/includes/configuration/before-send-hint/java.spring-boot.mdx +++ b/src/includes/configuration/before-send-hint/java.spring-boot.mdx @@ -1,15 +1,16 @@ -A `BiFunction` can be used to mutate, discard (return null), or return a completely new event. +A `BiFunction` can be used to mutate, discard (return null), or return a completely new event. ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { - if (hint instanceof MyHint) { + public SentryEvent execute(SentryEvent event, Hint hint) { + if (hint.get("my-hint-key") != null) { return null; } else { return event; @@ -21,12 +22,13 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { - if (hint is MyHint) { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { + if (hint["my-hint-key"] != null) { null } else { event diff --git a/src/includes/configuration/before-send-hint/java.spring.mdx b/src/includes/configuration/before-send-hint/java.spring.mdx index 88a9e609c050b..43ab8c728d504 100644 --- a/src/includes/configuration/before-send-hint/java.spring.mdx +++ b/src/includes/configuration/before-send-hint/java.spring.mdx @@ -1,15 +1,16 @@ -A `BiFunction` can be used to mutate, discard (return null), or return a completely new event. +A `BiFunction` can be used to mutate, discard (return null), or return a completely new event. ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { - if (hint instanceof MyHint) { + public SentryEvent execute(SentryEvent event, Hint hint) { + if (hint.get("my-hint-key") != null) { return null; } else { return event; @@ -21,12 +22,13 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { - if (hint is MyHint) { + override fun execute(event: SentryEvent, hint: Hnt): SentryEvent? { + if (hint["my-hint-key"] != null) { null } else { event diff --git a/src/includes/configuration/before-send/java.spring-boot.mdx b/src/includes/configuration/before-send/java.spring-boot.mdx index 05e2c8606eae3..758c962b61b52 100644 --- a/src/includes/configuration/before-send/java.spring-boot.mdx +++ b/src/includes/configuration/before-send/java.spring-boot.mdx @@ -3,12 +3,13 @@ ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { + public SentryEvent execute(SentryEvent event, Hint hint) { // Example: Never send server name in events event.setServerName(null); return event; @@ -19,11 +20,12 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { // Example: Never send server name in events event.serverName = null return event diff --git a/src/includes/configuration/before-send/java.spring.mdx b/src/includes/configuration/before-send/java.spring.mdx index 05e2c8606eae3..758c962b61b52 100644 --- a/src/includes/configuration/before-send/java.spring.mdx +++ b/src/includes/configuration/before-send/java.spring.mdx @@ -3,12 +3,13 @@ ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { + public SentryEvent execute(SentryEvent event, Hint hint) { // Example: Never send server name in events event.setServerName(null); return event; @@ -19,11 +20,12 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { // Example: Never send server name in events event.serverName = null return event diff --git a/src/includes/configuration/config-intro/java.mdx b/src/includes/configuration/config-intro/java.mdx index 88fb05b2e3722..6320ccefe4903 100644 --- a/src/includes/configuration/config-intro/java.mdx +++ b/src/includes/configuration/config-intro/java.mdx @@ -25,13 +25,14 @@ public class MyClass { ```kotlin {tabTitle:Kotlin} import io.sentry.Sentry import io.sentry.SentryOptions.BeforeSendCallback +import io.sentry.Hint fun main() { Sentry.init { options -> // your Sentry project/dashboard options.dsn = "___PUBLIC_DSN___" options.release = "io.sentry.samples.console@3.0.0+1" - options.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Any? -> + options.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Hint -> // Drop an event altogether: if (event.getTag("SomeTag") != null) { null diff --git a/src/includes/enriching-events/add-attachment/java.mdx b/src/includes/enriching-events/add-attachment/java.mdx new file mode 100644 index 0000000000000..f381778d51142 --- /dev/null +++ b/src/includes/enriching-events/add-attachment/java.mdx @@ -0,0 +1,110 @@ +To add an attachment, you can either add it to the scope, pass it to any of the `capture` methods, or manipulate the list of attachments in an `EventProcessor` or `beforeSend`. + +### Passing Attachments to Capture + +You may pass attachments to any of the `capture` methods, for example, when capturing an exception: + +```java +import io.sentry.Attachment; +import io.sentry.Hint; +import io.sentry.Sentry; + +Sentry.captureException(new IllegalStateException(), Hint.withAttachment("/path/to/file.txt")) +``` + +```kotlin +import io.sentry.Attachment; +import io.sentry.Hint; +import io.sentry.Sentry; + +Sentry.captureException(IllegalStateException(), Hint.withAttachment("/path/to/file.txt")) +``` + +### Adding Attachments in `EventProcessor` + +You may also manipulate attachments in `EventProcessor`: + +```java +import io.sentry.Attachment; +import io.sentry.EventProcessor; +import io.sentry.Hint; +import io.sentry.Sentry; +import io.sentry.SentryEvent; + +class AttachmentManipulationEventProcessor implements EventProcessor { + @Override + public SentryEvent process(SentryEvent event, Hint hint) { + hint.addAttachment(new Attachment("/path/to/file.txt")) + return event; + } +} + +// Register the AttachmentManipulationEventProcessor using SentryOptions#addEventProcessor or Scope#addEventProcessor + +// Send an event to Sentry. During construction of the event +// the attachment will be added by the event processor. +Sentry.captureMessage("Hello, world!"); +``` + +```kotlin +import io.sentry.Attachment; +import io.sentry.EventProcessor; +import io.sentry.Hint; +import io.sentry.Sentry +import io.sentry.SentryEvent; +import io.sentry.protocol.Message + +class AttachmentManipulationEventProcessor: EventProcessor { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { + hint.addAttachment(Attachment("/path/to/file.txt")) + return event + } +} + +// Register the AttachmentManipulationEventProcessor using SentryOptions#addEventProcessor or Scope#addEventProcessor + +// Send an event to Sentry. During construction of the event +// the attachment will be added by the event processor. +Sentry.captureMessage("Hello, world!") +``` + + + +Instead of adding attachments, you can also remove them, by setting a different (or empty) list of attachments using `Hint#setAttachments()`. + + + +### Adding Attachments in `beforeSend` + +Another way of adding attachments is using `beforeSend`: + +```java +import io.sentry.Attachment; +import io.sentry.Hint; +import io.sentry.Sentry; + +options.setBeforeSend((event, hint) -> { + hint.addAttachment(new Attachment("/path/to/file.txt")) + return event; +}); +``` + +```kotlin +import io.sentry.Attachment; +import io.sentry.Hint; +import io.sentry.Sentry; +import io.sentry.SentryOptions.BeforeSendCallback + +options.beforeSend = BeforeSendCallback { event, hint -> + hint.addAttachment(Attachment("/path/to/file.txt")) + event +} +``` + + + +Instead of adding attachments, you can also remove them, by setting a different (or empty) list of attachments using `Hint#setAttachments()`. + + + +### Adding Attachments to the Scope diff --git a/src/platforms/android/configuration/manual-init.mdx b/src/platforms/android/configuration/manual-init.mdx index 81060073784f0..e0fd4e7498dc1 100644 --- a/src/platforms/android/configuration/manual-init.mdx +++ b/src/platforms/android/configuration/manual-init.mdx @@ -22,7 +22,7 @@ Or, to completely remove the merging of the `ContentProvider`: android:name="io.sentry.android.core.SentryInitProvider" android:authorities="${applicationId}.SentryInitProvider" tools:node="remove" /> - + + BeforeSendCallback { event: SentryEvent, hint: Hint -> if (SentryLevel.DEBUG == event.level) { null } else { diff --git a/src/platforms/android/migration.mdx b/src/platforms/android/migration.mdx index bb6ab6bb5275a..b29a42ea14108 100644 --- a/src/platforms/android/migration.mdx +++ b/src/platforms/android/migration.mdx @@ -252,7 +252,7 @@ _New_: ```kotlin SentryOptions#addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hint: Any?): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return event } }) diff --git a/src/platforms/common/enriching-events/attachments/index.mdx b/src/platforms/common/enriching-events/attachments/index.mdx index efb38de644dcf..18cba267b84e9 100644 --- a/src/platforms/common/enriching-events/attachments/index.mdx +++ b/src/platforms/common/enriching-events/attachments/index.mdx @@ -84,7 +84,7 @@ In addition, you can set these parameters: ## Uploading Attachments - + diff --git a/src/platforms/java/guides/spring-boot/advanced-usage.mdx b/src/platforms/java/guides/spring-boot/advanced-usage.mdx index ae79a1a603a4c..8bcff925f92f0 100644 --- a/src/platforms/java/guides/spring-boot/advanced-usage.mdx +++ b/src/platforms/java/guides/spring-boot/advanced-usage.mdx @@ -28,12 +28,13 @@ Any Spring bean implementing `EventProcessor` will be automatically set on `Sent ```java import io.sentry.SentryEvent; import io.sentry.EventProcessor; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomEventProcessor implements EventProcessor { @Override - public SentryEvent process(SentryEvent event, Object hint) { + public SentryEvent process(SentryEvent event, Hint hint) { // modify the event or return null to drop it return event; } @@ -43,11 +44,12 @@ public class CustomEventProcessor implements EventProcessor { ```kotlin import io.sentry.SentryEvent import io.sentry.EventProcessor +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hint: Any?): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { // modify the event or return null to drop it return event } @@ -61,12 +63,13 @@ Any Spring bean implementing the `BeforeSendCallback` will be automatically set ```java import io.sentry.SentryEvent; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback { @Override - public SentryEvent execute(SentryEvent event, Object hint) { + public SentryEvent execute(SentryEvent event, Hint hint) { // Example: Never send server name in events event.setServerName(null); return event; @@ -77,11 +80,12 @@ public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallbac ```kotlin import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Any?): SentryEvent? { + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { // Example: Never send server name in events event.serverName = null return event @@ -96,13 +100,14 @@ Any Spring bean implementing the `BeforeBreadcrumbCallback` will be automaticall ```java import io.sentry.Breadcrumb; import io.sentry.SentryOptions; +import io.sentry.Hint import org.springframework.stereotype.Component; @Component public class CustomBeforeBreadcrumbCallback implements SentryOptions.BeforeBreadcrumbCallback { @Override - public Breadcrumb execute(Breadcrumb breadcrumb, Object hint) { + public Breadcrumb execute(Breadcrumb breadcrumb, Hint hint) { // Don't add breadcrumbs with message containing: if (breadcrumb.getMessage() != null && breadcrumb.getMessage().contains("bad breadcrumb")) { @@ -116,11 +121,12 @@ public class CustomBeforeBreadcrumbCallback implements SentryOptions.BeforeBread ```kotlin import io.sentry.Breadcrumb import io.sentry.SentryOptions +import io.sentry.Hint import org.springframework.stereotype.Component @Component class CustomBeforeBreadcrumbCallback : SentryOptions.BeforeBreadcrumbCallback { - override fun execute(breadcrumb: Breadcrumb, hint: Any?): Breadcrumb? { + override fun execute(breadcrumb: Breadcrumb, hint: Hint): Breadcrumb? { // Don't add breadcrumbs with message containing: return if (breadcrumb.message?.contains("bad breadcrumb") == true) { null diff --git a/src/platforms/java/migration.mdx b/src/platforms/java/migration.mdx index ff081a6aef558..8a6b321307644 100644 --- a/src/platforms/java/migration.mdx +++ b/src/platforms/java/migration.mdx @@ -77,7 +77,7 @@ _New_: ```kotlin SentryOptions#addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hint: Any?): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return event } }) diff --git a/src/platforms/java/usage.mdx b/src/platforms/java/usage.mdx index a02b6c484d81c..079394afc11be 100644 --- a/src/platforms/java/usage.mdx +++ b/src/platforms/java/usage.mdx @@ -92,6 +92,7 @@ public class MyClass { ```kotlin {tabTitle:Kotlin} import io.sentry.SentryOptions.BeforeBreadcrumbCallback import io.sentry.SentryOptions.BeforeSendCallback +import io.sentry.Hint fun main() { Sentry.init { options -> @@ -104,7 +105,7 @@ fun main() { options.release = "io.sentry.samples.console@4.2.0+1" // Modifications to event before it goes out. Could replace the event altogether - options.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Any? -> + options.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Hint -> // Drop an event altogether: if (event.getTag("SomeTag") != null) { null @@ -114,7 +115,7 @@ fun main() { } // Allows inspecting and modifying, returning a new or simply rejecting (returning null) - options.beforeBreadcrumb = BeforeBreadcrumbCallback { breadcrumb: Breadcrumb, hint: Any? -> + options.beforeBreadcrumb = BeforeBreadcrumbCallback { breadcrumb: Breadcrumb, hint: Hint -> // Don't add breadcrumbs with message containing: val message = breadcrumb.message if (message?.contains("bad breadcrumb") == true) { @@ -452,6 +453,7 @@ import io.sentry.EventProcessor; import io.sentry.IHub; import io.sentry.Sentry; import io.sentry.SentryEvent; +import io.sentry.Hint import io.sentry.protocol.Message; public class MyClass { @@ -461,7 +463,7 @@ public class MyClass { Sentry.configureScope(scope -> { scope.addEventProcessor(new EventProcessor() { @Override - public SentryEvent process(SentryEvent event, Object hint) { + public SentryEvent process(SentryEvent event, Hint hint) { Message message = new Message(); message.setMessage("Overwritten by myEventBuilderHelper!"); event.setMessage(message); @@ -479,6 +481,7 @@ public class MyClass { ```kotlin import io.sentry.Sentry +import io.sentry.Hint import io.sentry.protocol.Message class MyClass { @@ -487,7 +490,7 @@ class MyClass { // this helper will process *all* future events in this scope. Sentry.configureScope { scope -> scope.addEventProcessor(object: EventProcessor { - override fun process(event: SentryEvent, hint: Any?): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { event.message = Message().apply { message = "Overwritten by myEventBuilderHelper!" }