11import { Event , EventHint , Options , Session , Severity , Transport } from '@sentry/types' ;
22import { isDebugBuild , logger , SentryError } from '@sentry/utils' ;
33
4+ import { initAPIDetails } from './api' ;
5+ import { createEventEnvelope , createSessionEnvelope } from './request' ;
6+ import { NewTransport } from './transports/base' ;
47import { NoopTransport } from './transports/noop' ;
58
69/**
@@ -63,6 +66,9 @@ export abstract class BaseBackend<O extends Options> implements Backend {
6366 /** Cached transport used internally. */
6467 protected _transport : Transport ;
6568
69+ /** New v7 Transport that is initialized alongside the old one */
70+ protected _newTransport ?: NewTransport ;
71+
6672 /** Creates a new backend instance. */
6773 public constructor ( options : O ) {
6874 this . _options = options ;
@@ -91,9 +97,23 @@ export abstract class BaseBackend<O extends Options> implements Backend {
9197 * @inheritDoc
9298 */
9399 public sendEvent ( event : Event ) : void {
94- void this . _transport . sendEvent ( event ) . then ( null , reason => {
95- isDebugBuild ( ) && logger . error ( 'Error while sending event:' , reason ) ;
96- } ) ;
100+ // TODO(v7): Remove the if-else
101+ if (
102+ this . _newTransport &&
103+ this . _options . dsn &&
104+ this . _options . _experiments &&
105+ this . _options . _experiments . newTransport
106+ ) {
107+ const api = initAPIDetails ( this . _options . dsn , this . _options . _metadata , this . _options . tunnel ) ;
108+ const env = createEventEnvelope ( event , api ) ;
109+ void this . _newTransport . send ( env ) . then ( null , reason => {
110+ isDebugBuild ( ) && logger . error ( 'Error while sending event:' , reason ) ;
111+ } ) ;
112+ } else {
113+ void this . _transport . sendEvent ( event ) . then ( null , reason => {
114+ isDebugBuild ( ) && logger . error ( 'Error while sending event:' , reason ) ;
115+ } ) ;
116+ }
97117 }
98118
99119 /**
@@ -105,9 +125,23 @@ export abstract class BaseBackend<O extends Options> implements Backend {
105125 return ;
106126 }
107127
108- void this . _transport . sendSession ( session ) . then ( null , reason => {
109- isDebugBuild ( ) && logger . error ( 'Error while sending session:' , reason ) ;
110- } ) ;
128+ // TODO(v7): Remove the if-else
129+ if (
130+ this . _newTransport &&
131+ this . _options . dsn &&
132+ this . _options . _experiments &&
133+ this . _options . _experiments . newTransport
134+ ) {
135+ const api = initAPIDetails ( this . _options . dsn , this . _options . _metadata , this . _options . tunnel ) ;
136+ const [ env ] = createSessionEnvelope ( session , api ) ;
137+ void this . _newTransport . send ( env ) . then ( null , reason => {
138+ isDebugBuild ( ) && logger . error ( 'Error while sending session:' , reason ) ;
139+ } ) ;
140+ } else {
141+ void this . _transport . sendSession ( session ) . then ( null , reason => {
142+ isDebugBuild ( ) && logger . error ( 'Error while sending session:' , reason ) ;
143+ } ) ;
144+ }
111145 }
112146
113147 /**
@@ -123,4 +157,6 @@ export abstract class BaseBackend<O extends Options> implements Backend {
123157 protected _setupTransport ( ) : Transport {
124158 return new NoopTransport ( ) ;
125159 }
160+
161+ protected abstract _setupNewTransport ( ) : NewTransport ;
126162}
0 commit comments