-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
… a different RUM and LOGS valid browsing context / do not pass a sessionId when the cookies are off
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ export function makeGlobal<T>(stub: T): T { | |
export type Datacenter = 'eu' | 'us' | ||
export type Environment = 'production' | 'staging' | 'e2e-test' | ||
|
||
export enum BrowsingContext { | ||
RUM = 'rum', | ||
LOGS = 'logs' | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
export interface BuildEnv { | ||
datacenter: Datacenter | ||
env: Environment | ||
|
@@ -42,16 +47,25 @@ export function commonInit(userConfiguration: UserConfiguration, buildEnv: Build | |
} | ||
} | ||
|
||
export function isValidBrowsingContext() { | ||
if (!areCookiesAuthorized()) { | ||
console.error('Cookies are not authorized, we will not send any data.') | ||
return false | ||
} | ||
if (isLocalFile()) { | ||
console.error('Execution is not allowed in the current context.') | ||
return false | ||
export function isValidBrowsingContext(browsingContext: BrowsingContext) { | ||
switch (browsingContext) { | ||
case BrowsingContext.RUM: | ||
if (!areCookiesAuthorized()) { | ||
console.error('Cookies are not authorized, RUM will not send any data.') | ||
return false | ||
} | ||
if (isLocalFile()) { | ||
console.error('Execution is not allowed in the current context.') | ||
return false | ||
} | ||
return true | ||
case BrowsingContext.LOGS: | ||
if (isLocalFile()) { | ||
console.error('Execution is not allowed in the current context.') | ||
return false | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
mquentin
Author
Member
|
||
return true | ||
} | ||
return true | ||
} | ||
|
||
function isLocalFile() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import lodashMerge from 'lodash.merge' | |
|
||
import { LoggerSession } from './loggerSession' | ||
import { LogsGlobal } from './logs.entry' | ||
import { areCookiesAuthorized } from '../../core/src/cookie' | ||
This comment has been minimized.
Sorry, something went wrong.
mquentin
Author
Member
|
||
|
||
export enum StatusType { | ||
debug = 'debug', | ||
|
@@ -34,6 +35,7 @@ export const STATUSES = Object.keys(StatusType) | |
export interface LogsMessage { | ||
message: string | ||
status: StatusType | ||
|
||
[key: string]: ContextValue | ||
} | ||
|
||
|
@@ -63,15 +65,15 @@ export function startLogger(errorObservable: ErrorObservable, configuration: Con | |
lodashMerge( | ||
{ | ||
date: new Date().getTime(), | ||
session_id: session.getId(), | ||
view: { | ||
referrer: document.referrer, | ||
url: window.location.href, | ||
}, | ||
}, | ||
(areCookiesAuthorized()) ? { session_id: session.getId() } : {}, | ||
This comment has been minimized.
Sorry, something went wrong.
mquentin
Author
Member
|
||
globalContext, | ||
getRUMInternalContext() | ||
) as Context | ||
getRUMInternalContext(), | ||
) as Context, | ||
) | ||
const handlers = { | ||
[HandlerType.console]: (message: LogsMessage) => console.log(`${message.status}: ${message.message}`), | ||
|
@@ -119,7 +121,7 @@ export class Logger { | |
private handlers: { [key in HandlerType]: (message: LogsMessage) => void }, | ||
handler = HandlerType.http, | ||
private level = StatusType.debug, | ||
private loggerContext: Context = {} | ||
private loggerContext: Context = {}, | ||
) { | ||
this.handler = this.handlers[handler] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,26 @@ export function startLoggerSession(configuration: Configuration): LoggerSession | |
|
||
return { | ||
getId: session.getId, | ||
isTracked: () => session.getType() === LoggerSessionType.TRACKED, | ||
isTracked: () => (session.getType()) ? session.getType() === LoggerSessionType.TRACKED : computeSessionType(configuration) === LoggerSessionType.TRACKED, | ||
This comment has been minimized.
Sorry, something went wrong.
mquentin
Author
Member
|
||
} | ||
} | ||
|
||
function computeSessionType(configuration: Configuration): string { | ||
let sessionType | ||
if (!performDraw(configuration.sampleRate)) { | ||
sessionType = LoggerSessionType.NOT_TRACKED | ||
} else { | ||
sessionType = LoggerSessionType.TRACKED | ||
} | ||
return sessionType | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
mquentin
Author
Member
|
||
function computeSessionState(configuration: Configuration, rawSessionType?: string) { | ||
let sessionType | ||
if (hasValidLoggerSession(rawSessionType)) { | ||
sessionType = rawSessionType | ||
} else if (!performDraw(configuration.sampleRate)) { | ||
sessionType = LoggerSessionType.NOT_TRACKED | ||
} else { | ||
sessionType = LoggerSessionType.TRACKED | ||
sessionType = computeSessionType(configuration) | ||
} | ||
return { | ||
isTracked: sessionType === LoggerSessionType.TRACKED, | ||
|
Add a new concept of BrowsingContext for each sdk package that will define the validity of the context independently of each other.