question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to apply a custom report sender after switching to use 5.8.1

See original GitHub issue

Hello. Could anybody share info on how to apply a custom report sender after switching to use 5.8.1? I had the following

implementation 'ch.acra:acra-http:5.7.0'

class CustomReportSenderFactory : ReportSenderFactory {
  override fun create(context: Context, config: CoreConfiguration): ReportSender {
    return CustomReportSender(config)
  }
}
class CustomReportSender(config: CoreConfiguration) : HttpSender(config, null, null) {
  override fun send(context: Context, report: CrashReportData) {
    for (entry in report.toMap()) {
      if (entry.key == ReportField.LOGCAT.name || entry.key == ReportField.STACK_TRACE.name) {
        val element = (entry.value as? String) ?: continue
        report.put(entry.key, filterFileNames(element))
      }
    }
    
    super.send(context, report)
  }

  /**
   * Remove all file names from the given text
   * @param text The given text
   * @return the filtered text
   */
  private fun filterFileNames(text: String?): String {
    val regex = ("(?i)\\b([^\\s:.-]+)[.](" + listOfExtensions.joinToString("|") + ")\\b").toRegex()
    return text?.replace(regex, "example.file") ?: ""
  }

  companion object {
    val listOfExtensions = listOf( "DOC", "DOCX", "LOG", "MSG", "ODT", "PAGES", "RTF", "TEX", "TXT")
  }
}
@AcraCore(
    reportSenderFactoryClasses = [CustomReportSenderFactory::class],
    buildConfigClass = BuildConfig::class,
    reportFormat = StringFormat.JSON,
    reportContent = [
      ReportField.LOGCAT,
      ReportField.STACK_TRACE]
)
@AcraHttpSender(
    uri = "https://my.site/acra",
    httpMethod = HttpSender.Method.POST
)
class MyApplication : Application(), Configuration.Provider {
  override fun attachBaseContext(base: Context) {
    super.attachBaseContext(base)
    initACRA()
  }

  private fun initACRA() {
    ACRA.init(this)
    val installVersion = SharedPreferencesHelper.getString(
        PreferenceManager.getDefaultSharedPreferences(this),
        Constants.PREF_KEY_INSTALL_VERSION, "unknown")
    ACRA.getErrorReporter().putCustomData(
        Constants.PREF_KEY_INSTALL_VERSION.toUpperCase(Locale.getDefault()), installVersion)
  }
}

after switching to use 5.8.1

implementation 'ch.acra:acra-http:5.8.1'
//ACRA needs the following dependencies to use a custom report sender
compileOnly("com.google.auto.service:auto-service-annotations:1.0")
annotationProcessor("com.google.auto.service:auto-service:1.0")
@AutoService(ReportSenderFactory::class)
class CustomReportSenderFactory : HasConfigPlugin(HttpSenderConfiguration::class.java), ReportSenderFactory {
  override fun create(context: Context, config: CoreConfiguration): ReportSender {
    return CustomReportSender(config)
  }
}

class CustomReportSender - the same

class MyApplication : Application(), Configuration.Provider {
  override fun attachBaseContext(base: Context) {
    super.attachBaseContext(base)
    initACRA()
  }

  private fun initACRA() {
    initAcra {
      reportFormat = StringFormat.JSON
      buildConfigClass = BuildConfig::class.java
      reportContent = arrayOf(
        ReportField.LOGCAT,
        ReportField.STACK_TRACE
      )

      httpSender {
        uri = "https://my.site/acra"
        httpMethod = HttpSender.Method.POST
      }
    }   

    val installVersion = SharedPreferencesHelper.getString(
        PreferenceManager.getDefaultSharedPreferences(this),
        Constants.PREF_KEY_INSTALL_VERSION, "unknown")
    ACRA.errorReporter.putCustomData(
        Constants.PREF_KEY_INSTALL_VERSION.toUpperCase(Locale.getDefault()), installVersion)
  }
}

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DenBond7commented, May 20, 2021

@F43nd1r Also thank you for updating the docs

1reaction
F43nd1rcommented, May 20, 2021
@AutoService(ReportSenderFactory::class)
class CustomReportSenderFactory

This is the replacement, which you already applied. You need to use kapt instead of annotationProcessor for it to work with kotlin code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Report Sender Installation Guide | CloudAnswers Help Center
1. Install Report Sender · 2. Assign the Permission Set · 3. Go to the "Report Sender" tab · 4. Activate report sender...
Read more >
Sender - User Guide | BesWebSoft WordPress Plugin - BestWebSoft
Open your WordPress Admin Dashboard and find the menu on the left. 1.2. Open the ”Sender” > “Settings” page. 2. Settings. Use the...
Read more >
Apache Kafka Reference Guide - Quarkus
This reference guide demonstrates how your Quarkus application can utilize SmallRye Reactive Messaging to interact with Apache Kafka.
Read more >
Reliable group communication with JGroups
The address of the sender. Can be null , and will be filled in by the transport protocol (e.g. UDP) before the message...
Read more >
vApp Deployment and Configuration Guide - VMware
7. Click Update to apply your settings. vCenter Operations can send email notifications and scheduled reports. What to do next. Install a custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found