dd-trace-go
dd-trace-go copied to clipboard
all: implement shared agent discovery
dd-trace-go has lots of duplicated logic around agent discovery, including
finding the agent URL, handling UDS, and detecting agent features. Move this
logic into a shared package.
The shared discovery supports resolving the agent address from user config as follows:
- First, in-code config (
tracer.WithAgentAddr,profiler.WithAgentAddr, etc.) - If no in-code config, the value of
DD_TRACE_AGENT_URL - Next, a combination of
DD_AGENT_HOSTandDD_TRACE_AGENT_PORT, defaulting tolocalhostand8126, respectively - If none of those env vars are set,
/var/run/datadog/apm.socketif it exists - Finally,
localhost:8126
This is accomplished by adding functions to give an HTTP client (which handles UDS) and the address of the agent. The profiler and tracer can use these values first and then override them with user-provided options.
Note that this PR duplicates some of the work in #1199. We can resolve that one first and I can rebase this PR, or we can use this PR instead, either way works for me.
Resolves #1023