Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(browser): Add INP support for v8 #11650

Merged
merged 13 commits into from
Apr 22, 2024
Merged

feat(browser): Add INP support for v8 #11650

merged 13 commits into from
Apr 22, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 17, 2024

This is a step to support INP on v8.
It tries to forward port some stuff that has been merged into v7. It is a bit tricky to do this properly as this was spread over multiple PRs and cannot be directly ported at once.

Closes #10945

Copy link
Contributor

github-actions bot commented Apr 17, 2024

size-limit report 📦

Path Size
@sentry/browser 21.67 KB (0%)
@sentry/browser (incl. Tracing) 32.64 KB (+3.94% 🔺)
@sentry/browser (incl. Tracing, Replay) 67.92 KB (+1.78% 🔺)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.32 KB (+1.96% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) 71.74 KB (+1.67% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) 84.14 KB (+1.43% 🔺)
@sentry/browser (incl. Feedback) 37.78 KB (0%)
@sentry/browser (incl. sendFeedback) 26.45 KB (0%)
@sentry/browser (incl. FeedbackAsync) 30.93 KB (0%)
@sentry/react 24.35 KB (0%)
@sentry/react (incl. Tracing) 35.54 KB (+3.6% 🔺)
@sentry/vue 25.25 KB (+0.22% 🔺)
@sentry/vue (incl. Tracing) 34.4 KB (+3.86% 🔺)
@sentry/svelte 21.79 KB (0%)
CDN Bundle 23.97 KB (0%)
CDN Bundle (incl. Tracing) 33.88 KB (+3.75% 🔺)
CDN Bundle (incl. Tracing, Replay) 67.41 KB (+1.67% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 83.22 KB (+1.38% 🔺)
CDN Bundle - uncompressed 70.62 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 100.67 KB (+3.5% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 210.08 KB (+1.52% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.39 KB (+1.26% 🔺)
@sentry/nextjs (client) 34.77 KB (+3.36% 🔺)
@sentry/sveltekit (client) 33.13 KB (+3.86% 🔺)
@sentry/node 157.31 KB (+0.01% 🔺)

@@ -54,6 +55,9 @@ export interface SpanJSON {
trace_id: string;
origin?: SpanOrigin;
_metrics_summary?: Record<string, Array<MetricSummary>>;
profile_id?: string;
exclusive_time?: number;
measurements: Measurements;
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
measurements: Measurements;
measurements?: Measurements;

@@ -54,6 +55,9 @@ export interface SpanJSON {
trace_id: string;
origin?: SpanOrigin;
_metrics_summary?: Record<string, Array<MetricSummary>>;
profile_id?: string;
Copy link
Member Author

Choose a reason for hiding this comment

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

@jjbayer just to check if this is technically correct: Can we send these fields for a span both in the (current) span envelope, as well as for a span in a transaction event?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be clear we wont actually set this ever for spans in a transaction event, but the types for these are shared right now...

Copy link
Member

Choose a reason for hiding this comment

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

Can we send these fields for a span both in the (current) span envelope, as well as for a span in a transaction event?
Yes.

@@ -54,6 +55,9 @@ export interface SpanJSON {
trace_id: string;
origin?: SpanOrigin;
_metrics_summary?: Record<string, Array<MetricSummary>>;
profile_id?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Can we send these fields for a span both in the (current) span envelope, as well as for a span in a transaction event?
Yes.

measurements: { inp: { value: expect.any(Number), unit: expect.any(String) } },
};

expect(spanEnvelopeItem[0].type).toBe('span');
Copy link
Member

Choose a reason for hiding this comment

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

@cleptric I wonder, should we send an otel_span here instead? Since we discussed yesterday that SDKs should not longer send span items going forward.

Copy link
Member

Choose a reason for hiding this comment

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

INP and the upcoming HTTP.CLIENT spans are the only exception, which only applies to the JS SDK. I'm afraid we would also delay the v8 release too much, so I think it's the pragmatic solution to move forward here.

Copy link
Member Author

Choose a reason for hiding this comment

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

we can eventually update this and send something else! This is all internal stuff, so we can change it in the v8 cycle I think.

Comment on lines 77 to 78
await page.locator('[data-test-id=interaction-button]').click();
const envelope = await getMultipleSentryEnvelopeRequests<Event>(page, 1);
const envelope = await getMultipleSentryEnvelopeRequests<SentryEvent>(page, 1);
Copy link
Member

Choose a reason for hiding this comment

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

To avoid flakes I'd recommend

  1. start listening for the envelope by calling getMultipleSentryEnvelopeRequests and storing the promise
  2. clicking
  3. awaiting the promise.

@s1gr1d s1gr1d marked this pull request as ready for review April 22, 2024 09:28
@@ -143,7 +143,7 @@ function maybeSend(spans: ReadableSpan[]): ReadableSpan[] {
transactionEvent.spans = spans;

const measurements = timedEventsToMeasurements(span.events);
if (Object.keys(measurements).length) {
if (measurements && Object.keys(measurements).length) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we can remove this check then, as we actually do this in timedEventsToMeasurements now?

Suggested change
if (measurements && Object.keys(measurements).length) {
if (measurements) {

@@ -281,6 +281,7 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], remai
op,
origin,
_metrics_summary: getMetricSummaryJsonForSpan(span as unknown as Span),
measurements: timedEventsToMeasurements(span.events),
Copy link
Member Author

Choose a reason for hiding this comment

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

do we actually need/want this here? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess it's fine, lets leave it in!

Copy link
Member

Choose a reason for hiding this comment

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

If there are not measurements, the key gets dropped anyway :)

import type { InternalGlobal } from '../src/worldwide';
import { GLOBAL_OBJ } from '../src/worldwide';

describe('envelope', () => {
describe('createSpanEnvelope()', () => {
it('span-envelope-item of INP event has the correct object structure', () => {
const attributes: SpanAttributes = dropUndefinedKeys({
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we don't need dropUndefinedKeys here as we are manually building this object!

Copy link
Member Author

@mydea mydea left a comment

Choose a reason for hiding this comment

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

Just some small things, overall looking great!

[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: metric.value,
});

const envelope = span ? createSpanEnvelope([span]) : undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

span should always be defined here, no need to check for existence:

Suggested change
const envelope = span ? createSpanEnvelope([span]) : undefined;
const envelope = createSpanEnvelope([span]);


const envelope = span ? createSpanEnvelope([span]) : undefined;
const transport = client && client.getTransport();
if (transport && envelope) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
if (transport && envelope) {
if (transport) {

@s1gr1d s1gr1d enabled auto-merge (squash) April 22, 2024 11:58
@s1gr1d s1gr1d merged commit d679e7c into develop Apr 22, 2024
97 checks passed
@s1gr1d s1gr1d deleted the fn/inp-v8-port branch April 22, 2024 13:28
@s1gr1d
Copy link
Member

s1gr1d commented Apr 22, 2024

as a sidenote: I approved the PR, even though I was working on it 😅 @mydea created the PR and could therefore not approve (but gave me the "go" to do so)

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.

[v8] Add INP support
5 participants