Skip to content

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

Open
@1DevNawaf

Description

@1DevNawaf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions