-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ref(types): Loosen tag types, create new Primitive
type
#3108
Conversation
size-limit report
|
How about we create https://www.typescriptlang.org/docs/handbook/basic-types.html#object type Primititve = number | string | boolean | bigint | symbol | null | undefined;
type NonPrimitive = object; |
Oooh, I like it. Good idea. UPDATE: Done. |
MIGRATION.md
Outdated
`Scope`. | ||
|
||
```typescript | ||
setTags(tags: { [key: string]: string }): this; | ||
setTags(tags: { [key: string]: string | number | boolean | bigint| symbol| null | undefined }): this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I listed them out here in the migration doc for ease of reading, but used the Primitive
type everywhere in the code.
Primitive
type
b833312
to
3d4c98f
Compare
@@ -119,7 +119,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement | |||
let eventId: string | undefined = hint && hint.event_id; | |||
|
|||
const promisedEvent = isPrimitive(message) | |||
? this._getBackend().eventFromMessage(`${message}`, level, hint) | |||
? this._getBackend().eventFromMessage(String(message), level, hint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why the change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because symbols and bigints can't be automatically coerced to string form (see links in PR description) - you have to do it manually with String(x)
.
6d06745
to
d1355bd
Compare
One thing we'd like to have is the merged PR getsentry/sentry-javascript#3108, a type adjustment that lets us use `undefined` as a value in `setTag` and `setTags`. The author of that PR says that passing `undefined` for a tag's value is an unofficial way to unset a tag from the scope. If that works, we'd like to do it until getsentry/sentry-javascript#2218 is solved more officially. I see just one declared breaking change at 2.0.0 [1]: """ - build(android): Changes android package name from `io.sentry.RNSentryPackage` to `io.sentry.react.RNSentryPackage` (Breaking). zulip#1131 """ But autolinking handles the name change just fine, so there's nothing special we have to do about that. We don't have a complete libdef yet, but we seem to have good coverage for our usage in what we've translated from the TypeScript manually so far. So, double-check all of that against the new version and fix a few things that were slightly wrong or out-of-date (including by taking the relevant changes from getsentry/sentry-javascript#3108). [1] https://github.com/getsentry/sentry-react-native/blob/master/CHANGELOG.md#200
…sent. Instead of omitting them. We're about to start keeping these tags on the global scope, which means we have to listen to and propagate all changes in the server version, including changes where the server version disappears. It's been reported [1] that passing `undefined` as a tag's value in `setTags` will clear the tag from the current scope, and I've verified this experimentally. [1] getsentry/sentry-javascript#3108 (comment)
…sent. Instead of omitting them. We're about to start keeping these tags on the global scope, which means we have to listen to and propagate all changes in the server version, including changes where the server version disappears. It's been reported [1] that passing `undefined` as a tag's value in `setTags` will clear the tag from the current scope, and I've verified this experimentally. [1] getsentry/sentry-javascript#3108 (comment)
The only thing we do with tags is serialize/JSONify them, and any primitive* can handle that. And since we do that, relay isn't an issue, because all it ever sees from us is strings anyway.
This loosens the type requirements for tags to include all members of a new union type called
Primitive
. It also adds a note to thesetTag
docstring pointing out that a tag can be unset by passingundefined
. Finally, it refactorsisPrimitive()
into a type guard, and uses that type guard where possible.Doesn't fully answer the request in #2218, but at least it will stop people's linters from freaking out when they pass
undefined
, as we ourselves suggest.*Actually, symbols apparently don't let themselves be automatically cast to their string representation (EDIT: apparently BigInts don't either), so those are handled separately, in the
normalizeValue
function.