Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android agent - HttpAttributesVisitor Not Invoked for Auto-Instrumented HTTP Calls #901

Open
1DevNawaf opened this issue Jan 26, 2025 · 0 comments

Comments

@1DevNawaf
Copy link

Describe the bug

When using a custom HttpAttributesVisitor with the Elastic APM Android SDK, it never gets invoked for auto-instrumented HTTP requests. The default spans (HTTP GET, HTTP POST) appear in APM, but the custom visitor code (including any log statements) is never executed.


To Reproduce

  1. Use this configuration (simplified example):

    class ApmAttributesVisitor : HttpAttributesVisitor {
        override fun visit(builder: AttributesBuilder, request: HttpRequest) {
            Log.d("ApmAgentLogs", "Enter Visitor fun")
            val uri = Uri.parse(request.url.toString())
            val rawPath = uri.path ?: "/"
            builder.put("http.route", rawPath)
        }
    }
    
    val httpTraceConfig = HttpTraceConfiguration.builder()
        .addHttpAttributesVisitor(ApmAttributesVisitor())
        .build()
    
    val instrumentationsConfig = InstrumentationConfiguration.builder()
        .enableHttpTracing(true)
        .build()
    
    val elasticConfig = ElasticApmConfiguration.builder()
        .setHttpTraceConfiguration(httpTraceConfig)
        .setInstrumentationConfiguration(instrumentationsConfig)
        .setServiceName("MyServiceName")
        .build()
    
    ElasticApmAgent.initialize(application, elasticConfig)
  2. Make an OkHttp-based network call.

  3. Observe that the APM UI captures spans named HTTP GET or HTTP POST, but your custom visitor’s logic is never called (no logs, no custom attributes).


Expected behavior

  • The HttpAttributesVisitor should be invoked for each auto-instrumented HTTP request.
  • Logs in visit(...) should appear in Logcat.
  • Any custom attributes (e.g., http.route) should appear in the APM UI.

Debug logs

I enabled debug logging for the agent but found no references to the custom visitor being invoked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant