Skip to content

Aggregate metrics for spans#3238

Merged
markushi merged 16 commits into
mainfrom
feat/metrics-span-aggregations
Mar 6, 2024
Merged

Aggregate metrics for spans#3238
markushi merged 16 commits into
mainfrom
feat/metrics-span-aggregations

Conversation

@markushi

@markushi markushi commented Feb 29, 2024

Copy link
Copy Markdown
Member

📜 Description

Aggregate metrics based on spans: https://develop.sentry.dev/sdk/metrics/#span-aggregation.

image image

#skip-changelog
-- as the feature hasn't been released yet.

💡 Motivation and Context

Example event: https://sentry-sdks.sentry.io/performance/sentry-android%3A70c95de097d64ca68ebdbbe6f923d625/?openPanel=open&referrer=metrics#span-a39379e81c714978

In order to improve the link between metrics and spans (see RFC) we want to aggregate metric emissions when a span is active.

The span summary is grouped by export_key (an unique identifier, ignoring the metric tags) and then by metric_key (an unique identifier, including metric tags), the RFC provides a good example to illustrate why this is practical.

💚 How did you test it?

Added unit tests, as well as an integration test

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions

github-actions Bot commented Feb 29, 2024

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 36b152e

@github-actions

github-actions Bot commented Feb 29, 2024

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 389.98 ms 447.06 ms 57.08 ms
Size 1.70 MiB 2.28 MiB 592.02 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
b7fa26f 440.10 ms 533.98 ms 93.88 ms
6b4dd70 399.62 ms 479.08 ms 79.47 ms
3d8bd2b 379.45 ms 450.36 ms 70.90 ms
4e29063 376.38 ms 390.98 ms 14.60 ms
86f0096 368.63 ms 446.92 ms 78.29 ms
0bd723b 412.52 ms 496.65 ms 84.13 ms
d6d2b2e 463.14 ms 545.56 ms 82.42 ms
4e29063 384.14 ms 447.74 ms 63.60 ms
4e260b3 378.73 ms 454.18 ms 75.45 ms
c7e2fbc 398.35 ms 468.52 ms 70.17 ms

App size

Revision Plain With Sentry Diff
b7fa26f 1.70 MiB 2.27 MiB 583.82 KiB
6b4dd70 1.70 MiB 2.27 MiB 583.82 KiB
3d8bd2b 1.72 MiB 2.29 MiB 577.53 KiB
4e29063 1.72 MiB 2.29 MiB 578.38 KiB
86f0096 1.72 MiB 2.29 MiB 576.50 KiB
0bd723b 1.72 MiB 2.29 MiB 578.09 KiB
d6d2b2e 1.72 MiB 2.27 MiB 555.05 KiB
4e29063 1.72 MiB 2.29 MiB 578.38 KiB
4e260b3 1.72 MiB 2.27 MiB 554.95 KiB
c7e2fbc 1.72 MiB 2.29 MiB 576.40 KiB

Previous results on branch: feat/metrics-span-aggregations

Startup times

Revision Plain With Sentry Diff
350fd13 411.08 ms 511.49 ms 100.41 ms
450fa50 399.91 ms 474.27 ms 74.35 ms
a5701de 385.06 ms 457.86 ms 72.79 ms
f88769c 381.13 ms 464.45 ms 83.32 ms
bac9455 398.20 ms 538.94 ms 140.74 ms
7ebd815 376.46 ms 456.26 ms 79.80 ms
b26392f 356.48 ms 429.53 ms 73.05 ms

App size

Revision Plain With Sentry Diff
350fd13 1.70 MiB 2.28 MiB 591.92 KiB
450fa50 1.70 MiB 2.28 MiB 591.92 KiB
a5701de 1.70 MiB 2.28 MiB 591.93 KiB
f88769c 1.70 MiB 2.28 MiB 591.91 KiB
bac9455 1.70 MiB 2.28 MiB 591.91 KiB
7ebd815 1.70 MiB 2.28 MiB 591.91 KiB
b26392f 1.70 MiB 2.28 MiB 591.97 KiB

Comment thread sentry/src/main/java/io/sentry/Hub.java Outdated
Comment thread sentry/src/main/java/io/sentry/Span.java Outdated
Comment thread sentry/src/main/java/io/sentry/Span.java Outdated
measurements = reader.nextMapOrNull(logger, new MeasurementValue.Deserializer());
break;
case JsonKeys.METRICS_SUMMARY:
if (reader.peek() == JsonToken.NULL) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this logic into a new method in JsonObjectReader like nextMapOfListOrNull?
So we can reuse it in other places, like SentryTransaction

val span = fixture.getSut()
assertNotNull(span.localMetricsAggregator)

assertSame(span.localMetricsAggregator, span.localMetricsAggregator)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a mistake?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope this is intended, it just ensures the getter returns a reference to the same LocalMetricsAggregator.
Let me add a comment for this 👍

val aggregator = mock<IMetricsAggregator>()
val localMetricsAggregator = mock<LocalMetricsAggregator>()

val api = MetricsApi(object : IMetricsInterface {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this into a Fixture class, and the verifys into some private methods

@stefanosiano stefanosiano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left few minor comments, but good!

@markushi
markushi merged commit e37359d into main Mar 6, 2024
@markushi
markushi deleted the feat/metrics-span-aggregations branch March 6, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants