From d305f6215b59ae481834a595dcbfa42f350c585d Mon Sep 17 00:00:00 2001 From: Jonas Date: Thu, 16 Dec 2021 14:59:07 +0100 Subject: [PATCH] ref(types): deprecate transactionmethod enum (#4314) * ref(types): deprecate transactionmethod enum * fix(types): drop transactionsamplingmethod * ref(types): deprecate outcome enum (#4315) * ref(types): deprecate outcome enum * fix(types): drop transportoutcome * ref(types): deprecate request status enum (#4316) * ref(types): deprecate request status * ref(types): deprecate session status * ref(types): remove unused logLevel (#4317) (#4320) --- packages/browser/src/transports/fetch.ts | 8 ++-- packages/browser/src/transports/xhr.ts | 8 ++-- .../browser/test/unit/transports/base.test.ts | 32 ++++++++-------- .../test/unit/transports/fetch.test.ts | 9 ++--- .../browser/test/unit/transports/xhr.test.ts | 9 ++--- packages/core/src/baseclient.ts | 12 +++--- packages/core/test/lib/base.test.ts | 8 ++-- packages/core/test/lib/request.test.ts | 10 ++--- packages/hub/src/hub.ts | 5 +-- packages/hub/src/session.ts | 8 ++-- packages/hub/src/sessionflusher.ts | 6 +-- packages/hub/test/scope.test.ts | 26 ++++++------- packages/hub/test/session.test.ts | 22 +++++------ packages/hub/test/sessionflusher.test.ts | 24 ++++++------ packages/node/src/client.ts | 10 ++--- packages/node/src/handlers.ts | 9 +++-- packages/node/src/sdk.ts | 2 +- packages/node/test/client.test.ts | 37 +++++++++---------- packages/node/test/handlers.test.ts | 18 ++++----- packages/node/test/transports/http.test.ts | 4 +- packages/tracing/src/hubextensions.ts | 9 ++--- packages/tracing/src/transaction.ts | 3 +- packages/tracing/test/hub.test.ts | 9 ++--- packages/tracing/test/idletransaction.test.ts | 3 +- packages/types/src/index.ts | 1 - packages/types/src/loglevel.ts | 11 ------ packages/types/src/options.ts | 4 -- packages/types/src/requestsessionstatus.ts | 11 ++++++ packages/types/src/session.ts | 24 +----------- packages/types/src/sessionstatus.ts | 13 +++++++ packages/types/src/transaction.ts | 9 +---- packages/types/src/transport.ts | 15 ++++---- 32 files changed, 174 insertions(+), 205 deletions(-) delete mode 100644 packages/types/src/loglevel.ts create mode 100644 packages/types/src/requestsessionstatus.ts create mode 100644 packages/types/src/sessionstatus.ts diff --git a/packages/browser/src/transports/fetch.ts b/packages/browser/src/transports/fetch.ts index 241f2a1e8bc5..46c652bdea3e 100644 --- a/packages/browser/src/transports/fetch.ts +++ b/packages/browser/src/transports/fetch.ts @@ -1,5 +1,5 @@ import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core'; -import { Event, Outcome, Response, SentryRequest, Session, TransportOptions } from '@sentry/types'; +import { Event, Response, SentryRequest, Session, TransportOptions } from '@sentry/types'; import { SentryError, supportsReferrerPolicy, SyncPromise } from '@sentry/utils'; import { BaseTransport } from './base'; @@ -37,7 +37,7 @@ export class FetchTransport extends BaseTransport { */ private _sendRequest(sentryRequest: SentryRequest, originalPayload: Event | Session): PromiseLike { if (this._isRateLimited(sentryRequest.type)) { - this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type); + this.recordLostEvent('ratelimit_backoff', sentryRequest.type); return Promise.reject({ event: originalPayload, @@ -89,9 +89,9 @@ export class FetchTransport extends BaseTransport { .then(undefined, reason => { // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError. if (reason instanceof SentryError) { - this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type); + this.recordLostEvent('queue_overflow', sentryRequest.type); } else { - this.recordLostEvent(Outcome.NetworkError, sentryRequest.type); + this.recordLostEvent('network_error', sentryRequest.type); } throw reason; }); diff --git a/packages/browser/src/transports/xhr.ts b/packages/browser/src/transports/xhr.ts index 771cb16d2a51..1d5dd91f9c0b 100644 --- a/packages/browser/src/transports/xhr.ts +++ b/packages/browser/src/transports/xhr.ts @@ -1,5 +1,5 @@ import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core'; -import { Event, Outcome, Response, SentryRequest, Session } from '@sentry/types'; +import { Event, Response, SentryRequest, Session } from '@sentry/types'; import { SentryError, SyncPromise } from '@sentry/utils'; import { BaseTransport } from './base'; @@ -26,7 +26,7 @@ export class XHRTransport extends BaseTransport { */ private _sendRequest(sentryRequest: SentryRequest, originalPayload: Event | Session): PromiseLike { if (this._isRateLimited(sentryRequest.type)) { - this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type); + this.recordLostEvent('ratelimit_backoff', sentryRequest.type); return Promise.reject({ event: originalPayload, @@ -66,9 +66,9 @@ export class XHRTransport extends BaseTransport { .then(undefined, reason => { // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError. if (reason instanceof SentryError) { - this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type); + this.recordLostEvent('queue_overflow', sentryRequest.type); } else { - this.recordLostEvent(Outcome.NetworkError, sentryRequest.type); + this.recordLostEvent('network_error', sentryRequest.type); } throw reason; }); diff --git a/packages/browser/test/unit/transports/base.test.ts b/packages/browser/test/unit/transports/base.test.ts index 660163527048..9180fbabc8f3 100644 --- a/packages/browser/test/unit/transports/base.test.ts +++ b/packages/browser/test/unit/transports/base.test.ts @@ -1,5 +1,3 @@ -import { Outcome } from '@sentry/types'; - import { BaseTransport } from '../../../src/transports/base'; const testDsn = 'https://123@sentry.io/42'; @@ -44,12 +42,12 @@ describe('BaseTransport', () => { it('sends beacon request when there are outcomes captured and visibility changed to `hidden`', () => { const transport = new SimpleTransport({ dsn: testDsn, sendClientReports: true }); - transport.recordLostEvent(Outcome.BeforeSend, 'event'); + transport.recordLostEvent('before_send', 'event'); visibilityState = 'hidden'; document.dispatchEvent(new Event('visibilitychange')); - const outcomes = [{ reason: Outcome.BeforeSend, category: 'error', quantity: 1 }]; + const outcomes = [{ reason: 'before_send', category: 'error', quantity: 1 }]; expect(sendBeaconSpy).toHaveBeenCalledWith( envelopeEndpoint, @@ -59,7 +57,7 @@ describe('BaseTransport', () => { it('doesnt send beacon request when there are outcomes captured, but visibility state did not change to `hidden`', () => { const transport = new SimpleTransport({ dsn: testDsn, sendClientReports: true }); - transport.recordLostEvent(Outcome.BeforeSend, 'event'); + transport.recordLostEvent('before_send', 'event'); visibilityState = 'visible'; document.dispatchEvent(new Event('visibilitychange')); @@ -70,21 +68,21 @@ describe('BaseTransport', () => { it('correctly serializes request with different categories/reasons pairs', () => { const transport = new SimpleTransport({ dsn: testDsn, sendClientReports: true }); - transport.recordLostEvent(Outcome.BeforeSend, 'event'); - transport.recordLostEvent(Outcome.BeforeSend, 'event'); - transport.recordLostEvent(Outcome.SampleRate, 'transaction'); - transport.recordLostEvent(Outcome.NetworkError, 'session'); - transport.recordLostEvent(Outcome.NetworkError, 'session'); - transport.recordLostEvent(Outcome.RateLimitBackoff, 'event'); + transport.recordLostEvent('before_send', 'event'); + transport.recordLostEvent('before_send', 'event'); + transport.recordLostEvent('sample_rate', 'transaction'); + transport.recordLostEvent('network_error', 'session'); + transport.recordLostEvent('network_error', 'session'); + transport.recordLostEvent('ratelimit_backoff', 'event'); visibilityState = 'hidden'; document.dispatchEvent(new Event('visibilitychange')); const outcomes = [ - { reason: Outcome.BeforeSend, category: 'error', quantity: 2 }, - { reason: Outcome.SampleRate, category: 'transaction', quantity: 1 }, - { reason: Outcome.NetworkError, category: 'session', quantity: 2 }, - { reason: Outcome.RateLimitBackoff, category: 'error', quantity: 1 }, + { reason: 'before_send', category: 'error', quantity: 2 }, + { reason: 'sample_rate', category: 'transaction', quantity: 1 }, + { reason: 'network_error', category: 'session', quantity: 2 }, + { reason: 'ratelimit_backoff', category: 'error', quantity: 1 }, ]; expect(sendBeaconSpy).toHaveBeenCalledWith( @@ -97,12 +95,12 @@ describe('BaseTransport', () => { const tunnel = 'https://hello.com/world'; const transport = new SimpleTransport({ dsn: testDsn, sendClientReports: true, tunnel }); - transport.recordLostEvent(Outcome.BeforeSend, 'event'); + transport.recordLostEvent('before_send', 'event'); visibilityState = 'hidden'; document.dispatchEvent(new Event('visibilitychange')); - const outcomes = [{ reason: Outcome.BeforeSend, category: 'error', quantity: 1 }]; + const outcomes = [{ reason: 'before_send', category: 'error', quantity: 1 }]; expect(sendBeaconSpy).toHaveBeenCalledWith( tunnel, diff --git a/packages/browser/test/unit/transports/fetch.test.ts b/packages/browser/test/unit/transports/fetch.test.ts index caa47cd76773..afb427b4026e 100644 --- a/packages/browser/test/unit/transports/fetch.test.ts +++ b/packages/browser/test/unit/transports/fetch.test.ts @@ -1,4 +1,3 @@ -import { Outcome } from '@sentry/types'; import { SentryError } from '@sentry/utils'; import { Event, Response, Transports } from '../../../src'; @@ -117,7 +116,7 @@ describe('FetchTransport', () => { try { await transport.sendEvent(eventPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.NetworkError, 'event'); + expect(spy).toHaveBeenCalledWith('network_error', 'event'); } }); @@ -129,7 +128,7 @@ describe('FetchTransport', () => { try { await transport.sendEvent(transactionPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.QueueOverflow, 'transaction'); + expect(spy).toHaveBeenCalledWith('queue_overflow', 'transaction'); } }); @@ -490,13 +489,13 @@ describe('FetchTransport', () => { try { await transport.sendEvent(eventPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.RateLimitBackoff, 'event'); + expect(spy).toHaveBeenCalledWith('ratelimit_backoff', 'event'); } try { await transport.sendEvent(transactionPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.RateLimitBackoff, 'transaction'); + expect(spy).toHaveBeenCalledWith('ratelimit_backoff', 'transaction'); } }); }); diff --git a/packages/browser/test/unit/transports/xhr.test.ts b/packages/browser/test/unit/transports/xhr.test.ts index 95b5c840c763..fcf7c26211da 100644 --- a/packages/browser/test/unit/transports/xhr.test.ts +++ b/packages/browser/test/unit/transports/xhr.test.ts @@ -1,4 +1,3 @@ -import { Outcome } from '@sentry/types'; import { SentryError } from '@sentry/utils'; import { fakeServer, SinonFakeServer } from 'sinon'; @@ -79,7 +78,7 @@ describe('XHRTransport', () => { try { await transport.sendEvent(eventPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.NetworkError, 'event'); + expect(spy).toHaveBeenCalledWith('network_error', 'event'); } }); @@ -91,7 +90,7 @@ describe('XHRTransport', () => { try { await transport.sendEvent(transactionPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.QueueOverflow, 'transaction'); + expect(spy).toHaveBeenCalledWith('queue_overflow', 'transaction'); } }); @@ -416,13 +415,13 @@ describe('XHRTransport', () => { try { await transport.sendEvent(eventPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.RateLimitBackoff, 'event'); + expect(spy).toHaveBeenCalledWith('ratelimit_backoff', 'event'); } try { await transport.sendEvent(transactionPayload); } catch (_) { - expect(spy).toHaveBeenCalledWith(Outcome.RateLimitBackoff, 'transaction'); + expect(spy).toHaveBeenCalledWith('ratelimit_backoff', 'transaction'); } }); }); diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 8e08eaaf43f8..e9c4f1ca48bf 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -7,8 +7,6 @@ import { Integration, IntegrationClass, Options, - Outcome, - SessionStatus, SeverityLevel, Transport, } from '@sentry/types'; @@ -268,12 +266,12 @@ export abstract class BaseClient implement // A session is updated and that session update is sent in only one of the two following scenarios: // 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update // 2. Session with non terminal status and 1 error + a crash occurred -> Will set status crashed and send update - const sessionNonTerminal = session.status === SessionStatus.Ok; + const sessionNonTerminal = session.status === 'ok'; const shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed); if (shouldUpdateAndSend) { session.update({ - ...(crashed && { status: SessionStatus.Crashed }), + ...(crashed && { status: 'crashed' }), errors: session.errors || Number(errored || crashed), }); this.captureSession(session); @@ -541,7 +539,7 @@ export abstract class BaseClient implement // 0.0 === 0% events are sent // Sampling for transaction happens somewhere else if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) { - recordLostEvent(Outcome.SampleRate, 'event'); + recordLostEvent('sample_rate', 'event'); return SyncPromise.reject( new SentryError( `Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`, @@ -552,7 +550,7 @@ export abstract class BaseClient implement return this._prepareEvent(event, scope, hint) .then(prepared => { if (prepared === null) { - recordLostEvent(Outcome.EventProcessor, event.type || 'event'); + recordLostEvent('event_processor', event.type || 'event'); throw new SentryError('An event processor returned null, will not send event.'); } @@ -566,7 +564,7 @@ export abstract class BaseClient implement }) .then(processedEvent => { if (processedEvent === null) { - recordLostEvent(Outcome.BeforeSend, event.type || 'event'); + recordLostEvent('before_send', event.type || 'event'); throw new SentryError('`beforeSend` returned `null`, will not send event.'); } diff --git a/packages/core/test/lib/base.test.ts b/packages/core/test/lib/base.test.ts index 2b91d3f8cd03..cd8d7f992fb4 100644 --- a/packages/core/test/lib/base.test.ts +++ b/packages/core/test/lib/base.test.ts @@ -1,5 +1,5 @@ import { Hub, Scope, Session } from '@sentry/hub'; -import { Event, Outcome, Span, Transport } from '@sentry/types'; +import { Event, Span, Transport } from '@sentry/types'; import { logger, SentryError, SyncPromise } from '@sentry/utils'; import * as integrationModule from '../../src/integration'; @@ -882,7 +882,7 @@ describe('BaseClient', () => { client.captureEvent({ message: 'hello' }, {}); - expect(recordLostEventSpy).toHaveBeenCalledWith(Outcome.BeforeSend, 'event'); + expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'event'); }); test('eventProcessor can drop the even when it returns null', () => { @@ -914,7 +914,7 @@ describe('BaseClient', () => { scope.addEventProcessor(() => null); client.captureEvent({ message: 'hello' }, {}, scope); - expect(recordLostEventSpy).toHaveBeenCalledWith(Outcome.EventProcessor, 'event'); + expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'event'); }); test('eventProcessor sends an event and logs when it crashes', () => { @@ -958,7 +958,7 @@ describe('BaseClient', () => { ); client.captureEvent({ message: 'hello' }, {}); - expect(recordLostEventSpy).toHaveBeenCalledWith(Outcome.SampleRate, 'event'); + expect(recordLostEventSpy).toHaveBeenCalledWith('sample_rate', 'event'); }); }); diff --git a/packages/core/test/lib/request.test.ts b/packages/core/test/lib/request.test.ts index 6e27bb26a4af..bd9c3e424bac 100644 --- a/packages/core/test/lib/request.test.ts +++ b/packages/core/test/lib/request.test.ts @@ -1,4 +1,4 @@ -import { DebugMeta, Event, SentryRequest, TransactionSamplingMethod } from '@sentry/types'; +import { DebugMeta, Event, SentryRequest } from '@sentry/types'; import { initAPIDetails } from '../../src/api'; import { eventToSentryRequest, sessionToSentryRequest } from '../../src/request'; @@ -44,21 +44,21 @@ describe('eventToSentryRequest', () => { }); it('adds transaction sampling information to item header', () => { - event.debug_meta = { transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 } }; + event.debug_meta = { transactionSampling: { method: 'client_rate', rate: 0.1121 } }; const result = eventToSentryRequest(event, api); const envelope = parseEnvelopeRequest(result); expect(envelope.itemHeader).toEqual( expect.objectContaining({ - sample_rates: [{ id: TransactionSamplingMethod.Rate, rate: 0.1121 }], + sample_rates: [{ id: 'client_rate', rate: 0.1121 }], }), ); }); it('removes transaction sampling information (and only that) from debug_meta', () => { event.debug_meta = { - transactionSampling: { method: TransactionSamplingMethod.Sampler, rate: 0.1121 }, + transactionSampling: { method: 'client_sampler', rate: 0.1121 }, dog: 'Charlie', } as DebugMeta; @@ -71,7 +71,7 @@ describe('eventToSentryRequest', () => { it('removes debug_meta entirely if it ends up empty', () => { event.debug_meta = { - transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 }, + transactionSampling: { method: 'client_rate', rate: 0.1121 }, } as DebugMeta; const result = eventToSentryRequest(event, api); diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 7666e92a6fb1..c7fd4cac85e4 100644 --- a/packages/hub/src/hub.ts +++ b/packages/hub/src/hub.ts @@ -13,7 +13,6 @@ import { IntegrationClass, Primitive, SessionContext, - SessionStatus, SeverityLevel, Span, SpanContext, @@ -451,8 +450,8 @@ export class Hub implements HubInterface { if (scope) { // End existing session if there's one const currentSession = scope.getSession && scope.getSession(); - if (currentSession && currentSession.status === SessionStatus.Ok) { - currentSession.update({ status: SessionStatus.Exited }); + if (currentSession && currentSession.status === 'ok') { + currentSession.update({ status: 'exited' }); } this.endSession(); diff --git a/packages/hub/src/session.ts b/packages/hub/src/session.ts index 1bca2377cdd5..3206ef9306dc 100644 --- a/packages/hub/src/session.ts +++ b/packages/hub/src/session.ts @@ -13,7 +13,7 @@ export class Session implements SessionInterface { public timestamp: number; public started: number; public duration?: number = 0; - public status: SessionStatus = SessionStatus.Ok; + public status: SessionStatus = 'ok'; public environment?: string; public ipAddress?: string; public init: boolean = true; @@ -88,11 +88,11 @@ export class Session implements SessionInterface { } /** JSDoc */ - public close(status?: Exclude): void { + public close(status?: Exclude): void { if (status) { this.update({ status }); - } else if (this.status === SessionStatus.Ok) { - this.update({ status: SessionStatus.Exited }); + } else if (this.status === 'ok') { + this.update({ status: 'exited' }); } else { this.update(); } diff --git a/packages/hub/src/sessionflusher.ts b/packages/hub/src/sessionflusher.ts index bb898030efb4..82aa0af8c4c2 100644 --- a/packages/hub/src/sessionflusher.ts +++ b/packages/hub/src/sessionflusher.ts @@ -113,13 +113,13 @@ export class SessionFlusher implements SessionFlusherLike { } switch (status) { - case RequestSessionStatus.Errored: + case 'errored': aggregationCounts.errored = (aggregationCounts.errored || 0) + 1; return aggregationCounts.errored; - case RequestSessionStatus.Ok: + case 'ok': aggregationCounts.exited = (aggregationCounts.exited || 0) + 1; return aggregationCounts.exited; - case RequestSessionStatus.Crashed: + default: aggregationCounts.crashed = (aggregationCounts.crashed || 0) + 1; return aggregationCounts.crashed; } diff --git a/packages/hub/test/scope.test.ts b/packages/hub/test/scope.test.ts index 12dc965d2c03..9b1760dcd11c 100644 --- a/packages/hub/test/scope.test.ts +++ b/packages/hub/test/scope.test.ts @@ -1,4 +1,4 @@ -import { Event, EventHint, RequestSessionStatus } from '@sentry/types'; +import { Event, EventHint } from '@sentry/types'; import { getGlobalObject } from '@sentry/utils'; import { addGlobalEventProcessor, Scope } from '../src'; @@ -147,7 +147,7 @@ describe('Scope', () => { test('_requestSession clone', () => { const parentScope = new Scope(); - parentScope.setRequestSession({ status: RequestSessionStatus.Errored }); + parentScope.setRequestSession({ status: 'errored' }); const scope = Scope.clone(parentScope); expect(parentScope.getRequestSession()).toEqual(scope.getRequestSession()); }); @@ -174,16 +174,16 @@ describe('Scope', () => { // Test that ensures if the status value of `status` of `_requestSession` is changed in a child scope // that it should also change in parent scope because we are copying the reference to the object const parentScope = new Scope(); - parentScope.setRequestSession({ status: RequestSessionStatus.Errored }); + parentScope.setRequestSession({ status: 'errored' }); const scope = Scope.clone(parentScope); const requestSession = scope.getRequestSession(); if (requestSession) { - requestSession.status = RequestSessionStatus.Ok; + requestSession.status = 'ok'; } - expect(parentScope.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok }); - expect(scope.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok }); + expect(parentScope.getRequestSession()).toEqual({ status: 'ok' }); + expect(scope.getRequestSession()).toEqual({ status: 'ok' }); }); }); @@ -375,7 +375,7 @@ describe('Scope', () => { scope.setUser({ id: '1' }); scope.setFingerprint(['abcd']); scope.addBreadcrumb({ message: 'test' }); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); expect((scope as any)._extra).toEqual({ a: 2 }); scope.clear(); expect((scope as any)._extra).toEqual({}); @@ -402,7 +402,7 @@ describe('Scope', () => { scope.setUser({ id: '1337' }); scope.setLevel('info'); scope.setFingerprint(['foo']); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); }); test('given no data, returns the original scope', () => { @@ -450,7 +450,7 @@ describe('Scope', () => { localScope.setUser({ id: '42' }); localScope.setLevel('warning'); localScope.setFingerprint(['bar']); - (localScope as any)._requestSession = { status: RequestSessionStatus.Ok }; + (localScope as any)._requestSession = { status: 'ok' }; const updatedScope = scope.update(localScope) as any; @@ -472,7 +472,7 @@ describe('Scope', () => { expect(updatedScope._user).toEqual({ id: '42' }); expect(updatedScope._level).toEqual('warning'); expect(updatedScope._fingerprint).toEqual(['bar']); - expect(updatedScope._requestSession.status).toEqual(RequestSessionStatus.Ok); + expect(updatedScope._requestSession.status).toEqual('ok'); }); test('given an empty instance of Scope, it should preserve all the original scope data', () => { @@ -493,7 +493,7 @@ describe('Scope', () => { expect(updatedScope._user).toEqual({ id: '1337' }); expect(updatedScope._level).toEqual('info'); expect(updatedScope._fingerprint).toEqual(['foo']); - expect(updatedScope._requestSession.status).toEqual(RequestSessionStatus.Ok); + expect(updatedScope._requestSession.status).toEqual('ok'); }); test('given a plain object, it should merge two together, with the passed object having priority', () => { @@ -504,7 +504,7 @@ describe('Scope', () => { level: 'warning', tags: { bar: '3', baz: '4' }, user: { id: '42' }, - requestSession: { status: RequestSessionStatus.Errored }, + requestSession: { status: 'errored' }, }; const updatedScope = scope.update(localAttributes) as any; @@ -526,7 +526,7 @@ describe('Scope', () => { expect(updatedScope._user).toEqual({ id: '42' }); expect(updatedScope._level).toEqual('warning'); expect(updatedScope._fingerprint).toEqual(['bar']); - expect(updatedScope._requestSession).toEqual({ status: RequestSessionStatus.Errored }); + expect(updatedScope._requestSession).toEqual({ status: 'errored' }); }); }); diff --git a/packages/hub/test/session.test.ts b/packages/hub/test/session.test.ts index d334becd4821..f25e5ad4189b 100644 --- a/packages/hub/test/session.test.ts +++ b/packages/hub/test/session.test.ts @@ -1,4 +1,4 @@ -import { SessionContext, SessionStatus } from '@sentry/types'; +import { SessionContext } from '@sentry/types'; import { timestampInSeconds } from '@sentry/utils'; import { Session } from '../src/session'; @@ -16,7 +16,7 @@ describe('Session', () => { init: true, sid: expect.any(String), started: expect.stringMatching(currentYear), - status: SessionStatus.Ok, + status: 'ok', timestamp: expect.stringMatching(currentYear), }); @@ -74,7 +74,7 @@ describe('Session', () => { ], ['sets an userAgent', { userAgent: 'Mozilla/5.0' }, { attrs: { user_agent: 'Mozilla/5.0' } }], ['sets errors', { errors: 3 }, { errors: 3 }], - ['sets status', { status: SessionStatus.Crashed }, { status: SessionStatus.Crashed }], + ['sets status', { status: 'crashed' }, { status: 'crashed' }], ]; test.each(table)('%s', (...test) => { @@ -93,26 +93,26 @@ describe('Session', () => { describe('close', () => { it('exits a normal session', () => { const session = new Session(); - expect(session.status).toEqual(SessionStatus.Ok); + expect(session.status).toEqual('ok'); session.close(); - expect(session.status).toEqual(SessionStatus.Exited); + expect(session.status).toEqual('exited'); }); it('updates session status when give status', () => { const session = new Session(); - expect(session.status).toEqual(SessionStatus.Ok); + expect(session.status).toEqual('ok'); - session.close(SessionStatus.Abnormal); - expect(session.status).toEqual(SessionStatus.Abnormal); + session.close('abnormal'); + expect(session.status).toEqual('abnormal'); }); it('only changes status ok to exited', () => { const session = new Session(); - session.update({ status: SessionStatus.Crashed }); - expect(session.status).toEqual(SessionStatus.Crashed); + session.update({ status: 'crashed' }); + expect(session.status).toEqual('crashed'); session.close(); - expect(session.status).toEqual(SessionStatus.Crashed); + expect(session.status).toEqual('crashed'); }); }); }); diff --git a/packages/hub/test/sessionflusher.test.ts b/packages/hub/test/sessionflusher.test.ts index e126a374a415..3c7dc9782615 100644 --- a/packages/hub/test/sessionflusher.test.ts +++ b/packages/hub/test/sessionflusher.test.ts @@ -1,5 +1,3 @@ -import { RequestSessionStatus } from '@sentry/types'; - import { SessionFlusher } from '../src/sessionflusher'; describe('Session Flusher', () => { @@ -28,16 +26,16 @@ describe('Session Flusher', () => { const flusher = new SessionFlusher(transport, { release: '1.0.0', environment: 'dev' }); const date = new Date('2021-04-08T12:18:23.043Z'); - let count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); + let count = (flusher as any)._incrementSessionStatusCount('ok', date); expect(count).toEqual(1); - count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); + count = (flusher as any)._incrementSessionStatusCount('ok', date); expect(count).toEqual(2); - count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date); + count = (flusher as any)._incrementSessionStatusCount('errored', date); expect(count).toEqual(1); date.setMinutes(date.getMinutes() + 1); - count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); + count = (flusher as any)._incrementSessionStatusCount('ok', date); expect(count).toEqual(1); - count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date); + count = (flusher as any)._incrementSessionStatusCount('errored', date); expect(count).toEqual(1); expect(flusher.getSessionAggregates().aggregates).toEqual([ @@ -51,8 +49,8 @@ describe('Session Flusher', () => { const flusher = new SessionFlusher(transport, { release: '1.0.0' }); const date = new Date('2021-04-08T12:18:23.043Z'); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date); + (flusher as any)._incrementSessionStatusCount('ok', date); + (flusher as any)._incrementSessionStatusCount('errored', date); expect(flusher.getSessionAggregates()).toEqual({ aggregates: [{ errored: 1, exited: 1, started: '2021-04-08T12:18:00.000Z' }], @@ -77,8 +75,8 @@ describe('Session Flusher', () => { const flusher = new SessionFlusher(transport, { release: '1.0.0', environment: 'dev' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); const date = new Date('2021-04-08T12:18:23.043Z'); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); + (flusher as any)._incrementSessionStatusCount('ok', date); + (flusher as any)._incrementSessionStatusCount('ok', date); expect(sendSession).toHaveBeenCalledTimes(0); @@ -113,8 +111,8 @@ describe('Session Flusher', () => { const flusher = new SessionFlusher(transport, { release: '1.0.x' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); const date = new Date('2021-04-08T12:18:23.043Z'); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); - (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date); + (flusher as any)._incrementSessionStatusCount('ok', date); + (flusher as any)._incrementSessionStatusCount('ok', date); flusher.close(); expect(flusherFlushFunc).toHaveBeenCalledTimes(1); diff --git a/packages/node/src/client.ts b/packages/node/src/client.ts index 7f4842b48ad4..c5f19ed611d0 100644 --- a/packages/node/src/client.ts +++ b/packages/node/src/client.ts @@ -1,6 +1,6 @@ import { BaseClient, Scope, SDK_VERSION } from '@sentry/core'; import { SessionFlusher } from '@sentry/hub'; -import { Event, EventHint, RequestSessionStatus } from '@sentry/types'; +import { Event, EventHint } from '@sentry/types'; import { logger } from '@sentry/utils'; import { NodeBackend } from './backend'; @@ -48,8 +48,8 @@ export class NodeClient extends BaseClient { // Necessary checks to ensure this is code block is executed only within a request // Should override the status only if `requestSession.status` is `Ok`, which is its initial stage - if (requestSession && requestSession.status === RequestSessionStatus.Ok) { - requestSession.status = RequestSessionStatus.Errored; + if (requestSession && requestSession.status === 'ok') { + requestSession.status = 'errored'; } } @@ -74,8 +74,8 @@ export class NodeClient extends BaseClient { // Ensure that this is happening within the bounds of a request, and make sure not to override // Session Status if Errored / Crashed - if (requestSession && requestSession.status === RequestSessionStatus.Ok) { - requestSession.status = RequestSessionStatus.Errored; + if (requestSession && requestSession.status === 'ok') { + requestSession.status = 'errored'; } } } diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index c8156896acc8..332d8593010a 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core'; import { extractTraceparentData, Span } from '@sentry/tracing'; -import { Event, ExtractedNodeRequestData, RequestSessionStatus, Transaction } from '@sentry/types'; +import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types'; import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils'; import * as cookie from 'cookie'; import * as domain from 'domain'; @@ -424,7 +424,7 @@ export function requestHandler( const scope = currentHub.getScope(); if (scope) { // Set `status` of `RequestSession` to Ok, at the beginning of the request - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); } } }); @@ -517,8 +517,9 @@ export function errorHandler(options?: { // If an error bubbles to the `errorHandler`, then this is an unhandled error, and should be reported as a // Crashed session. The `_requestSession.status` is checked to ensure that this error is happening within // the bounds of a request, and if so the status is updated - if (requestSession && requestSession.status !== undefined) - requestSession.status = RequestSessionStatus.Crashed; + if (requestSession && requestSession.status !== undefined) { + requestSession.status = 'crashed'; + } } } diff --git a/packages/node/src/sdk.ts b/packages/node/src/sdk.ts index 7fbd6ba479be..52d137277fd8 100644 --- a/packages/node/src/sdk.ts +++ b/packages/node/src/sdk.ts @@ -232,7 +232,7 @@ function startSessionTracking(): void { // Ref: https://nodejs.org/api/process.html#process_event_beforeexit process.on('beforeExit', () => { const session = hub.getScope()?.getSession(); - const terminalStates = [SessionStatus.Exited, SessionStatus.Crashed]; + const terminalStates: SessionStatus[] = ['exited', 'crashed']; // Only call endSession, if the Session exists on Scope and SessionStatus is not a // Terminal Status i.e. Exited or Crashed because // "When a session is moved away from ok it must not be updated anymore." diff --git a/packages/node/test/client.test.ts b/packages/node/test/client.test.ts index 1ff6dc73d03e..f18f66c716af 100644 --- a/packages/node/test/client.test.ts +++ b/packages/node/test/client.test.ts @@ -1,5 +1,4 @@ import { Scope, SessionFlusher } from '@sentry/hub'; -import { RequestSessionStatus } from '@sentry/types'; import { NodeClient } from '../src'; @@ -17,12 +16,12 @@ describe('NodeClient', () => { test('when autoSessionTracking is enabled, and requestHandler is not used -> requestStatus should not be set', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' }); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception'), undefined, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); test('when autoSessionTracking is disabled -> requestStatus should not be set', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' }); @@ -31,12 +30,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception'), undefined, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); test('when autoSessionTracking is enabled + requestSession status is Crashed -> requestStatus should not be overridden', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' }); @@ -45,12 +44,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Crashed }); + scope.setRequestSession({ status: 'crashed' }); client.captureException(new Error('test exception'), undefined, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Crashed); + expect(requestSession!.status).toEqual('crashed'); }); test('when autoSessionTracking is enabled + error occurs within request bounds -> requestStatus should be set to Errored', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' }); @@ -59,12 +58,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception'), undefined, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Errored); + expect(requestSession!.status).toEqual('errored'); }); test('when autoSessionTracking is enabled + error occurs outside of request bounds -> requestStatus should not be set to Errored', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' }); @@ -89,7 +88,7 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureEvent( { message: 'message', exception: { values: [{ type: 'exception type 1' }] } }, undefined, @@ -97,7 +96,7 @@ describe('NodeClient', () => { ); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); test('When captureEvent is called with an exception, requestSession status should be set to Errored', () => { @@ -107,12 +106,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }, {}, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Errored); + expect(requestSession!.status).toEqual('errored'); }); test('When captureEvent is called without an exception, requestSession status should not be set to Errored', () => { @@ -122,12 +121,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message' }, {}, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); test('When captureEvent is called with an exception but outside of a request, then requestStatus should not be set', () => { @@ -154,18 +153,18 @@ describe('NodeClient', () => { client.initSessionFlusher(); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', type: 'transaction' }, undefined, scope); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); test('When captureEvent is called with an exception but requestHandler is not used, then requestSession status should not be set', () => { client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' }); const scope = new Scope(); - scope.setRequestSession({ status: RequestSessionStatus.Ok }); + scope.setRequestSession({ status: 'ok' }); client.captureEvent( { message: 'message', exception: { values: [{ type: 'exception type 1' }] } }, undefined, @@ -173,7 +172,7 @@ describe('NodeClient', () => { ); const requestSession = scope.getRequestSession(); - expect(requestSession!.status).toEqual(RequestSessionStatus.Ok); + expect(requestSession!.status).toEqual('ok'); }); }); }); diff --git a/packages/node/test/handlers.test.ts b/packages/node/test/handlers.test.ts index 9033ffc2ba81..daef81e4d44c 100644 --- a/packages/node/test/handlers.test.ts +++ b/packages/node/test/handlers.test.ts @@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core'; import { Hub } from '@sentry/hub'; import * as sentryHub from '@sentry/hub'; import { Transaction } from '@sentry/tracing'; -import { RequestSessionStatus, Runtime } from '@sentry/types'; +import { Runtime } from '@sentry/types'; import * as http from 'http'; import * as net from 'net'; @@ -229,7 +229,7 @@ describe('requestHandler', () => { sentryRequestMiddleware(req, res, next); const scope = sentryCore.getCurrentHub().getScope(); - expect(scope?.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok }); + expect(scope?.getRequestSession()).toEqual({ status: 'ok' }); }); it('autoSessionTracking is disabled, does not set requestSession, when handling a request', () => { @@ -258,7 +258,7 @@ describe('requestHandler', () => { res.emit('finish'); setImmediate(() => { - expect(scope?.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok }); + expect(scope?.getRequestSession()).toEqual({ status: 'ok' }); expect(captureRequestSession).toHaveBeenCalled(); done(); }); @@ -708,10 +708,10 @@ describe('errorHandler()', () => { jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub); - scope?.setRequestSession({ status: RequestSessionStatus.Ok }); + scope?.setRequestSession({ status: 'ok' }); sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next); const requestSession = scope?.getRequestSession(); - expect(requestSession).toEqual({ status: RequestSessionStatus.Ok }); + expect(requestSession).toEqual({ status: 'ok' }); }); it('autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash', () => { @@ -724,10 +724,10 @@ describe('errorHandler()', () => { jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub); - scope?.setRequestSession({ status: RequestSessionStatus.Ok }); + scope?.setRequestSession({ status: 'ok' }); sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next); const requestSession = scope?.getRequestSession(); - expect(requestSession).toEqual({ status: RequestSessionStatus.Ok }); + expect(requestSession).toEqual({ status: 'ok' }); }); it('when autoSessionTracking is enabled, should set requestSession status to Crashed when an unhandled error occurs within the bounds of a request', () => { @@ -742,10 +742,10 @@ describe('errorHandler()', () => { jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub); - scope?.setRequestSession({ status: RequestSessionStatus.Ok }); + scope?.setRequestSession({ status: 'ok' }); sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next); const requestSession = scope?.getRequestSession(); - expect(requestSession).toEqual({ status: RequestSessionStatus.Crashed }); + expect(requestSession).toEqual({ status: 'crashed' }); }); it('when autoSessionTracking is enabled, should not set requestSession status on Crash when it occurs outside the bounds of a request', () => { diff --git a/packages/node/test/transports/http.test.ts b/packages/node/test/transports/http.test.ts index a1d649da4576..d4d8e53d734c 100644 --- a/packages/node/test/transports/http.test.ts +++ b/packages/node/test/transports/http.test.ts @@ -1,5 +1,5 @@ import { Session } from '@sentry/hub'; -import { Event, SessionAggregates, SessionStatus, TransportOptions } from '@sentry/types'; +import { Event, SessionAggregates, TransportOptions } from '@sentry/types'; import { SentryError } from '@sentry/utils'; import * as http from 'http'; import * as HttpsProxyAgent from 'https-proxy-agent'; @@ -27,7 +27,7 @@ const sessionPayload: Session = { timestamp: Date.now(), init: true, duration: 0, - status: SessionStatus.Exited, + status: 'exited', update: jest.fn(), close: jest.fn(), toJSON: jest.fn(), diff --git a/packages/tracing/src/hubextensions.ts b/packages/tracing/src/hubextensions.ts index a70aa01e18a5..7bc654094ef7 100644 --- a/packages/tracing/src/hubextensions.ts +++ b/packages/tracing/src/hubextensions.ts @@ -6,7 +6,6 @@ import { Options, SamplingContext, TransactionContext, - TransactionSamplingMethod, } from '@sentry/types'; import { dynamicRequire, isNodeEnv, loadModule, logger } from '@sentry/utils'; @@ -51,7 +50,7 @@ function sample(transaction: T, options: Options, samplin // if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that if (transaction.sampled !== undefined) { transaction.setMetadata({ - transactionSampling: { method: TransactionSamplingMethod.Explicit }, + transactionSampling: { method: 'explicitly_set' }, }); return transaction; } @@ -63,7 +62,7 @@ function sample(transaction: T, options: Options, samplin sampleRate = options.tracesSampler(samplingContext); transaction.setMetadata({ transactionSampling: { - method: TransactionSamplingMethod.Sampler, + method: 'client_sampler', // cast to number in case it's a boolean rate: Number(sampleRate), }, @@ -71,13 +70,13 @@ function sample(transaction: T, options: Options, samplin } else if (samplingContext.parentSampled !== undefined) { sampleRate = samplingContext.parentSampled; transaction.setMetadata({ - transactionSampling: { method: TransactionSamplingMethod.Inheritance }, + transactionSampling: { method: 'inheritance' }, }); } else { sampleRate = options.tracesSampleRate; transaction.setMetadata({ transactionSampling: { - method: TransactionSamplingMethod.Rate, + method: 'client_rate', // cast to number in case it's a boolean rate: Number(sampleRate), }, diff --git a/packages/tracing/src/transaction.ts b/packages/tracing/src/transaction.ts index 45cb41357863..5143881ab159 100644 --- a/packages/tracing/src/transaction.ts +++ b/packages/tracing/src/transaction.ts @@ -2,7 +2,6 @@ import { getCurrentHub, Hub } from '@sentry/hub'; import { Event, Measurements, - Outcome, Transaction as TransactionInterface, TransactionContext, TransactionMetadata, @@ -107,7 +106,7 @@ export class Transaction extends SpanClass implements TransactionInterface { const client = this._hub.getClient(); const transport = client && client.getTransport && client.getTransport(); if (transport && transport.recordLostEvent) { - transport.recordLostEvent(Outcome.SampleRate, 'transaction'); + transport.recordLostEvent('sample_rate', 'transaction'); } return undefined; } diff --git a/packages/tracing/test/hub.test.ts b/packages/tracing/test/hub.test.ts index 576cf0a34ca4..3f39bb985ca6 100644 --- a/packages/tracing/test/hub.test.ts +++ b/packages/tracing/test/hub.test.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { BrowserClient } from '@sentry/browser'; import { Hub, makeMain } from '@sentry/hub'; -import { TransactionSamplingMethod } from '@sentry/types'; import * as utilsModule from '@sentry/utils'; // for mocking import { logger } from '@sentry/utils'; @@ -221,7 +220,7 @@ describe('Hub', () => { hub.startTransaction({ name: 'dogpark', sampled: true }); expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({ - transactionSampling: { method: TransactionSamplingMethod.Explicit }, + transactionSampling: { method: 'explicitly_set' }, }); }); @@ -232,7 +231,7 @@ describe('Hub', () => { hub.startTransaction({ name: 'dogpark' }); expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({ - transactionSampling: { method: TransactionSamplingMethod.Sampler, rate: 0.1121 }, + transactionSampling: { method: 'client_sampler', rate: 0.1121 }, }); }); @@ -242,7 +241,7 @@ describe('Hub', () => { hub.startTransaction({ name: 'dogpark', parentSampled: true }); expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({ - transactionSampling: { method: TransactionSamplingMethod.Inheritance }, + transactionSampling: { method: 'inheritance' }, }); }); @@ -252,7 +251,7 @@ describe('Hub', () => { hub.startTransaction({ name: 'dogpark' }); expect(Transaction.prototype.setMetadata).toHaveBeenCalledWith({ - transactionSampling: { method: TransactionSamplingMethod.Rate, rate: 0.1121 }, + transactionSampling: { method: 'client_rate', rate: 0.1121 }, }); }); }); diff --git a/packages/tracing/test/idletransaction.test.ts b/packages/tracing/test/idletransaction.test.ts index 07c545022ac1..b60fec726c54 100644 --- a/packages/tracing/test/idletransaction.test.ts +++ b/packages/tracing/test/idletransaction.test.ts @@ -1,6 +1,5 @@ import { BrowserClient, Transports } from '@sentry/browser'; import { Hub } from '@sentry/hub'; -import { Outcome } from '@sentry/types'; import { DEFAULT_IDLE_TIMEOUT, @@ -174,7 +173,7 @@ describe('IdleTransaction', () => { transaction.initSpanRecorder(10); transaction.finish(transaction.startTimestamp + 10); - expect(spy).toHaveBeenCalledWith(Outcome.SampleRate, 'transaction'); + expect(spy).toHaveBeenCalledWith('sample_rate', 'transaction'); }); describe('_initTimeout', () => { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index a323b8478ac1..fdc33cac2d1f 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -11,7 +11,6 @@ export { Exception } from './exception'; export { Extra, Extras } from './extra'; export { Hub } from './hub'; export { Integration, IntegrationClass } from './integration'; -export { LogLevel } from './loglevel'; export { Mechanism } from './mechanism'; export { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc'; export { Options } from './options'; diff --git a/packages/types/src/loglevel.ts b/packages/types/src/loglevel.ts deleted file mode 100644 index 7a75d69312dc..000000000000 --- a/packages/types/src/loglevel.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** Console logging verbosity for the SDK. */ -export enum LogLevel { - /** No logs will be generated. */ - None = 0, - /** Only SDK internal errors will be logged. */ - Error = 1, - /** Information useful for debugging the SDK will be logged. */ - Debug = 2, - /** All SDK actions will be logged. */ - Verbose = 3, -} diff --git a/packages/types/src/options.ts b/packages/types/src/options.ts index f746db3412b9..eefcd225a06b 100644 --- a/packages/types/src/options.ts +++ b/packages/types/src/options.ts @@ -1,7 +1,6 @@ import { Breadcrumb, BreadcrumbHint } from './breadcrumb'; import { Event, EventHint } from './event'; import { Integration } from './integration'; -import { LogLevel } from './loglevel'; import { CaptureContext } from './scope'; import { SdkMetadata } from './sdkmetadata'; import { SamplingContext } from './transaction'; @@ -82,9 +81,6 @@ export interface Options { */ maxBreadcrumbs?: number; - /** Console logging verbosity for the SDK Client. */ - logLevel?: LogLevel; - /** A global sample rate to apply to all events (0 - 1). */ sampleRate?: number; diff --git a/packages/types/src/requestsessionstatus.ts b/packages/types/src/requestsessionstatus.ts new file mode 100644 index 000000000000..b6b7ab9ee659 --- /dev/null +++ b/packages/types/src/requestsessionstatus.ts @@ -0,0 +1,11 @@ +/** JSDoc + * @deprecated Use string literals - if you require type casting, cast to RequestSessionStatus type + */ +export enum RequestSessionStatus { + /** JSDoc */ + Ok = 'ok', + /** JSDoc */ + Errored = 'errored', + /** JSDoc */ + Crashed = 'crashed', +} diff --git a/packages/types/src/session.ts b/packages/types/src/session.ts index 9b53772b4918..552dda002531 100644 --- a/packages/types/src/session.ts +++ b/packages/types/src/session.ts @@ -55,28 +55,8 @@ export interface SessionContext { ignoreDuration?: boolean; } -/** - * Session Status - */ -export enum SessionStatus { - /** JSDoc */ - Ok = 'ok', - /** JSDoc */ - Exited = 'exited', - /** JSDoc */ - Crashed = 'crashed', - /** JSDoc */ - Abnormal = 'abnormal', -} - -export enum RequestSessionStatus { - /** JSDoc */ - Ok = 'ok', - /** JSDoc */ - Errored = 'errored', - /** JSDoc */ - Crashed = 'crashed', -} +export type SessionStatus = 'ok' | 'exited' | 'crashed' | 'abnormal'; +export type RequestSessionStatus = 'ok' | 'errored' | 'crashed'; /** JSDoc */ export interface SessionAggregates { diff --git a/packages/types/src/sessionstatus.ts b/packages/types/src/sessionstatus.ts new file mode 100644 index 000000000000..339b4ea2f5e6 --- /dev/null +++ b/packages/types/src/sessionstatus.ts @@ -0,0 +1,13 @@ +/** JSDoc + * @deprecated Use string literals - if you require type casting, cast to SessionStatus type + */ +export enum SessionStatus { + /** JSDoc */ + Ok = 'ok', + /** JSDoc */ + Exited = 'exited', + /** JSDoc */ + Crashed = 'crashed', + /** JSDoc */ + Abnormal = 'abnormal', +} diff --git a/packages/types/src/transaction.ts b/packages/types/src/transaction.ts index 805d1350bff0..585eb66dd8dd 100644 --- a/packages/types/src/transaction.ts +++ b/packages/types/src/transaction.ts @@ -117,15 +117,10 @@ export interface SamplingContext extends CustomSamplingContext { export type Measurements = Record; -export enum TransactionSamplingMethod { - Explicit = 'explicitly_set', - Sampler = 'client_sampler', - Rate = 'client_rate', - Inheritance = 'inheritance', -} +export type TransactionSamplingMethod = 'explicitly_set' | 'client_sampler' | 'client_rate' | 'inheritance'; export interface TransactionMetadata { - transactionSampling?: { rate?: number; method?: string }; + transactionSampling?: { rate?: number; method?: TransactionSamplingMethod }; /** The two halves (sentry and third-party) of a transaction's tracestate header, used for dynamic sampling */ tracestate?: { diff --git a/packages/types/src/transport.ts b/packages/types/src/transport.ts index 40c26c146554..a1ba2983b1a3 100644 --- a/packages/types/src/transport.ts +++ b/packages/types/src/transport.ts @@ -5,14 +5,13 @@ import { Response } from './response'; import { SdkMetadata } from './sdkmetadata'; import { Session, SessionAggregates } from './session'; -export enum Outcome { - BeforeSend = 'before_send', - EventProcessor = 'event_processor', - NetworkError = 'network_error', - QueueOverflow = 'queue_overflow', - RateLimitBackoff = 'ratelimit_backoff', - SampleRate = 'sample_rate', -} +export type Outcome = + | 'before_send' + | 'event_processor' + | 'network_error' + | 'queue_overflow' + | 'ratelimit_backoff' + | 'sample_rate'; /** Transport used sending data to Sentry */ export interface Transport {