apm-agent-go icon indicating copy to clipboard operation
apm-agent-go copied to clipboard

`apm.DefaultTracer` misbehaves when transport configuration is invalid

Open axw opened this issue 2 years ago • 4 comments

The documentation for apm.DefaultTracer says:

// The default tracer is configured via environment variables, and will always // be non-nil. If any of the environment variables are invalid, the // corresponding errors will be logged to stderr and the default values will be // used instead.

However, at the moment, if creating the transport fails (e.g. beause the URL is invalid) the default URL (http://localhost:8200) is not used -- instead, we use a transport that discards all data:

https://github.com/elastic/apm-agent-go/blob/2e6d3cf4bd88961fbb47f72451e18e45922a81c9/tracer.go#L315-L317

Another problem is that the agent will be "active", meaning that it will create transactions and spans and inject their trace context into headers, but the events will be discarded - so distributed traces will always be broken.

If we were to change the code to match the comment, distributed traces would still be broken unless the expected URL happened to be http://localhost:8200, which seems unlikely. I think instead we should:

  • set the tracer to be inactive rather than just using a discard transport
  • update the DefaultTracer comment to mention that if the transport-specific config vars are invalid, then we'll deactivate the tracer

axw avatar Feb 09 '23 07:02 axw

Hi @axw, I hope this message finds you well. I'm reaching out to express my interest in contributing to the resolution of this bug. I noticed this particular issue and wanted to inquire if anyone is currently working on it. If not, I would like to take it up!

shubhamsharma7867 avatar Mar 28 '24 17:03 shubhamsharma7867

Nobody is working on this yet. We do welcome PRs though.

dmathieu avatar Apr 02 '24 09:04 dmathieu

@dmathieu Sure! Thanks for confirming.

shubhamsharma7867 avatar Apr 04 '24 15:04 shubhamsharma7867

Hi @dmathieu created a PR for this bug fix https://github.com/elastic/apm-agent-go/pull/1618

shubhamsharma7867 avatar Apr 28 '24 07:04 shubhamsharma7867