LCOV - code coverage report
Current view: top level - packages/shared-frontend-utils/src - telemetry.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 37.5 % 8 3
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : /** The backend family a RUM session reports under, as Datadog and backend engineers name it. */
       2              : export type DeployEnv = 'prod-v2' | 'stg-v2' | 'test-v2'
       3              : 
       4              : /** One RUM application for every Comfy web surface; each sets its own `service`. */
       5              : export const COMFY_RUM_APPLICATION = {
       6              :   clientToken: 'pub7704486e5b64eb4ff6f62891cda45559',
       7              :   applicationId: '041a9897-5516-4b1f-a245-1a9aa6895488',
       8              :   site: 'us5.datadoghq.com'
       9              : } as const
      10              : 
      11              : export const DEFAULT_POSTHOG_API_HOST = 'https://t.comfy.org'
      12              : 
      13              : /** PostHog settings every Comfy web surface shares; each adds its own token, host and before_send. */
      14              : export const COMFY_POSTHOG_OPTIONS = {
      15              :   ui_host: 'https://us.posthog.com',
      16              :   autocapture: false,
      17              :   capture_pageview: 'history_change',
      18              :   capture_pageleave: false,
      19              :   persistence: 'localStorage+cookie',
      20              :   person_profiles: 'identified_only'
      21              : } as const
      22              : 
      23              : /**
      24              :  * Marks the console line a reporter writes for every report. RUM collects
      25              :  * `console.error` on its own, so `isRumErrorNoise` matches on this to drop the
      26              :  * untagged console copy of a failure RUM already received tagged.
      27              :  */
      28         2356 : export const REPORTED_ERROR_PREFIX = '[Reported error]: '
      29              : 
      30         2356 : const EXTENSION_ERROR_MESSAGES = [
      31              :   'Invalid call to runtime.sendMessage(). Tab not found.',
      32              :   '[messaging] In this JS context, only one listener can be setup for'
      33              : ]
      34              : 
      35         2356 : const ERROR_MESSAGE_PREFIX =
      36              :   /^(?:Unhandled promise rejection:\s*)?(?:Error:\s*)?$/
      37              : 
      38              : const RUM_NOISE_HOSTS = [
      39              :   'facebook.com',
      40              :   'px.ads.linkedin.com',
      41              :   'browser-intake-us5-datadoghq.com',
      42              :   'e2.sy-d.io',
      43              :   'google-analytics.com',
      44              :   'googletagmanager.com'
      45              : ]
      46              : 
      47            0 : export function isThirdPartyErrorNoise(message?: string): boolean {
      48            0 :   if (!message) return false
      49            0 :   return EXTENSION_ERROR_MESSAGES.some((known) => {
      50            0 :     const index = message.indexOf(known)
      51            0 :     return index >= 0 && ERROR_MESSAGE_PREFIX.test(message.slice(0, index))
      52              :   })
      53              : }
      54              : 
      55              : /** An error no Comfy page raised or can act on. */
      56              : export function isRumErrorNoise(error: {
      57              :   readonly message: string
      58              :   readonly source?: string
      59              : }): boolean {
      60              :   const { message } = error
      61              :   if (error.source === 'console' && message.startsWith(REPORTED_ERROR_PREFIX))
      62              :     return true
      63              :   if (isThirdPartyErrorNoise(message)) return true
      64              :   if (message.startsWith('intervention:')) return true
      65              :   if (message.includes('ResizeObserver loop')) return true
      66              : 
      67              :   const isNetworkNoise =
      68              :     message.includes('csp_violation') || message.includes('Failed to fetch')
      69              :   return (
      70              :     isNetworkNoise && RUM_NOISE_HOSTS.some((host) => message.includes(host))
      71              :   )
      72              : }
      73              : 
      74              : /** Origin and path only: a query or fragment can carry a client secret or an email. */
      75              : export function stripUrlQuery(url: string): string {
      76              :   return url.replace(/[?#].*$/s, '')
      77              : }
      78              : 
      79              : const URL_PATTERN = /\bhttps?:\/\/[^\s"'<>()]*/g
      80              : 
      81              : const SENSITIVE_TEXT_PATTERNS: readonly (readonly [RegExp, string])[] = [
      82              :   [/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g, '[token]'],
      83              :   [/\b(Bearer\s+)[\w.~+/-]+=*/gi, '$1[token]'],
      84              :   [/\b\w+_secret_\w+/g, '[token]'],
      85              :   // Anchored on the character before the address, so a long run of
      86              :   // address characters is scanned once instead of from every offset.
      87              :   [
      88              :     /(^|[^\w.%+-])[\w.%+-]+(?:@|%40)[\w-]+(?:\.[\w-]+)*\.[a-z]{2,}/gi,
      89              :     '$1[email]'
      90              :   ]
      91              : ]
      92              : 
      93              : /** Free text with every URL query, token, client secret and email taken out. */
      94              : export function redactSensitiveText(text: string): string {
      95              :   return SENSITIVE_TEXT_PATTERNS.reduce(
      96              :     (redacted, [pattern, replacement]) =>
      97              :       redacted.replace(pattern, replacement),
      98              :     text.replace(URL_PATTERN, stripUrlQuery)
      99              :   )
     100              : }
        

Generated by: LCOV version 2.0-1