elastic / apm-agent-go

https://www.elastic.co/guide/en/apm/agent/go/current/index.html
Apache License 2.0
422 stars 197 forks source link

capture_headers option ignored with remote agent cfg #1427

Open kruskall opened 1 year ago

kruskall commented 1 year ago

Describe the bug While testing https://github.com/elastic/apm-server/issues/10467 an issue was discovered in which the go agent was ignoring the capture_headers option. The test was carried out with a test application and and Elastic Agent managed APM Server (without fleet).

app:

package main

import (
    "fmt"
    "net/http"

    "golang.org/x/net/context/ctxhttp"

    "go.elastic.co/apm/module/apmhttp/v2"
    "go.elastic.co/apm/v2"
)

var tracingClient = apmhttp.WrapClient(http.DefaultClient)

func serverHandler(w http.ResponseWriter, req *http.Request) {
    resp, err := ctxhttp.Get(req.Context(), tracingClient, "http://example.com")
    if err != nil {
        apm.CaptureError(req.Context(), err).Send()
        http.Error(w, "failed to query backend", 500)
        return
    }
    defer resp.Body.Close()
    fmt.Println(resp.Status)
}

func main() {
    http.ListenAndServe(":8080", apmhttp.Wrap(http.HandlerFunc(serverHandler)))
}

To Reproduce Steps to reproduce the behavior:

  1. Create an EA managed APM Server (you might want to reduce the agent config cache)
  2. Run the example app: ELASTIC_APM_LOG_FILE=out.log ELASTIC_APM_LOG_LEVEL=debug ELASTIC_APM_SERVER_URL=<apm_server_url> ELASTIC_APM_SECRET_TOKEN=<token> go run main.go
  3. Send a request to localhost:8080
  4. Make sure the agent is working and you can see APM data in kibana
  5. Update the agent settings in kibana to enable capture headers
  6. Send a request to localhost:8080
  7. stop the example app
  8. open out.log and look at the warning:
{"level":"debug","message":"central config update: updated capture_body to all"}
{"level":"warning","message":"central config failure: unsupported config: capture_headers"}
{"level":"debug","message":"central config update: updated log_level to debug"}

Expected behavior A clear and concise description of what you expected to happen.

No warning

milesich commented 3 weeks ago

This is still na issue. To fix it the support would have to be added to the updateRemoteConfig method in https://github.com/elastic/apm-agent-go/blob/main/config.go#L413