Skip to content

HttpAttributesVisitor Not Invoked for Auto-Instrumented HTTP Calls #385

Open
@1DevNawaf

Description

@1DevNawaf

Description

I’m using the Elastic APM Android SDK (auto-instrumentation) to capture HTTP calls in my Android application. According to the [official documentation](https://www.elastic.co/guide/en/apm/guide/current/), I can implement a custom HttpAttributesVisitor and add it to the HttpTraceConfiguration to modify or add attributes (e.g., rename spans to include the endpoint path). However, my custom visitor is never invoked during runtime, and no logs appear to show that it’s being accessed.


Steps to Reproduce

  1. Initialize the agent in Application.onCreate() (or a similar place) with enableHttpTracing(true):
    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 network calls using OkHttp or another supported library.
  3. Observe that the HTTP spans appear in APM (named HTTP GET or HTTP POST), but the custom visitor’s code never runs (no log statements, no custom attributes visible).

Expected Behavior

  • The HttpAttributesVisitor should be called for every auto-instrumented HTTP request.
  • My custom log (Log.d("MyTest", ...)) should appear in Logcat.
  • Additional attributes (e.g., "http.route") or custom data should be visible in the APM UI.

Actual Behavior

  • HTTP requests are auto-instrumented and show up in APM as HTTP GET or HTTP POST, but the custom visitor code is never triggered.
  • No logs from HttpAttributesVisitor.
  • No additional attributes in APM.

Workarounds Tried

  • Verified that the agent initializes before any network calls.
  • Attempted HttpFilter or different approaches to confirm instrumentation. Only the default BasicHttpAttributesVisitor output is visible.
  • Tried using various attributes (http.route, http.target) to see if any rename logic might appear.
  • Disabled auto-instrumentation and used manual instrumentation, which works but defeats the purpose of a HttpAttributesVisitor.

Request

  • Please confirm if HttpTraceConfiguration with a custom HttpAttributesVisitor is fully supported in this SDK version for auto-instrumented OkHttp calls.
  • If it is supported, is there additional configuration needed (e.g., a separate artifact or version mismatch)?
  • Any guidance on why the visitor might never be invoked would be very helpful.

Thanks in advance!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions