init()

in packages/rum/src/apm-base.js [60:136]


  init(config) {
    if (this.isEnabled() && !this._initialized) {
      this._initialized = true
      const [
        configService,
        loggingService,
        transactionService
      ] = this.serviceFactory.getService([
        CONFIG_SERVICE,
        LOGGING_SERVICE,
        TRANSACTION_SERVICE
      ])
      /**
       * Set Agent version to be sent as part of metadata to the APM Server
       */
      configService.setVersion('5.17.0')
      this.config(config)
      /**
       * Set level here to account for both active and inactive cases
       */
      const logLevel = configService.get('logLevel')
      loggingService.setLevel(logLevel)
      /**
       * Deactive agent when the active config flag is set to false
       */
      const isConfigActive = configService.get('active')
      if (isConfigActive) {
        this.serviceFactory.init()

        const flags = getInstrumentationFlags(
          configService.get('instrument'),
          configService.get('disableInstrumentations')
        )

        const performanceMonitoring = this.serviceFactory.getService(
          PERFORMANCE_MONITORING
        )
        performanceMonitoring.init(flags)

        if (flags[ERROR]) {
          const errorLogging = this.serviceFactory.getService(ERROR_LOGGING)
          errorLogging.registerListeners()
        }

        if (configService.get('session')) {
          let localConfig = configService.getLocalConfig()
          if (localConfig && localConfig.session) {
            configService.setConfig({
              session: localConfig.session
            })
          }
        }

        const sendPageLoad = () =>
          flags[PAGE_LOAD] && this._sendPageLoadMetrics()

        if (configService.get('centralConfig')) {
          /**
           * Waiting for the remote config before sending the page load transaction
           */
          this.fetchCentralConfig().then(sendPageLoad)
        } else {
          sendPageLoad()
        }

        observePageVisibility(configService, transactionService)
        if (flags[EVENT_TARGET] && flags[CLICK]) {
          observePageClicks(transactionService)
        }
        observeUserInteractions()
      } else {
        this._disable = true
        loggingService.warn('RUM agent is inactive')
      }
    }
    return this
  }