Android agent - HttpAttributesVisitor Not Invoked for Auto-Instrumented HTTP Calls
- Dominant language
- Gherkin
- Stars
- 427
- Forks
- 125
- PR merge metrics
- No merged PRs in 30d
Description
### **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):
```kotlin
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.