elastic / elastic/apm-agent-android

HttpAttributesVisitor Not Invoked for Auto-Instrumented HTTP Calls

Open
#385 1 comment 0 reactions 1 assignee Claimed by @LikeTheSalad View on GitHub
agent-android agent-mobile community triage v1.0.0
Dominant language
Kotlin
Stars
43
Forks
22
Avg merge
2d 1h
Merged PRs (30d)
26

Description

### **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/)](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)`:
```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 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!**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.