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(core): Deprecate span startTimestamp & endTimestamp #10192

Merged
merged 1 commit into from Jan 16, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 16, 2024

Instead, you can use spanToJSON() to read the timestamps. Updating timestamps after span creation will not be possible in v8.

Also ensure that span.end() can only be called once - we already do that for transactions, and it saves us from checking e.g. span.endTimestamp before calling span.end(). This is also aligned with how OTEL does it (they emit a warning if trying to end a span twice).

@mydea mydea self-assigned this Jan 16, 2024
@@ -12,9 +12,14 @@ export function isMeasurementValue(value: unknown): value is number {
* Helper function to start child on transactions. This function will make sure that the transaction will
* use the start timestamp of the created child span if it is earlier than the transactions actual
* start timestamp.
*
* Note: this will not be possible anymore in v8,
* unless we do some special handling for browser here...
*/
export function _startChild(transaction: Transaction, { startTimestamp, ...ctx }: SpanContext): Span {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is really the main place I found where we are overwriting the start time in a way that is not really compatible with the new model. How bad is it to drop this in v8, I wonder? 🤔 if we want to keep it we'll have to do some trickery to make this work here.

Copy link
Member

Choose a reason for hiding this comment

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

This is very important because we use it to clamp the start timestamp of page load transactions to the browser native measurements for when the request started.

Do you have anything in mind on how we could still have this functionality?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMHO since this is a browser specific thing we'll probably use some internal/private API for this here... I don't think this is possible to do with OTEL native APIs. so probably we'll have to do something like this:

function clampSpanStartTime(span: Span, startTime: number) {
  const existingStartTime = spanToJSON(span).start_timestamp;
  if (!existingStartTime || existingStartTime > startTime) {
    (span as BrowserInternalSpan).updateStartTime(startTime);
  }
}

or something along these lines, if you know what I mean..? Not pretty, but 🤷

Copy link
Contributor

github-actions bot commented Jan 16, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.27 KB (+0.2% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.59 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.23 KB (+0.15% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.62 KB (+0.32% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.13 KB (+0.13% 🔺)
@sentry/browser - Webpack (gzipped) 22.48 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 74.89 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 66.52 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.36 KB (+0.26% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.13 KB (+0.18% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 209.56 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 97.61 KB (+0.09% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 72.23 KB (+0.21% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35.4 KB (+0.27% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.98 KB (+0.17% 🔺)
@sentry/react - Webpack (gzipped) 22.52 KB (+0.18% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.61 KB (+0.08% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.73 KB (+0.14% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.11 KB (0%)

Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

Generally lgtm. We should add a migration guide though! Ideally we explain how to truncate transactions and spans after the fact (before sending).

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice! As long as we find a way to somehow solve the IdleTransaction/Span use case for correcting the start time, I'm totally on board.

Random thought: If nothing else works, maybe we need to store the updated timestamp as an attribute and set the timestamp to this attribute value when processing 🤔

@mydea
Copy link
Member Author

mydea commented Jan 16, 2024

Ah, totally forgot to update MIGRATIONS.md, will do that!

As long as we find a way to somehow solve the IdleTransaction/Span use case for correcting the start time, I'm totally on board.

This is generally OK because there we want to set the transaction end time to a specific timestamp based on the spans, which we can still do with these APIs. the tricky thing is updating the start time of the transaction retrospectively...

Instead, you can use `spanToJSON()` to _read_ the timestamps.
Updating timestamps after span creation will not be possible in v8.

Also ensure that `span.end()` can only be called once.
@mydea mydea force-pushed the fn/deprecate-span-timestamps branch from 49a6531 to 3c8260a Compare January 16, 2024 12:44
@mydea mydea merged commit 2974df6 into develop Jan 16, 2024
96 checks passed
@mydea mydea deleted the fn/deprecate-span-timestamps branch January 16, 2024 14:02
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.

None yet

3 participants