{"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;EAC3B,MAAM,KAAK;EAEX,KAAK,cAAcC,wBAAAA,IAAI,cAAc;EACrC,KAAK,QAAQ,EACX,UAAU,MACZ;CACF;CAEA,OAAc,2BAA2B;EACvC,OAAO,EAAE,UAAU,KAAK;CAC1B;CAEA,kBAAkC,OAAc,WAA4B;EAC1E,KAAK,YAAY,aAAa,OAAO;GACnC,SAAS;GACT,YAAY;IACV,yBAAyB,UAAU,kBAAkB,KAAA;KACpDC,6BAAAA,0BAAAA;GAEH;EACF,CAAC;CACH;CAEA,SAAyB;EACvB,IAAI,KAAK,MAAM,UACb,OAAO,KAAK,MAAM,SAAS;EAG7B,OAAO,KAAK,MAAM;CACpB;AACF"}