Skip to content

Commit 2c71a19

Browse files
committed
use new Primitive type rather than listing primitives
1 parent 4e94e5f commit 2c71a19

File tree

13 files changed

+42
-30
lines changed

13 files changed

+42
-30
lines changed

MIGRATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ like this:
8888

8989
## New Scope functions
9090

91-
We realized how annoying it is to set a whole object using `setExtra`, that's why there are now a few new methods on the
91+
We realized how annoying it is to set a whole object using `setExtra`, so there are now a few new methods on the
9292
`Scope`.
9393

9494
```typescript
95-
setTags(tags: { [key: string]: string | number | boolean | undefined }): this;
95+
setTags(tags: { [key: string]: string | number | boolean | bigint| symbol| null | undefined }): this;
9696
setExtras(extras: { [key: string]: any }): this;
9797
clearBreadcrumbs(): this;
9898
```

packages/hub/src/hub.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Hub as HubInterface,
1212
Integration,
1313
IntegrationClass,
14+
Primitive,
1415
SessionContext,
1516
Severity,
1617
Span,
@@ -261,7 +262,7 @@ export class Hub implements HubInterface {
261262
/**
262263
* @inheritDoc
263264
*/
264-
public setTags(tags: { [key: string]: string | number | boolean | undefined }): void {
265+
public setTags(tags: { [key: string]: Primitive }): void {
265266
const scope = this.getScope();
266267
if (scope) scope.setTags(tags);
267268
}
@@ -277,7 +278,7 @@ export class Hub implements HubInterface {
277278
/**
278279
* @inheritDoc
279280
*/
280-
public setTag(key: string, value: string | number | boolean | undefined): void {
281+
public setTag(key: string, value: Primitive): void {
281282
const scope = this.getScope();
282283
if (scope) scope.setTag(key, value);
283284
}

packages/hub/src/scope.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EventProcessor,
1010
Extra,
1111
Extras,
12+
Primitive,
1213
Scope as ScopeInterface,
1314
ScopeContext,
1415
Severity,
@@ -41,7 +42,7 @@ export class Scope implements ScopeInterface {
4142
protected _user: User = {};
4243

4344
/** Tags */
44-
protected _tags: { [key: string]: string | number | boolean | undefined } = {};
45+
protected _tags: { [key: string]: Primitive } = {};
4546

4647
/** Extra */
4748
protected _extra: Extras = {};
@@ -124,7 +125,7 @@ export class Scope implements ScopeInterface {
124125
/**
125126
* @inheritDoc
126127
*/
127-
public setTags(tags: { [key: string]: string | number | boolean | undefined }): this {
128+
public setTags(tags: { [key: string]: Primitive }): this {
128129
this._tags = {
129130
...this._tags,
130131
...tags,
@@ -136,7 +137,7 @@ export class Scope implements ScopeInterface {
136137
/**
137138
* @inheritDoc
138139
*/
139-
public setTag(key: string, value: string | number | boolean | undefined): this {
140+
public setTag(key: string, value: Primitive): this {
140141
this._tags = { ...this._tags, [key]: value };
141142
this._notifyScopeListeners();
142143
return this;

packages/minimal/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Event,
77
Extra,
88
Extras,
9+
Primitive,
910
Severity,
1011
Transaction,
1112
TransactionContext,
@@ -127,7 +128,7 @@ export function setExtras(extras: Extras): void {
127128
* Set an object that will be merged sent as tags data with the event.
128129
* @param tags Tags context object to merge into current context.
129130
*/
130-
export function setTags(tags: { [key: string]: string | number | boolean | undefined }): void {
131+
export function setTags(tags: { [key: string]: Primitive }): void {
131132
callOnHub<void>('setTags', tags);
132133
}
133134

@@ -148,7 +149,7 @@ export function setExtra(key: string, extra: Extra): void {
148149
* @param key String key of tag
149150
* @param value Value of tag
150151
*/
151-
export function setTag(key: string, value: string | number | boolean | undefined): void {
152+
export function setTag(key: string, value: Primitive): void {
152153
callOnHub<void>('setTag', key, value);
153154
}
154155

packages/react/src/reactrouterv3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Transaction, TransactionContext } from '@sentry/types';
1+
import { Primitive, Transaction, TransactionContext } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils';
33

44
import { Location, ReactRouterInstrumentation } from './types';
@@ -62,7 +62,7 @@ export function reactRouterV3Instrumentation(
6262
if (activeTransaction) {
6363
activeTransaction.finish();
6464
}
65-
const tags: Record<string, string | number | boolean | undefined> = {
65+
const tags: Record<string, Primitive> = {
6666
'routing.instrumentation': 'react-router-v3',
6767
};
6868
if (prevName) {

packages/tracing/src/span.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines */
2-
import { Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
2+
import { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
33
import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils';
44

55
import { SpanStatus } from './spanstatus';
@@ -86,7 +86,7 @@ export class Span implements SpanInterface {
8686
/**
8787
* @inheritDoc
8888
*/
89-
public tags: { [key: string]: string | number | boolean | undefined } = {};
89+
public tags: { [key: string]: Primitive } = {};
9090

9191
/**
9292
* @inheritDoc
@@ -187,7 +187,7 @@ export class Span implements SpanInterface {
187187
/**
188188
* @inheritDoc
189189
*/
190-
public setTag(key: string, value: string | number | boolean | undefined): this {
190+
public setTag(key: string, value: Primitive): this {
191191
this.tags = { ...this.tags, [key]: value };
192192
return this;
193193
}
@@ -257,7 +257,7 @@ export class Span implements SpanInterface {
257257
parent_span_id?: string;
258258
span_id: string;
259259
status?: string;
260-
tags?: { [key: string]: string | number | boolean | undefined };
260+
tags?: { [key: string]: Primitive };
261261
trace_id: string;
262262
} {
263263
return dropUndefinedKeys({
@@ -284,7 +284,7 @@ export class Span implements SpanInterface {
284284
span_id: string;
285285
start_timestamp: number;
286286
status?: string;
287-
tags?: { [key: string]: string | number | boolean | undefined };
287+
tags?: { [key: string]: Primitive };
288288
timestamp?: number;
289289
trace_id: string;
290290
} {

packages/types/src/event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Breadcrumb } from './breadcrumb';
22
import { Contexts } from './context';
33
import { Exception } from './exception';
44
import { Extras } from './extra';
5+
import { Primitive } from './misc';
56
import { Request } from './request';
67
import { CaptureContext } from './scope';
78
import { SdkInfo } from './sdkinfo';
@@ -35,7 +36,7 @@ export interface Event {
3536
stacktrace?: Stacktrace;
3637
breadcrumbs?: Breadcrumb[];
3738
contexts?: Contexts;
38-
tags?: { [key: string]: string | number | boolean | undefined };
39+
tags?: { [key: string]: Primitive };
3940
extra?: Extras;
4041
user?: User;
4142
type?: EventType;

packages/types/src/hub.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Client } from './client';
33
import { Event, EventHint } from './event';
44
import { Extra, Extras } from './extra';
55
import { Integration, IntegrationClass } from './integration';
6+
import { Primitive } from './misc';
67
import { Scope } from './scope';
78
import { Session, SessionContext } from './session';
89
import { Severity } from './severity';
@@ -127,7 +128,7 @@ export interface Hub {
127128
*
128129
* @param tags Tags context object to merge into current context.
129130
*/
130-
setTags(tags: { [key: string]: string | number | boolean | undefined }): void;
131+
setTags(tags: { [key: string]: Primitive }): void;
131132

132133
/**
133134
* Set key:value that will be sent as tags data with the event.
@@ -137,7 +138,7 @@ export interface Hub {
137138
* @param key String key of tag
138139
* @param value Value of tag
139140
*/
140-
setTag(key: string, value: string | number | boolean | undefined): void;
141+
setTag(key: string, value: Primitive): void;
141142

142143
/**
143144
* Set key:value that will be sent as extra data with the event.

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export { Hub } from './hub';
1111
export { Integration, IntegrationClass } from './integration';
1212
export { LogLevel } from './loglevel';
1313
export { Mechanism } from './mechanism';
14-
export { ExtractedNodeRequestData, WorkerLocation } from './misc';
14+
export { ExtractedNodeRequestData, NonPrimitive, Primitive, WorkerLocation } from './misc';
1515
export { Options } from './options';
1616
export { Package } from './package';
1717
export { Request, SentryRequest, SentryRequestType } from './request';

packages/types/src/misc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ export interface WorkerLocation {
5959
/** Synonym for `href` attribute */
6060
toString(): string;
6161
}
62+
63+
export type Primitive = number | string | boolean | bigint | symbol | null | undefined;
64+
65+
// at eslint's suggestion, not using 'object' because https://github.com/microsoft/TypeScript/issues/21732 is still open
66+
export type NonPrimitive = Record<string, unknown>;

0 commit comments

Comments
 (0)