Skip to content

Commit 737f3ed

Browse files
committed
loosen tag types
1 parent 7710945 commit 737f3ed

File tree

11 files changed

+44
-29
lines changed

11 files changed

+44
-29
lines changed

MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ We realized how annoying it is to set a whole object using `setExtra`, that's wh
9292
`Scope`.
9393

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

packages/hub/src/hub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class Hub implements HubInterface {
261261
/**
262262
* @inheritDoc
263263
*/
264-
public setTags(tags: { [key: string]: string }): void {
264+
public setTags(tags: { [key: string]: string | number | boolean | undefined }): void {
265265
const scope = this.getScope();
266266
if (scope) scope.setTags(tags);
267267
}
@@ -277,7 +277,7 @@ export class Hub implements HubInterface {
277277
/**
278278
* @inheritDoc
279279
*/
280-
public setTag(key: string, value: string): void {
280+
public setTag(key: string, value: string | number | boolean | undefined): void {
281281
const scope = this.getScope();
282282
if (scope) scope.setTag(key, value);
283283
}

packages/hub/src/scope.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Scope implements ScopeInterface {
4141
protected _user: User = {};
4242

4343
/** Tags */
44-
protected _tags: { [key: string]: string } = {};
44+
protected _tags: { [key: string]: string | number | boolean | undefined } = {};
4545

4646
/** Extra */
4747
protected _extra: Extras = {};
@@ -124,7 +124,7 @@ export class Scope implements ScopeInterface {
124124
/**
125125
* @inheritDoc
126126
*/
127-
public setTags(tags: { [key: string]: string }): this {
127+
public setTags(tags: { [key: string]: string | number | boolean | undefined }): this {
128128
this._tags = {
129129
...this._tags,
130130
...tags,
@@ -136,7 +136,7 @@ export class Scope implements ScopeInterface {
136136
/**
137137
* @inheritDoc
138138
*/
139-
public setTag(key: string, value: string): this {
139+
public setTag(key: string, value: string | number | boolean | undefined): this {
140140
this._tags = { ...this._tags, [key]: value };
141141
this._notifyScopeListeners();
142142
return this;

packages/minimal/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function setExtras(extras: Extras): void {
127127
* Set an object that will be merged sent as tags data with the event.
128128
* @param tags Tags context object to merge into current context.
129129
*/
130-
export function setTags(tags: { [key: string]: string }): void {
130+
export function setTags(tags: { [key: string]: string | number | boolean | undefined }): void {
131131
callOnHub<void>('setTags', tags);
132132
}
133133

@@ -142,10 +142,13 @@ export function setExtra(key: string, extra: Extra): void {
142142

143143
/**
144144
* Set key:value that will be sent as tags data with the event.
145+
*
146+
* Can also be used to unset a tag, by passing `undefined`.
147+
*
145148
* @param key String key of tag
146-
* @param value String value of tag
149+
* @param value Value of tag
147150
*/
148-
export function setTag(key: string, value: string): void {
151+
export function setTag(key: string, value: string | number | boolean | undefined): void {
149152
callOnHub<void>('setTag', key, value);
150153
}
151154

packages/react/src/reactrouterv3.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export function reactRouterV3Instrumentation(
6262
if (activeTransaction) {
6363
activeTransaction.finish();
6464
}
65-
const tags: Record<string, string> = { 'routing.instrumentation': 'react-router-v3' };
65+
const tags: Record<string, string | number | boolean | undefined> = {
66+
'routing.instrumentation': 'react-router-v3',
67+
};
6668
if (prevName) {
6769
tags.from = prevName;
6870
}

packages/tracing/src/span.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class Span implements SpanInterface {
8686
/**
8787
* @inheritDoc
8888
*/
89-
public tags: { [key: string]: string } = {};
89+
public tags: { [key: string]: string | number | boolean | undefined } = {};
9090

9191
/**
9292
* @inheritDoc
@@ -187,7 +187,7 @@ export class Span implements SpanInterface {
187187
/**
188188
* @inheritDoc
189189
*/
190-
public setTag(key: string, value: string): this {
190+
public setTag(key: string, value: string | number | boolean | undefined): 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 };
260+
tags?: { [key: string]: string | number | boolean | undefined };
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 };
287+
tags?: { [key: string]: string | number | boolean | undefined };
288288
timestamp?: number;
289289
trace_id: string;
290290
} {

packages/types/src/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface Event {
3535
stacktrace?: Stacktrace;
3636
breadcrumbs?: Breadcrumb[];
3737
contexts?: Contexts;
38-
tags?: { [key: string]: string };
38+
tags?: { [key: string]: string | number | boolean | undefined };
3939
extra?: Extras;
4040
user?: User;
4141
type?: EventType;

packages/types/src/hub.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,20 @@ export interface Hub {
124124

125125
/**
126126
* Set an object that will be merged sent as tags data with the event.
127+
*
127128
* @param tags Tags context object to merge into current context.
128129
*/
129-
setTags(tags: { [key: string]: string }): void;
130+
setTags(tags: { [key: string]: string | number | boolean | undefined }): void;
130131

131132
/**
132133
* Set key:value that will be sent as tags data with the event.
134+
*
135+
* Can also be used to unset a tag, by passing `undefined`.
136+
*
133137
* @param key String key of tag
134-
* @param value String value of tag
138+
* @param value Value of tag
135139
*/
136-
setTag(key: string, value: string): void;
140+
setTag(key: string, value: string | number | boolean | undefined): void;
137141

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

packages/types/src/scope.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ScopeContext {
1717
level: Severity;
1818
extra: Extras;
1919
contexts: Contexts;
20-
tags: { [key: string]: string };
20+
tags: { [key: string]: string | number | boolean | undefined };
2121
fingerprint: string[];
2222
}
2323

@@ -45,14 +45,17 @@ export interface Scope {
4545
* Set an object that will be merged sent as tags data with the event.
4646
* @param tags Tags context object to merge into current context.
4747
*/
48-
setTags(tags: { [key: string]: string }): this;
48+
setTags(tags: { [key: string]: string | number | boolean | undefined }): this;
4949

5050
/**
5151
* Set key:value that will be sent as tags data with the event.
52+
*
53+
* Can also be used to unset a tag by passing `undefined`.
54+
*
5255
* @param key String key of tag
53-
* @param value String value of tag
56+
* @param value Value of tag
5457
*/
55-
setTag(key: string, value: string): this;
58+
setTag(key: string, value: string | number | boolean | undefined): this;
5659

5760
/**
5861
* Set an object that will be merged sent as extra data with the event.

packages/types/src/span.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface SpanContext {
4141
/**
4242
* Tags of the Span.
4343
*/
44-
tags?: { [key: string]: string };
44+
tags?: { [key: string]: string | number | boolean | undefined };
4545

4646
/**
4747
* Data of the Span.
@@ -79,7 +79,7 @@ export interface Span extends SpanContext {
7979
/**
8080
* @inheritDoc
8181
*/
82-
tags: { [key: string]: string };
82+
tags: { [key: string]: string | number | boolean | undefined };
8383

8484
/**
8585
* @inheritDoc
@@ -98,11 +98,14 @@ export interface Span extends SpanContext {
9898
finish(endTimestamp?: number): void;
9999

100100
/**
101-
* Sets the tag attribute on the current span
101+
* Sets the tag attribute on the current span.
102+
*
103+
* Can also be used to unset a tag, by passing `undefined`.
104+
*
102105
* @param key Tag key
103106
* @param value Tag value
104107
*/
105-
setTag(key: string, value: string): this;
108+
setTag(key: string, value: string | number | boolean | undefined): this;
106109

107110
/**
108111
* Sets the data attribute on the current span
@@ -156,7 +159,7 @@ export interface Span extends SpanContext {
156159
parent_span_id?: string;
157160
span_id: string;
158161
status?: string;
159-
tags?: { [key: string]: string };
162+
tags?: { [key: string]: string | number | boolean | undefined };
160163
trace_id: string;
161164
};
162165
/** Convert the object to JSON */
@@ -168,7 +171,7 @@ export interface Span extends SpanContext {
168171
span_id: string;
169172
start_timestamp: number;
170173
status?: string;
171-
tags?: { [key: string]: string };
174+
tags?: { [key: string]: string | number | boolean | undefined };
172175
timestamp?: number;
173176
trace_id: string;
174177
};

0 commit comments

Comments
 (0)