Skip to content

Commit 3513eaa

Browse files
committed
Metrics Options
1 parent 3d5a001 commit 3513eaa

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
@@ -3419,6 +3419,7 @@ public class io/sentry/SentryOptions {
34193419
public fun getMaxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize;
34203420
public fun getMaxSpans ()I
34213421
public fun getMaxTraceFileSize ()J
3422+
public fun getMetrics ()Lio/sentry/SentryOptions$Metrics;
34223423
public fun getModulesLoader ()Lio/sentry/internal/modules/IModulesLoader;
34233424
public fun getOnDiscard ()Lio/sentry/SentryOptions$OnDiscardCallback;
34243425
public fun getOnOversizedEvent ()Lio/sentry/SentryOptions$OnOversizedEventCallback;
@@ -3571,6 +3572,7 @@ public class io/sentry/SentryOptions {
35713572
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
35723573
public fun setMaxSpans (I)V
35733574
public fun setMaxTraceFileSize (J)V
3575+
public fun setMetrics (Lio/sentry/SentryOptions$Metrics;)V
35743576
public fun setModulesLoader (Lio/sentry/internal/modules/IModulesLoader;)V
35753577
public fun setOnDiscard (Lio/sentry/SentryOptions$OnDiscardCallback;)V
35763578
public fun setOnOversizedEvent (Lio/sentry/SentryOptions$OnOversizedEventCallback;)V
@@ -3625,10 +3627,6 @@ public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback
36253627
public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)Lio/sentry/Breadcrumb;
36263628
}
36273629

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

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

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

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

Comments
 (0)