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 tags, data, context & setters #10053

Merged
merged 1 commit into from
Jan 10, 2024
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 4, 2024

Also deprecate direct access to span.attributes (instead use spanToJSON(span)).

There are a few usages that we still need to figure out how we will replace them...!

@mydea mydea self-assigned this Jan 4, 2024
@@ -159,6 +159,8 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
// Always call onProfileHandler to ensure stopProfiling is called and the timeout is cleared.
void onProfileHandler().then(
() => {
// TODO: Can we rewrite this to use attributes?
// eslint-disable-next-line deprecation/deprecation
transaction.setContext('profile', { profile_id: profileId, start_timestamp: startTimestamp });
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @JonasBa we either need to move this to be an attribute (~~data) on the transaction, or find a way to set these on the surrounding scope of the transaction instead 🤔 nothing to do in this PR but when we actually remove this in v8 we need to handle this somehow.

Copy link
Member

Choose a reason for hiding this comment

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

Ok sounds good. Thanks for the ping!

@@ -145,6 +145,7 @@ export class IdleTransaction extends Transaction {
this.activities = {};

if (this.op === 'ui.action.click') {
// eslint-disable-next-line deprecation/deprecation
this.setTag(FINISH_REASON_TAG, this._finishReason);
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 need this tag on the idle transaction in v8? @AbhiPrasad

Copy link
Member

Choose a reason for hiding this comment

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

No we don't, we can remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll just change it to an attribute then!

import { dropUndefinedKeys, generateSentryTraceHeader } from '@sentry/utils';

/**
* Convert a span to a trace context, which can be sent as the `trace` context in an event.
*/
export function spanToTraceContext(span: Span): TraceContext {
const { data, description, op, parent_span_id, span_id, status, tags, trace_id, origin } = span.toJSON();
const {
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 conflicted with some tests, but I figured it is overall safer as we assumed that this always is a Span class instance with toJSON() which may be a bit unsafe. Now we just treat this as a POJO which should be safer (and .toJSON() will actually go away for v8 as well, so we may as well already do that now)

// Since formDataObject is not a primitive, we cannot store it on the span as attributes
// so instead we put it as extra on the scope
const scope = getCurrentScope();
scope.setExtra('server_action_form_data', formDataObject);
Copy link
Member Author

Choose a reason for hiding this comment

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

@lforst do we need this as a nested object here? attributes cannot be nested, so going forward we need to either flatten this, if the shape is known (which I guess it is not?), or store it as context on the scope (?), or as JSON string...

@@ -341,6 +341,8 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
trpcContext.input = normalize(rawInput);
}

// TODO: Can we rewrite this to an attribute? Or set this on the scope?
// eslint-disable-next-line deprecation/deprecation
sentryTransaction.setContext('trpc', trpcContext);
Copy link
Member Author

Choose a reason for hiding this comment

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

Any thoughts on this? Not sure how important that is, but I guess we need some way to access the scope of the sentryTransaction then we could just put it on there...?

@@ -201,17 +200,14 @@ function updateSpanWithOtelData(sentrySpan: SentrySpan, otelSpan: OtelSpan): voi
function updateTransactionWithOtelData(transaction: Transaction, otelSpan: OtelSpan): void {
const { op, description, source, data } = parseOtelSpanDescription(otelSpan);

// eslint-disable-next-line deprecation/deprecation
transaction.setContext('otel', {
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 this will generally go away in v8, so no need to worry about this.

Which reminds me, we should also deprecate these I guess...

Copy link
Contributor

github-actions bot commented Jan 4, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 76.66 KB (-0.24% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.02 KB (-0.28% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 61.65 KB (-0.31% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.29 KB (+0.16% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.74 KB (+0.04% 🔺)
@sentry/browser - Webpack (gzipped) 22.1 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 74.23 KB (-0.42% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 65.86 KB (-0.47% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.03 KB (+0.12% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.74 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 206.88 KB (-0.84% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 96.74 KB (+0.07% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 70.95 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35 KB (+0.1% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.4 KB (-0.28% 🔽)
@sentry/react - Webpack (gzipped) 22.13 KB (+0.04% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.12 KB (-0.24% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 49.48 KB (+0.09% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.75 KB (+0.06% 🔺)

@mydea mydea force-pushed the fn/spanData branch 2 times, most recently from 5ebab8f to 6cfe78b Compare January 4, 2024 14:48
} else {
formDataObject[key] = '[non-string value]';
}
span?.setAttribute(
Copy link
Member Author

Choose a reason for hiding this comment

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

After talking with @lforst, we decided to flatten this here, as the exact shape of this is not important, and thus we can more easily rewrite it to attributes!

@mydea mydea force-pushed the fn/spanData branch 2 times, most recently from 30dc0ac to 4cb5aaa Compare January 9, 2024 09:12
@mydea
Copy link
Member Author

mydea commented Jan 9, 2024

I updated this to use spanToJSON().

Also deprecate direct access to `span.attributes` (instead use `spanGetAttributes(span)`).

There are a few usages that we still need to figure out how we will replace them.
@mydea mydea merged commit a56fc29 into develop Jan 10, 2024
96 checks passed
@mydea mydea deleted the fn/spanData branch January 10, 2024 09:15
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

4 participants