@@ -621,6 +621,8 @@ public class SentryOptions {
621621
622622 private @ NotNull SentryOptions .Logs logs = new SentryOptions .Logs ();
623623
624+ private @ NotNull SentryOptions .Metrics metrics = new SentryOptions .Metrics ();
625+
624626 private @ NotNull ISocketTagger socketTagger = NoOpSocketTagger .getInstance ();
625627
626628 /** Runtime manager to manage runtime policies, like StrictMode on Android. */
@@ -3258,20 +3260,6 @@ public interface BeforeEnvelopeCallback {
32583260 void execute (@ NotNull SentryEnvelope envelope , @ Nullable Hint hint );
32593261 }
32603262
3261- /** The BeforeEmitMetric callback */
3262- @ ApiStatus .Experimental
3263- public interface BeforeEmitMetricCallback {
3264-
3265- /**
3266- * A callback which gets called right before a metric is about to be emitted.
3267- *
3268- * @param key the metric key
3269- * @param tags the metric tags
3270- * @return true if the metric should be emitted, false otherwise
3271- */
3272- boolean execute (@ NotNull String key , @ Nullable Map <String , String > tags );
3273- }
3274-
32753263 /**
32763264 * Creates SentryOptions instance without initializing any of the internal parts.
32773265 *
@@ -3534,6 +3522,16 @@ public void setLogs(@NotNull SentryOptions.Logs logs) {
35343522 this .logs = logs ;
35353523 }
35363524
3525+ @ ApiStatus .Experimental
3526+ public @ NotNull SentryOptions .Metrics getMetrics () {
3527+ return metrics ;
3528+ }
3529+
3530+ @ ApiStatus .Experimental
3531+ public void setMetrics (@ NotNull SentryOptions .Metrics metrics ) {
3532+ this .metrics = metrics ;
3533+ }
3534+
35373535 public static final class Proxy {
35383536 private @ Nullable String host ;
35393537 private @ Nullable String port ;
@@ -3738,6 +3736,67 @@ public interface BeforeSendLogCallback {
37383736 }
37393737 }
37403738
3739+ public static final class Metrics {
3740+
3741+ /** Whether Sentry Metrics feature is enabled and metrics are sent to Sentry. */
3742+ private boolean enable = false ;
3743+
3744+ /**
3745+ * This function is called with a metric key and tags and can return false to skip sending the
3746+ * metric
3747+ */
3748+ private @ Nullable BeforeSendMetricCallback beforeSend ;
3749+
3750+ /**
3751+ * Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
3752+ *
3753+ * @return true if Sentry Metrics should be enabled
3754+ */
3755+ public boolean isEnabled () {
3756+ return enable ;
3757+ }
3758+
3759+ /**
3760+ * Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
3761+ *
3762+ * @param enableMetrics true if Sentry Metrics should be enabled
3763+ */
3764+ public void setEnabled (boolean enableMetrics ) {
3765+ this .enable = enableMetrics ;
3766+ }
3767+
3768+ /**
3769+ * Returns the BeforeSendMetric callback
3770+ *
3771+ * @return the beforeSend callback or null if not set
3772+ */
3773+ public @ Nullable BeforeSendMetricCallback getBeforeSend () {
3774+ return beforeSend ;
3775+ }
3776+
3777+ /**
3778+ * Sets the beforeSend callback for metrics
3779+ *
3780+ * @param beforeSend the beforeSend callback for metrics
3781+ */
3782+ public void setBeforeSend (@ Nullable BeforeSendMetricCallback beforeSend ) {
3783+ this .beforeSend = beforeSend ;
3784+ }
3785+
3786+ public interface BeforeSendMetricCallback {
3787+
3788+ /**
3789+ * A callback which gets called right before a metric is about to be sent.
3790+ *
3791+ * @param metric the metric
3792+ * @return the original metric, mutated metric or null if metric was dropped
3793+ */
3794+ // TODO replace with SentryMetric
3795+ @ Nullable
3796+ Object execute (@ NotNull Object metric );
3797+ }
3798+ }
3799+
37413800 @ ApiStatus .Experimental
37423801 public @ NotNull DistributionOptions getDistribution () {
37433802 return distribution ;
0 commit comments