File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
main/java/io/sentry/metrics Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -5283,6 +5283,7 @@ public final class io/sentry/metrics/SentryMetricsParameters {
52835283 public fun <init> ()V
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;
5286+ public static fun create (Ljava/util/Map;)Lio/sentry/metrics/SentryMetricsParameters;
52865287 public fun getAttributes ()Lio/sentry/SentryAttributes;
52875288 public fun getHint ()Lio/sentry/Hint;
52885289 public fun getOrigin ()Ljava/lang/String;
Original file line number Diff line number Diff line change 33import io .sentry .Hint ;
44import io .sentry .SentryAttributes ;
55import io .sentry .SentryDate ;
6+ import java .util .Map ;
67import org .jetbrains .annotations .NotNull ;
78import org .jetbrains .annotations .Nullable ;
89
@@ -60,4 +61,15 @@ public void setHint(final @Nullable Hint hint) {
6061 final @ Nullable SentryAttributes attributes ) {
6162 return create (null , attributes );
6263 }
64+
65+ /**
66+ * A shortcut for SentryMetricsParameters.create(SentryAttributes.fromMap())
67+ *
68+ * @param attributes a map of attributes
69+ * @return parameters
70+ */
71+ public static @ NotNull SentryMetricsParameters create (
72+ final @ Nullable Map <String , Object > attributes ) {
73+ return create (null , SentryAttributes .fromMap (attributes ));
74+ }
6375}
Original file line number Diff line number Diff line change @@ -3324,6 +3324,36 @@ class ScopesTest {
33243324 )
33253325 }
33263326
3327+ @Test
3328+ fun `creating count metric with attributes from map and shortcut factory method works` () {
3329+ val (sut, mockClient) = getEnabledScopes()
3330+
3331+ sut
3332+ .metrics()
3333+ .count(
3334+ " metric name" ,
3335+ 1.0 ,
3336+ " visit" ,
3337+ SentryMetricsParameters .create(mapOf (" attrname1" to " attrval1" )),
3338+ )
3339+
3340+ verify(mockClient)
3341+ .captureMetric(
3342+ check {
3343+ assertEquals(" metric name" , it.name)
3344+ assertEquals(1.0 , it.value)
3345+ assertEquals(" visit" , it.unit)
3346+ assertEquals(" counter" , it.type)
3347+
3348+ val attr1 = it.attributes?.get(" attrname1" )!!
3349+ assertEquals(" attrval1" , attr1.value)
3350+ assertEquals(" string" , attr1.type)
3351+ },
3352+ anyOrNull(),
3353+ anyOrNull(),
3354+ )
3355+ }
3356+
33273357 @Test
33283358 fun `creating count metric with attributes works` () {
33293359 val (sut, mockClient) = getEnabledScopes()
You can’t perform that action at this time.
0 commit comments