Skip to content

Commit

Permalink
👷 Remove sanitize feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickadam committed Apr 19, 2023
1 parent af0787a commit c677d1b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 58 deletions.
8 changes: 2 additions & 6 deletions packages/core/src/domain/console/consoleObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack:

function formatConsoleParameters(param: unknown) {
if (typeof param === 'string') {
return isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(param) : param
return sanitize(param)
}
if (param instanceof Error) {
return formatErrorMessage(computeStackTrace(param))
}
return jsonStringify(
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(param) : param,
undefined,
2
)
return jsonStringify(sanitize(param), undefined, 2)
}
5 changes: 1 addition & 4 deletions packages/core/src/domain/error/error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { StackTrace } from '../tracekit'
import { computeStackTrace } from '../tracekit'
import { ExperimentalFeature, isExperimentalFeatureEnabled } from '../../tools/experimentalFeatures'
import { callMonitored } from '../../tools/monitor'
import { sanitize } from '../../tools/serialisation/sanitize'
import type { ClocksState } from '../../tools/utils/timeUtils'
Expand Down Expand Up @@ -71,9 +70,7 @@ export function computeRawError({
handling,
}: RawErrorParams): RawError {
if (!stackTrace || (stackTrace.message === undefined && !(originalError instanceof Error))) {
const sanitizedError = isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(originalError)
: originalError
const sanitizedError = sanitize(originalError)
return {
startClocks,
source,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum ExperimentalFeature {
RESOURCE_PAGE_STATES = 'resource_page_states',
CLICKMAP = 'clickmap',
COLLECT_FLUSH_REASON = 'collect_flush_reason',
SANITIZE_INPUTS = 'sanitize_inputs',
REPLAY_JSON_PAYLOAD = 'replay_json_payload',
}

Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/tools/serialisation/contextManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ExperimentalFeature, isExperimentalFeatureEnabled } from '../experimentalFeatures'
import { computeBytesCount } from '../utils/byteUtils'
import { throttle } from '../utils/functionUtils'
import { deepClone } from '../mergeInto'
Expand Down Expand Up @@ -52,16 +51,12 @@ export function createContextManager(customerDataType: CustomerDataType, compute
getContext: () => deepClone(context),

setContext: (newContext: Context) => {
context = isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(newContext)
: deepClone(newContext)
context = sanitize(newContext)
computeBytesCountThrottled(context)
},

setContextProperty: (key: string, property: any) => {
context[key] = isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(property)
: deepClone(property)
context[key] = sanitize(property)
computeBytesCountThrottled(context)
},

Expand Down
8 changes: 2 additions & 6 deletions packages/logs/src/boot/logsPublicApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Context, InitConfiguration, User } from '@datadog/browser-core'
import {
ExperimentalFeature,
isExperimentalFeatureEnabled,
CustomerDataType,
assign,
BoundedBuffer,
Expand Down Expand Up @@ -122,12 +120,10 @@ export function makeLogsPublicApi(startLogsImpl: StartLogs) {
createLogger: monitor((name: string, conf: LoggerConfiguration = {}) => {
customLoggers[name] = new Logger(
(...params) => handleLogStrategy(...params),
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(name) : name,
sanitize(name),
conf.handler,
conf.level,
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? (sanitize(conf.context) as object)
: conf.context
sanitize(conf.context) as object
)

return customLoggers[name]!
Expand Down
11 changes: 2 additions & 9 deletions packages/logs/src/domain/logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { Context } from '@datadog/browser-core'
import {
ExperimentalFeature,
isExperimentalFeatureEnabled,
clocksNow,
computeRawError,
ErrorHandling,
PROVIDED_ERROR_MESSAGE_PREFIX,
computeStackTrace,
CustomerDataType,
deepClone,
assign,
combine,
createContextManager,
Expand Down Expand Up @@ -84,19 +81,15 @@ export class Logger {
}
}

const sanitizedMessageContext = (
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(messageContext)
: deepClone(messageContext)
) as Context
const sanitizedMessageContext = sanitize(messageContext) as Context

const context = errorContext
? (combine({ error: errorContext }, sanitizedMessageContext) as Context)
: sanitizedMessageContext

this.handleLogStrategy(
{
message: isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(message)! : message,
message: sanitize(message)!,
context,
status,
},
Expand Down
22 changes: 5 additions & 17 deletions packages/rum-core/src/boot/rumPublicApi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Context, InitConfiguration, TimeStamp, RelativeTime, User } from '@datadog/browser-core'
import {
ExperimentalFeature,
noop,
isExperimentalFeatureEnabled,
CustomerDataType,
willSyntheticsInjectRum,
assign,
Expand Down Expand Up @@ -213,10 +211,8 @@ export function makeRumPublicApi(

addAction: monitor((name: string, context?: object) => {
addActionStrategy({
name: isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(name)! : name,
context: (isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(context)
: deepClone(context)) as Context,
name: sanitize(name)!,
context: sanitize(context) as Context,
startClocks: clocksNow(),
type: ActionType.CUSTOM,
})
Expand All @@ -228,19 +224,14 @@ export function makeRumPublicApi(
addErrorStrategy({
error, // Do not sanitize error here, it is needed unserialized by computeRawError()
handlingStack,
context: (isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS)
? sanitize(context)
: deepClone(context)) as Context,
context: sanitize(context) as Context,
startClocks: clocksNow(),
})
})
},

addTiming: monitor((name: string, time?: number) => {
addTimingStrategy(
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(name)! : name,
time as RelativeTime | TimeStamp | undefined
)
addTimingStrategy(sanitize(name)!, time as RelativeTime | TimeStamp | undefined)
}),

setUser: monitor((newUser: User) => {
Expand Down Expand Up @@ -275,10 +266,7 @@ export function makeRumPublicApi(
* This feature is currently in beta. For more information see the full [feature flag tracking guide](https://docs.datadoghq.com/real_user_monitoring/feature_flag_tracking/).
*/
addFeatureFlagEvaluation: monitor((key: string, value: any) => {
addFeatureFlagEvaluationStrategy(
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(key)! : key,
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(value) : value
)
addFeatureFlagEvaluationStrategy(sanitize(key)!, sanitize(value))
}),
getSessionReplayLink: monitor(() => getSessionReplayLinkStrategy()),
})
Expand Down
2 changes: 0 additions & 2 deletions packages/rum-core/src/domain/limitModification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ describe('limitModification', () => {
})

it('should call sanitize on newly provided values', () => {
addExperimentalFeatures([ExperimentalFeature.SANITIZE_INPUTS])
const object: Context = { bar: { baz: 42 } }

const modifier = (candidate: any) => {
Expand All @@ -167,6 +166,5 @@ describe('limitModification', () => {

limitModification(object, ['bar'], modifier)
expect(() => JSON.stringify(object)).not.toThrowError()
resetExperimentalFeatures()
})
})
8 changes: 2 additions & 6 deletions packages/rum-core/src/domain/limitModification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExperimentalFeature, isExperimentalFeatureEnabled, sanitize, deepClone, getType } from '@datadog/browser-core'
import { sanitize, deepClone, getType } from '@datadog/browser-core'
import type { Context } from '@datadog/browser-core'

/**
Expand All @@ -18,11 +18,7 @@ export function limitModification<T extends Context, Result>(
const originalType = getType(originalValue)
const newType = getType(newValue)
if (newType === originalType) {
set(
object,
path,
isExperimentalFeatureEnabled(ExperimentalFeature.SANITIZE_INPUTS) ? sanitize(newValue) : newValue
)
set(object, path, sanitize(newValue))
} else if (originalType === 'object' && (newType === 'undefined' || newType === 'null')) {
set(object, path, {})
}
Expand Down

0 comments on commit c677d1b

Please sign in to comment.