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): Add attributes to Span #10008

Merged
merged 2 commits into from
Jan 3, 2024
Merged

feat(core): Add attributes to Span #10008

merged 2 commits into from
Jan 3, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 2, 2024

Together with setAttribute() and setAttributes() APIs, mirroring the OpenTelemetry API for their spans.

For now, these are stored as data on spans/transactions, until we "directly" support them.

@mydea mydea self-assigned this Jan 2, 2024
public setData(key: string, value: any): this {
this.data = { ...this.data, [key]: value };
return this;
}

/** @inheritdoc */
public setAttribute(key: string, value: SpanAttributeValue | undefined): void {
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 chose to implement this in a mutating way, for a slight performance improvment I guess. But no strong feelings, if we prefer to always clone the attributes (like we currently do for data etc) we can also do that!

Copy link
Member

Choose a reason for hiding this comment

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

Hmm I'd argue that this implementation (be it mutable or not) is more correct since we're deleting the property when passing undefined. Should be fine.

Copy link
Contributor

github-actions bot commented Jan 2, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 76 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.36 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 60.98 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.94 KB (+0.25% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.42 KB (0%)
@sentry/browser - Webpack (gzipped) 22.12 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.4 KB (+0.09% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 65.08 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 31.24 KB (+0.28% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.15 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 204.1 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 93.99 KB (+0.25% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 68.69 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 34.2 KB (+0.26% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 67.77 KB (+0.12% 🔺)
@sentry/react - Webpack (gzipped) 22.16 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.42 KB (+0.1% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.05 KB (+0.15% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.63 KB (0%)

public setData(key: string, value: any): this {
this.data = { ...this.data, [key]: value };
return this;
}

/** @inheritdoc */
public setAttribute(key: string, value: SpanAttributeValue | undefined): void {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I'd argue that this implementation (be it mutable or not) is more correct since we're deleting the property when passing undefined. Should be fine.

/**
* @inheritDoc
*/
attributes: SpanAttributes;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's mark this as experimental in case we want to change something before v8.

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean the shape (SpanAttributes) or to have this at all on the span? This is also exposed this way on OTEL spans so I think there won't really be a way around exposing this for us as well 😅

Copy link
Member

Choose a reason for hiding this comment

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

ah okay, I didn't know that. If we know it's gonna stick around it's fine 👍

Together with `setAttribute()` and `setAttributes()` APIs, mirroring the OpenTelemetry API for their spans.

For now, these are stored as `data` on spans/transactions, until we "directly" support them.
@@ -297,7 +320,7 @@ export class Span implements SpanInterface {
*/
public toContext(): SpanContext {
return dropUndefinedKeys({
data: this.data,
data: this._getData(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Just to double check, I guess/hope it is not important that we never return undefined here? In contrast to toJSON() and getTraceContext()? I've aligned this here so that this always returns undefined if there is no data at all. cc @AbhiPrasad

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine that we never return 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.

but is it also fine to return undefined? 😅 otherwise I can update this to data: this._getData() || {} but IMHO if we don't need this we rather avoid it?

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'll I'm gonna merge this anyway, I think it should be fine, otherwise we can adjust it later.

@mydea mydea merged commit b7480d7 into develop Jan 3, 2024
95 checks passed
@mydea mydea deleted the fn/span-attributes branch January 3, 2024 08:53
anonrig pushed a commit that referenced this pull request Jan 3, 2024
Together with `setAttribute()` and `setAttributes()` APIs, mirroring the
OpenTelemetry API for their spans.

For now, these are stored as `data` on spans/transactions, until we
"directly" support them.
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.

4 participants