Skip to content

Commit

Permalink
feat: Deprecate sanitize_properties
Browse files Browse the repository at this point in the history
We can achieve the exact same outcome we achieve with `sanitize_properties` by using `before_send` which is a much more compreheensive function, with better usability and ergonomics.

We can't remove this function without a major, so let's deprecate it and issue a console warning when it's used.
  • Loading branch information
rafaeelaudibert committed Dec 27, 2024
1 parent b2954a5 commit 8d54002
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ export class PostHog {
this.compression = includes(config['supportedCompression'], Compression.GZipJS)
? Compression.GZipJS
: includes(config['supportedCompression'], Compression.Base64)
? Compression.Base64
: undefined
? Compression.Base64
: undefined
}

if (config.analytics?.endpoint) {
Expand All @@ -586,8 +586,8 @@ export class PostHog {
person_profiles: this._initialPersonProfilesConfig
? this._initialPersonProfilesConfig
: config['defaultIdentifiedOnly']
? 'identified_only'
: 'always',
? 'identified_only'
: 'always',
})

this.siteApps?.onRemoteConfig(config)
Expand Down Expand Up @@ -1036,6 +1036,7 @@ export class PostHog {

const sanitize_properties = this.config.sanitize_properties
if (sanitize_properties) {
logger.error('sanitize_properties is deprecated. Use before_send instead')
properties = sanitize_properties(properties, event_name)
}

Expand All @@ -1058,6 +1059,7 @@ export class PostHog {
let setOnceProperties = extend({}, this.persistence.get_initial_props(), dataSetOnce || {})
const sanitize_properties = this.config.sanitize_properties
if (sanitize_properties) {
logger.error('sanitize_properties is deprecated. Use before_send instead')
setOnceProperties = sanitize_properties(setOnceProperties, '$set_once')
}
if (isEmptyObject(setOnceProperties)) {
Expand Down
20 changes: 11 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const knownUnsafeEditableEvent = [
*
* Some features of PostHog rely on receiving 100% of these events
*/
export type KnownUnsafeEditableEvent = (typeof knownUnsafeEditableEvent)[number]
export type KnownUnsafeEditableEvent = typeof knownUnsafeEditableEvent[number]

/**
* These are known events PostHog events that can be processed by the `beforeCapture` function
Expand Down Expand Up @@ -278,7 +278,6 @@ export interface PostHogConfig {
inapp_protocol: string
inapp_link_new_window: boolean
request_batching: boolean
sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null
properties_string_max_length: number
session_recording: SessionRecordingOptions
session_idle_timeout_seconds: number
Expand All @@ -291,6 +290,13 @@ export interface PostHogConfig {
feature_flag_request_timeout_ms: number
get_device_id: (uuid: string) => string
name: string

/**
* This function is called when collecting properties for an event.
* It allows you to edit data before it is sent
* @deprecated - use `before_send` instead
*/
sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null
/**
* this is a read-only function that can be used to react to event capture
* @deprecated - use `before_send` instead - NB before_send is not read only
Expand Down Expand Up @@ -527,11 +533,7 @@ export interface RemoteConfig {
}
elementsChainAsString?: boolean
// this is currently in development and may have breaking changes without a major version bump
autocaptureExceptions?:
| boolean
| {
endpoint?: string
}
autocaptureExceptions?: boolean | { endpoint?: string }
sessionRecording?: SessionRecordingCanvasOptions & {
endpoint?: string
consoleLogRecordingEnabled?: boolean
Expand Down Expand Up @@ -759,7 +761,7 @@ export type ErrorEventArgs = [
source?: string | undefined,
lineno?: number | undefined,
colno?: number | undefined,
error?: Error | undefined,
error?: Error | undefined
]

export type ErrorMetadata = {
Expand All @@ -776,7 +778,7 @@ export type ErrorMetadata = {
// and to avoid relying on a frequently changing @sentry/types dependency
// but provided as an array of literal types, so we can constrain the level below
export const severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const
export declare type SeverityLevel = (typeof severityLevels)[number]
export declare type SeverityLevel = typeof severityLevels[number]

export interface ErrorProperties {
$exception_type: string
Expand Down

0 comments on commit 8d54002

Please sign in to comment.