-
Notifications
You must be signed in to change notification settings - Fork 437
/
agent.go
36 lines (32 loc) · 1016 Bytes
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022 Datadog, Inc.
package internal
import (
"net/url"
"os"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)
// AgentURLFromEnv determines the trace agent URL from environment variable
// DD_TRACE_AGENT_URL. If the determined value is valid and the scheme is
// supported (unix, http or https), it will return an *url.URL. Otherwise,
// it returns nil.
func AgentURLFromEnv() *url.URL {
agentURL := os.Getenv("DD_TRACE_AGENT_URL")
if agentURL == "" {
return nil
}
u, err := url.Parse(agentURL)
if err != nil {
log.Warn("Failed to parse DD_TRACE_AGENT_URL: %v", err)
return nil
}
switch u.Scheme {
case "unix", "http", "https":
return u
default:
log.Warn("Unsupported protocol %q in Agent URL %q. Must be one of: http, https, unix.", u.Scheme, agentURL)
return nil
}
}