You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also, should Sentry.startSpan() not be named Sentry.withSpan()?
Solution Brainstorm
Rudimentary span implementation:
exportfunctionWithSpan(spanConfig?: SentryTypes.StartSpanOptions,): MethodDecorator{// @ts-expect-error -- Not sure what the error isreturnfunction<Textends(...args: readonlyunknown[])=>Promise<unknown>>(target: object,propertyKey: string|symbol,descriptor: TypedPropertyDescriptor<T>,){constoriginalMethod=descriptor.value;// istanbul ignore nextif(!originalMethod)return;constconfig: SentryTypes.StartSpanOptions=spanConfig??{name: target.constructor.name+'.'+propertyKey.toString(),op: 'method',};// @ts-expect-error -- Not sure what the error isdescriptor.value=function(...args: unknown[]): Promise<unknown>{returnSentry.startSpan(config,()=>originalMethod.apply(this,args));};};}
It is a lot more convenient to attach decorators to class methods
So technically yes, this would be a nice feature. However, we didn't add decorators yet because decorators are not used widely and there are multiple different experimental stages (TS experimentalDecorators vs JS decorators; see TC39 proposal). Also Node doesn't support them without transpilation. This makes it hard to add a feature to the SDK that is supposed to support a variety of older ES/Node versions. The exception to the rule is our Angular SDK where we can already use decorators as the Angular framework supports them well (with transpilation under the hood but in this case it's safe).
If decorators work fine in your setup, I suggest to write them yourself. Might even be a nice idea to publish them. Maybe in a distant future, we can add such decorators to the SDK.
Also, should Sentry.startSpan() not be named Sentry.withSpan()?
This is unfortunately a bit of a rabbit hole for us but we decided against withSpan to more closely match OpenTelemetry APIs. We're not fully there (startSpan vs. startActiveSpan) but that's the direction we want to move towards. This was discussed and decided in getsentry/rfcs#101 and getsentry/rfcs#113.
I'm going to close this issue for the time being because I don't think we can actionably incorporate these suggestions at the moment. Feel free to ping me if you think this should be reopened. Thanks!
(TS experimentalDecorators vs JS decorators; see TC39 proposal)
Interesting to see the proposal differ from TS' implementation. I was not aware.
I disagree with the other arguments about runtimes not supporting decorators, as, from the lib's perspective, decorators are merely functions. A library may provide it regardless of whether the user is capable of consuming that, is my stance on that.
Regardless, a missing standard is a counter-argument strong enough.
Activity
Lms24 commentedon Apr 2, 2024
Hey @jeengbe thx for the suggestions!
So technically yes, this would be a nice feature. However, we didn't add decorators yet because decorators are not used widely and there are multiple different experimental stages (TS
experimentalDecoratorsvs JS decorators; see TC39 proposal). Also Node doesn't support them without transpilation. This makes it hard to add a feature to the SDK that is supposed to support a variety of older ES/Node versions. The exception to the rule is our Angular SDKwhere we can already use decorators as the Angular framework supports them well (with transpilation under the hood but in this case it's safe).
If decorators work fine in your setup, I suggest to write them yourself. Might even be a nice idea to publish them. Maybe in a distant future, we can add such decorators to the SDK.
This is unfortunately a bit of a rabbit hole for us but we decided against
withSpanto more closely match OpenTelemetry APIs. We're not fully there (startSpan vs. startActiveSpan) but that's the direction we want to move towards. This was discussed and decided in getsentry/rfcs#101 and getsentry/rfcs#113.I'm going to close this issue for the time being because I don't think we can actionably incorporate these suggestions at the moment. Feel free to ping me if you think this should be reopened. Thanks!
jeengbe commentedon Apr 2, 2024
Interesting to see the proposal differ from TS' implementation. I was not aware.
I disagree with the other arguments about runtimes not supporting decorators, as, from the lib's perspective, decorators are merely functions. A library may provide it regardless of whether the user is capable of consuming that, is my stance on that.
Regardless, a missing standard is a counter-argument strong enough.