{"version":3,"file":"EmbraceErrorBoundary.cjs","names":["React","log","KEY_EMB_INSTRUMENTATION"],"sources":["../../../../../src/instrumentations/exceptions/react/EmbraceErrorBoundary/EmbraceErrorBoundary.ts"],"sourcesContent":["import type { PropsWithChildren } from 'react';\nimport * as React from 'react';\nimport type { LogManager } from '../../../../api-logs/index.ts';\nimport { log } from '../../../../api-logs/index.ts';\nimport {\n  EMB_ERROR_INSTRUMENTATIONS,\n  KEY_EMB_INSTRUMENTATION,\n} from '../../../../constants/index.ts';\n\ntype EmbraceErrorBoundaryProps = {\n  fallback: () => React.ReactNode;\n};\n\ntype EmbraceErrorBoundaryState = {\n  hasError: boolean;\n};\n\nexport class EmbraceErrorBoundary<\n  P extends PropsWithChildren<EmbraceErrorBoundaryProps>,\n> extends React.Component<P, EmbraceErrorBoundaryState> {\n  private readonly _logManager: LogManager;\n\n  public constructor(props: P) {\n    super(props);\n\n    this._logManager = log.getLogManager();\n    this.state = {\n      hasError: false,\n    };\n  }\n\n  public static getDerivedStateFromError() {\n    return { hasError: true };\n  }\n\n  public override componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {\n    this._logManager.logException(error, {\n      handled: false,\n      attributes: {\n        'react.component_stack': errorInfo.componentStack ?? undefined,\n        [KEY_EMB_INSTRUMENTATION]:\n          EMB_ERROR_INSTRUMENTATIONS.ReactErrorBoundary,\n      },\n    });\n  }\n\n  public override render() {\n    if (this.state.hasError) {\n      return this.props.fallback();\n    }\n\n    return this.props.children;\n  }\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,uBAAb,cAEUA,MAAM,UAAwC;CACtD;CAEA,YAAmB,OAAU;AAC3B,QAAM,MAAM;AAEZ,OAAK,cAAcC,wBAAAA,IAAI,eAAe;AACtC,OAAK,QAAQ,EACX,UAAU,OACX;;CAGH,OAAc,2BAA2B;AACvC,SAAO,EAAE,UAAU,MAAM;;CAG3B,kBAAkC,OAAc,WAA4B;AAC1E,OAAK,YAAY,aAAa,OAAO;GACnC,SAAS;GACT,YAAY;IACV,yBAAyB,UAAU,kBAAkB,KAAA;KACpDC,6BAAAA,0BAAAA;IAEF;GACF,CAAC;;CAGJ,SAAyB;AACvB,MAAI,KAAK,MAAM,SACb,QAAO,KAAK,MAAM,UAAU;AAG9B,SAAO,KAAK,MAAM"}