Skip to content

Commit 0fb047d

Browse files
committed
Added logic to stringify release if it is of type object
1 parent d98f5d6 commit 0fb047d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/hub/src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class Session implements SessionInterface {
115115
did: typeof this.did === 'number' || typeof this.did === 'string' ? `${this.did}` : undefined,
116116
duration: this.duration,
117117
attrs: dropUndefinedKeys({
118-
release: this.release,
118+
release: typeof this.release !== 'string' ? JSON.stringify(this.release) : this.release,
119119
environment: this.environment,
120120
ip_address: this.ipAddress,
121121
user_agent: this.userAgent,

packages/hub/test/session.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Session } from '../src';
2+
3+
describe('Session', () => {
4+
test('Release of type object is stringified in toJSON()', () => {
5+
const session = new Session({
6+
// @ts-ignore
7+
release: { name: 'whatever' },
8+
});
9+
expect(session.toJSON()).toEqual(
10+
expect.objectContaining({ attrs: { release: JSON.stringify({ name: 'whatever' }) } }),
11+
);
12+
});
13+
});

0 commit comments

Comments
 (0)