dd-trace-go icon indicating copy to clipboard operation
dd-trace-go copied to clipboard

tracer: add use UDS if the environment variable is available

Open agates4 opened this issue 2 years ago • 5 comments

Rather than manually specifying "WithUds" in our client startup options like this:

func (b *Bootstrap) startTracingDatadog(ctx context.Context) (tracetools.Span, context.Context, stopper) {
	opts := []tracer.StartOption{
		tracer.WithServiceName("buildkite_agent"),
		tracer.WithSampler(tracer.NewAllSampler()),
		tracer.WithAnalytics(true),
	}

	if sock := os.Getenv("DD_APM_RECEIVER_SOCKET"); sock != "" {
		opts = append(opts, tracer.WithUDS(sock))
	}

	// ... rest of the tracing setup
}

This feature has dd-trace-go handle the Datadog environment variable and automatically setup withUDS if the variable is set. This replicates the functionality of the Ruby, C++, and Python Datadog clients.

agates4 avatar May 17 '22 17:05 agates4

@gbbr hey Gabriel, this is a change to enable automatic UDS usage if the expected Datadog environment variable is set.

agates4 avatar May 17 '22 17:05 agates4

@agates4 I did a s/profiler/tracer/ on the PR title because it doesn't seem like this PR is tracer related?

felixge avatar May 23 '22 10:05 felixge

@felixge looks good to me, thanks for the change

agates4 avatar May 23 '22 10:05 agates4

Hi @agates4 thanks for proposing a change here. Looking at the variable described here DD_APM_RECEIVER_SOCKET, it appears this env var is only used by the datadog agent and not the tracing libraries. I took a look at the python tracing library as well as the ruby tracing library and neither seem to look for this variable. The go tracing library here only requires you to use WithUDS if you aren't using the default UDS location from the agent /var/run/datadog/apm.socket. (checked here https://github.com/DataDog/dd-trace-go/blob/v1/ddtrace/tracer/option.go#L310).

Are you looking to use a different UDS path and only configure it via an environment variable?

ajgajg1134 avatar May 24 '22 17:05 ajgajg1134

Hey @ajgajg1134, thank you for the comment. Looks like you are right, I was confusing the tracing libraries mention of the variable with the implementation of it:

It looks like the functionality to replicate is taking the DD_TRACE_AGENT_URL and if it is a UDS url, to use withUDS with that specified path. I'll add the changes needed to go in that direction instead

agates4 avatar Jun 06 '22 09:06 agates4

The tracer already automatically uses the defaultSocketAPM if it's available. Please see: https://github.com/DataDog/dd-trace-go/blob/814381c4a58aca78c5dc3b8537c988b3d976147c/ddtrace/tracer/option.go#L325-L332

I'm going to close this PR as stale for now. Please feel free to re-open or open a new one if there's a change you'd like to make.

knusbaum avatar Sep 21 '22 15:09 knusbaum