@@ -624,6 +624,8 @@ public class SentryOptions {
624624
625625 private @ NotNull SentryOptions .Logs logs = new SentryOptions .Logs ();
626626
627+ private @ NotNull SentryOptions .Metrics metrics = new SentryOptions .Metrics ();
628+
627629 private @ NotNull ISocketTagger socketTagger = NoOpSocketTagger .getInstance ();
628630
629631 /** Runtime manager to manage runtime policies, like StrictMode on Android. */
@@ -3261,20 +3263,6 @@ public interface BeforeEnvelopeCallback {
32613263 void execute (@ NotNull SentryEnvelope envelope , @ Nullable Hint hint );
32623264 }
32633265
3264- /** The BeforeEmitMetric callback */
3265- @ ApiStatus .Experimental
3266- public interface BeforeEmitMetricCallback {
3267-
3268- /**
3269- * A callback which gets called right before a metric is about to be emitted.
3270- *
3271- * @param key the metric key
3272- * @param tags the metric tags
3273- * @return true if the metric should be emitted, false otherwise
3274- */
3275- boolean execute (@ NotNull String key , @ Nullable Map <String , String > tags );
3276- }
3277-
32783266 /**
32793267 * Creates SentryOptions instance without initializing any of the internal parts.
32803268 *
@@ -3537,6 +3525,16 @@ public void setLogs(@NotNull SentryOptions.Logs logs) {
35373525 this .logs = logs ;
35383526 }
35393527
3528+ @ ApiStatus .Experimental
3529+ public @ NotNull SentryOptions .Metrics getMetrics () {
3530+ return metrics ;
3531+ }
3532+
3533+ @ ApiStatus .Experimental
3534+ public void setMetrics (@ NotNull SentryOptions .Metrics metrics ) {
3535+ this .metrics = metrics ;
3536+ }
3537+
35403538 public static final class Proxy {
35413539 private @ Nullable String host ;
35423540 private @ Nullable String port ;
@@ -3741,6 +3739,67 @@ public interface BeforeSendLogCallback {
37413739 }
37423740 }
37433741
3742+ public static final class Metrics {
3743+
3744+ /** Whether Sentry Metrics feature is enabled and metrics are sent to Sentry. */
3745+ private boolean enable = false ;
3746+
3747+ /**
3748+ * This function is called with a metric key and tags and can return false to skip sending the
3749+ * metric
3750+ */
3751+ private @ Nullable BeforeSendMetricCallback beforeSend ;
3752+
3753+ /**
3754+ * Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
3755+ *
3756+ * @return true if Sentry Metrics should be enabled
3757+ */
3758+ public boolean isEnabled () {
3759+ return enable ;
3760+ }
3761+
3762+ /**
3763+ * Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
3764+ *
3765+ * @param enableMetrics true if Sentry Metrics should be enabled
3766+ */
3767+ public void setEnabled (boolean enableMetrics ) {
3768+ this .enable = enableMetrics ;
3769+ }
3770+
3771+ /**
3772+ * Returns the BeforeSendMetric callback
3773+ *
3774+ * @return the beforeSend callback or null if not set
3775+ */
3776+ public @ Nullable BeforeSendMetricCallback getBeforeSend () {
3777+ return beforeSend ;
3778+ }
3779+
3780+ /**
3781+ * Sets the beforeSend callback for metrics
3782+ *
3783+ * @param beforeSend the beforeSend callback for metrics
3784+ */
3785+ public void setBeforeSend (@ Nullable BeforeSendMetricCallback beforeSend ) {
3786+ this .beforeSend = beforeSend ;
3787+ }
3788+
3789+ public interface BeforeSendMetricCallback {
3790+
3791+ /**
3792+ * A callback which gets called right before a metric is about to be sent.
3793+ *
3794+ * @param metric the metric
3795+ * @return the original metric, mutated metric or null if metric was dropped
3796+ */
3797+ // TODO replace with SentryMetric
3798+ @ Nullable
3799+ Object execute (@ NotNull Object metric );
3800+ }
3801+ }
3802+
37443803 @ ApiStatus .Experimental
37453804 public @ NotNull DistributionOptions getDistribution () {
37463805 return distribution ;
0 commit comments