@@ -15,10 +15,10 @@ import (
15
15
"fmt"
16
16
"net/http"
17
17
"os"
18
- "strconv"
19
18
"time"
20
19
21
20
"github.com/DataDog/datadog-lambda-go/internal/logger"
21
+
22
22
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
23
23
)
24
24
@@ -50,27 +50,29 @@ const (
50
50
)
51
51
52
52
type ExtensionManager struct {
53
- helloRoute string
54
- flushRoute string
55
- extensionPath string
56
- startInvocationUrl string
57
- endInvocationUrl string
58
- httpClient HTTPClient
59
- isExtensionRunning bool
53
+ helloRoute string
54
+ flushRoute string
55
+ extensionPath string
56
+ startInvocationUrl string
57
+ endInvocationUrl string
58
+ httpClient HTTPClient
59
+ isExtensionRunning bool
60
+ isUniversalInstrumentation bool
60
61
}
61
62
62
63
type HTTPClient interface {
63
64
Do (req * http.Request ) (* http.Response , error )
64
65
}
65
66
66
- func BuildExtensionManager () * ExtensionManager {
67
+ func BuildExtensionManager (isUniversalInstrumentation bool ) * ExtensionManager {
67
68
em := & ExtensionManager {
68
- helloRoute : helloUrl ,
69
- flushRoute : flushUrl ,
70
- startInvocationUrl : startInvocationUrl ,
71
- endInvocationUrl : endInvocationUrl ,
72
- extensionPath : extensionPath ,
73
- httpClient : & http.Client {Timeout : timeout },
69
+ helloRoute : helloUrl ,
70
+ flushRoute : flushUrl ,
71
+ startInvocationUrl : startInvocationUrl ,
72
+ endInvocationUrl : endInvocationUrl ,
73
+ extensionPath : extensionPath ,
74
+ httpClient : & http.Client {Timeout : timeout },
75
+ isUniversalInstrumentation : isUniversalInstrumentation ,
74
76
}
75
77
em .checkAgentRunning ()
76
78
return em
@@ -85,8 +87,7 @@ func (em *ExtensionManager) checkAgentRunning() {
85
87
em .isExtensionRunning = true
86
88
87
89
// Tell the extension not to create an execution span if universal instrumentation is disabled
88
- isUniversalInstrumentation , _ := strconv .ParseBool (os .Getenv ("DD_UNIVERSAL_INSTRUMENTATION" ))
89
- if ! isUniversalInstrumentation {
90
+ if ! em .isUniversalInstrumentation {
90
91
req , _ := http .NewRequest (http .MethodGet , em .helloRoute , nil )
91
92
if response , err := em .httpClient .Do (req ); err == nil && response .StatusCode == 200 {
92
93
logger .Debug ("Hit the extension /hello route" )
0 commit comments