Skip to content

Commit 857a7aa

Browse files
committed
Metrics Options
1 parent d15471f commit 857a7aa

File tree

2 files changed

+87
-18
lines changed

2 files changed

+87
-18
lines changed

sentry/api/sentry.api

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,7 @@ public class io/sentry/SentryOptions {
34203420
public fun getMaxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize;
34213421
public fun getMaxSpans ()I
34223422
public fun getMaxTraceFileSize ()J
3423+
public fun getMetrics ()Lio/sentry/SentryOptions$Metrics;
34233424
public fun getModulesLoader ()Lio/sentry/internal/modules/IModulesLoader;
34243425
public fun getOnDiscard ()Lio/sentry/SentryOptions$OnDiscardCallback;
34253426
public fun getOnOversizedEvent ()Lio/sentry/SentryOptions$OnOversizedEventCallback;
@@ -3572,6 +3573,7 @@ public class io/sentry/SentryOptions {
35723573
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
35733574
public fun setMaxSpans (I)V
35743575
public fun setMaxTraceFileSize (J)V
3576+
public fun setMetrics (Lio/sentry/SentryOptions$Metrics;)V
35753577
public fun setModulesLoader (Lio/sentry/internal/modules/IModulesLoader;)V
35763578
public fun setOnDiscard (Lio/sentry/SentryOptions$OnDiscardCallback;)V
35773579
public fun setOnOversizedEvent (Lio/sentry/SentryOptions$OnOversizedEventCallback;)V
@@ -3626,10 +3628,6 @@ public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback
36263628
public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)Lio/sentry/Breadcrumb;
36273629
}
36283630

3629-
public abstract interface class io/sentry/SentryOptions$BeforeEmitMetricCallback {
3630-
public abstract fun execute (Ljava/lang/String;Ljava/util/Map;)Z
3631-
}
3632-
36333631
public abstract interface class io/sentry/SentryOptions$BeforeEnvelopeCallback {
36343632
public abstract fun execute (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
36353633
}
@@ -3683,6 +3681,18 @@ public abstract interface class io/sentry/SentryOptions$Logs$BeforeSendLogCallba
36833681
public abstract fun execute (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent;
36843682
}
36853683

3684+
public final class io/sentry/SentryOptions$Metrics {
3685+
public fun <init> ()V
3686+
public fun getBeforeSend ()Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;
3687+
public fun isEnabled ()Z
3688+
public fun setBeforeSend (Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;)V
3689+
public fun setEnabled (Z)V
3690+
}
3691+
3692+
public abstract interface class io/sentry/SentryOptions$Metrics$BeforeSendMetricCallback {
3693+
public abstract fun execute (Ljava/lang/Object;)Ljava/lang/Object;
3694+
}
3695+
36863696
public abstract interface class io/sentry/SentryOptions$OnDiscardCallback {
36873697
public abstract fun execute (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;Ljava/lang/Long;)V
36883698
}

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)