Skip to content

Commit 6f439ac

Browse files
authored
Merge pull request #5019 from getsentry/01-12-add_hint_to_metrics
feat(metrics): [Trace Metrics 25] Add Hint to Metrics
2 parents 552940b + 76e7b2c commit 6f439ac

File tree

13 files changed

+89
-27
lines changed

13 files changed

+89
-27
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public DefaultAndroidEventProcessor(
9494
}
9595

9696
@Override
97-
public @Nullable SentryMetricsEvent process(@NotNull SentryMetricsEvent event) {
97+
public @Nullable SentryMetricsEvent process(
98+
final @NotNull SentryMetricsEvent event, final @NotNull Hint hint) {
9899
setDevice(event);
99100
setOs(event);
100101
return event;

sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ class DefaultAndroidEventProcessorTest {
636636
"42e6bd2a-c45e-414d-8066-ed5196fbc686",
637637
"counter",
638638
123.0,
639-
)
639+
),
640+
Hint(),
640641
)
641642

642643
assertNotNull(processedEvent?.attributes?.get("device.brand"))

sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SessionTrackingIntegrationTest {
194194
TODO("Not yet implemented")
195195
}
196196

197-
override fun captureMetric(event: SentryMetricsEvent, scope: IScope?) {
197+
override fun captureMetric(event: SentryMetricsEvent, scope: IScope?, hint: Hint?) {
198198
TODO("Not yet implemented")
199199
}
200200

sentry/api/sentry.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public abstract interface class io/sentry/EventProcessor {
461461
public fun getOrder ()Ljava/lang/Long;
462462
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
463463
public fun process (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent;
464-
public fun process (Lio/sentry/SentryMetricsEvent;)Lio/sentry/SentryMetricsEvent;
464+
public fun process (Lio/sentry/SentryMetricsEvent;Lio/sentry/Hint;)Lio/sentry/SentryMetricsEvent;
465465
public fun process (Lio/sentry/SentryReplayEvent;Lio/sentry/Hint;)Lio/sentry/SentryReplayEvent;
466466
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
467467
}
@@ -1048,7 +1048,7 @@ public abstract interface class io/sentry/ISentryClient {
10481048
public abstract fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;)V
10491049
public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId;
10501050
public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
1051-
public abstract fun captureMetric (Lio/sentry/SentryMetricsEvent;Lio/sentry/IScope;)V
1051+
public abstract fun captureMetric (Lio/sentry/SentryMetricsEvent;Lio/sentry/IScope;Lio/sentry/Hint;)V
10521052
public abstract fun captureProfileChunk (Lio/sentry/ProfileChunk;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
10531053
public abstract fun captureReplayEvent (Lio/sentry/SentryReplayEvent;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
10541054
public fun captureSession (Lio/sentry/Session;)V
@@ -2863,7 +2863,7 @@ public final class io/sentry/SentryClient : io/sentry/ISentryClient {
28632863
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
28642864
public fun captureFeedback (Lio/sentry/protocol/Feedback;Lio/sentry/Hint;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
28652865
public fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;)V
2866-
public fun captureMetric (Lio/sentry/SentryMetricsEvent;Lio/sentry/IScope;)V
2866+
public fun captureMetric (Lio/sentry/SentryMetricsEvent;Lio/sentry/IScope;Lio/sentry/Hint;)V
28672867
public fun captureProfileChunk (Lio/sentry/ProfileChunk;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
28682868
public fun captureReplayEvent (Lio/sentry/SentryReplayEvent;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
28692869
public fun captureSession (Lio/sentry/Session;Lio/sentry/Hint;)V
@@ -3769,7 +3769,7 @@ public final class io/sentry/SentryOptions$Metrics {
37693769
}
37703770

37713771
public abstract interface class io/sentry/SentryOptions$Metrics$BeforeSendMetricCallback {
3772-
public abstract fun execute (Lio/sentry/SentryMetricsEvent;)Lio/sentry/SentryMetricsEvent;
3772+
public abstract fun execute (Lio/sentry/SentryMetricsEvent;Lio/sentry/Hint;)Lio/sentry/SentryMetricsEvent;
37733773
}
37743774

37753775
public abstract interface class io/sentry/SentryOptions$OnDiscardCallback {
@@ -5284,9 +5284,11 @@ public final class io/sentry/metrics/SentryMetricsParameters {
52845284
public static fun create (Lio/sentry/SentryAttributes;)Lio/sentry/metrics/SentryMetricsParameters;
52855285
public static fun create (Lio/sentry/SentryDate;Lio/sentry/SentryAttributes;)Lio/sentry/metrics/SentryMetricsParameters;
52865286
public fun getAttributes ()Lio/sentry/SentryAttributes;
5287+
public fun getHint ()Lio/sentry/Hint;
52875288
public fun getOrigin ()Ljava/lang/String;
52885289
public fun getTimestamp ()Lio/sentry/SentryDate;
52895290
public fun setAttributes (Lio/sentry/SentryAttributes;)V
5291+
public fun setHint (Lio/sentry/Hint;)V
52905292
public fun setOrigin (Ljava/lang/String;)V
52915293
public fun setTimestamp (Lio/sentry/SentryDate;)V
52925294
}

sentry/src/main/java/io/sentry/EventProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ default SentryLogEvent process(@NotNull SentryLogEvent event) {
6363
* @return the event itself, a mutated SentryMetricsEvent or null
6464
*/
6565
@Nullable
66-
default SentryMetricsEvent process(@NotNull SentryMetricsEvent event) {
66+
default SentryMetricsEvent process(@NotNull SentryMetricsEvent event, @NotNull Hint hint) {
6767
return event;
6868
}
6969

sentry/src/main/java/io/sentry/ISentryClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ SentryId captureProfileChunk(
305305

306306
void captureLog(@NotNull SentryLogEvent logEvent, @Nullable IScope scope);
307307

308-
void captureMetric(@NotNull SentryMetricsEvent logEvent, @Nullable IScope scope);
308+
void captureMetric(
309+
@NotNull SentryMetricsEvent logEvent, @Nullable IScope scope, @Nullable Hint hint);
309310

310311
@ApiStatus.Internal
311312
void captureBatchedLogEvents(@NotNull SentryLogEvents logEvents);

sentry/src/main/java/io/sentry/NoOpSentryClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public void captureLog(@NotNull SentryLogEvent logEvent, @Nullable IScope scope)
8989
}
9090

9191
@Override
92-
public void captureMetric(@NotNull SentryMetricsEvent metricsEvent, @Nullable IScope scope) {
92+
public void captureMetric(
93+
@NotNull SentryMetricsEvent metricsEvent, @Nullable IScope scope, @Nullable Hint hint) {
9394
// do nothing
9495
}
9596

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,12 @@ private SentryLogEvent processLogEvent(
517517

518518
@Nullable
519519
private SentryMetricsEvent processMetricsEvent(
520-
@NotNull SentryMetricsEvent event, final @NotNull List<EventProcessor> eventProcessors) {
520+
@NotNull SentryMetricsEvent event,
521+
final @NotNull List<EventProcessor> eventProcessors,
522+
final @NotNull Hint hint) {
521523
for (final EventProcessor processor : eventProcessors) {
522524
try {
523-
event = processor.process(event);
525+
event = processor.process(event, hint);
524526
} catch (Throwable e) {
525527
options
526528
.getLogger()
@@ -1278,23 +1280,30 @@ public void captureBatchedLogEvents(final @NotNull SentryLogEvents logEvents) {
12781280

12791281
@ApiStatus.Experimental
12801282
@Override
1281-
public void captureMetric(@Nullable SentryMetricsEvent metricsEvent, @Nullable IScope scope) {
1283+
public void captureMetric(
1284+
@Nullable SentryMetricsEvent metricsEvent,
1285+
final @Nullable IScope scope,
1286+
@Nullable Hint hint) {
1287+
if (hint == null) {
1288+
hint = new Hint();
1289+
}
1290+
12821291
if (metricsEvent != null && scope != null) {
1283-
metricsEvent = processMetricsEvent(metricsEvent, scope.getEventProcessors());
1292+
metricsEvent = processMetricsEvent(metricsEvent, scope.getEventProcessors(), hint);
12841293
if (metricsEvent == null) {
12851294
return;
12861295
}
12871296
}
12881297

12891298
if (metricsEvent != null) {
1290-
metricsEvent = processMetricsEvent(metricsEvent, options.getEventProcessors());
1299+
metricsEvent = processMetricsEvent(metricsEvent, options.getEventProcessors(), hint);
12911300
if (metricsEvent == null) {
12921301
return;
12931302
}
12941303
}
12951304

12961305
if (metricsEvent != null) {
1297-
metricsEvent = executeBeforeSendMetric(metricsEvent);
1306+
metricsEvent = executeBeforeSendMetric(metricsEvent, hint);
12981307

12991308
if (metricsEvent == null) {
13001309
options
@@ -1625,12 +1634,13 @@ private void sortBreadcrumbsByDate(
16251634
return event;
16261635
}
16271636

1628-
private @Nullable SentryMetricsEvent executeBeforeSendMetric(@NotNull SentryMetricsEvent event) {
1637+
private @Nullable SentryMetricsEvent executeBeforeSendMetric(
1638+
@NotNull SentryMetricsEvent event, final @NotNull Hint hint) {
16291639
final SentryOptions.Metrics.BeforeSendMetricCallback beforeSendMetric =
16301640
options.getMetrics().getBeforeSend();
16311641
if (beforeSendMetric != null) {
16321642
try {
1633-
event = beforeSendMetric.execute(event);
1643+
event = beforeSendMetric.execute(event, hint);
16341644
} catch (Throwable e) {
16351645
options
16361646
.getLogger()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3813,7 +3813,8 @@ public interface BeforeSendMetricCallback {
38133813
* @return the original metric, mutated metric or null if metric was dropped
38143814
*/
38153815
@Nullable
3816-
SentryMetricsEvent execute(final @NotNull SentryMetricsEvent metric);
3816+
SentryMetricsEvent execute(
3817+
final @NotNull SentryMetricsEvent metric, final @NotNull Hint hint);
38173818
}
38183819
}
38193820

sentry/src/main/java/io/sentry/metrics/MetricsApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void captureMetrics(
158158
metricsEvent.setUnit(unit);
159159
metricsEvent.setAttributes(createAttributes(params));
160160

161-
scopes.getClient().captureMetric(metricsEvent, combinedScope);
161+
scopes.getClient().captureMetric(metricsEvent, combinedScope, params.getHint());
162162
} catch (Throwable e) {
163163
options.getLogger().log(SentryLevel.ERROR, "Error while capturing log event", e);
164164
}

0 commit comments

Comments
 (0)