Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 7, 2024
1 parent dbc55ed commit eb2e8d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ func BuildExtensionManager(isUniversalInstrumentation bool) *ExtensionManager {
}

func (em *ExtensionManager) checkAgentRunning() {
fmt.Printf("[DEBUG] checkAgentRunning()\n")
if _, err := os.Stat(em.extensionPath); err != nil {
logger.Debug("Will use the API")
fmt.Printf("[DEBUG] Extension is not running\n")
em.isExtensionRunning = false
} else {
fmt.Printf("[DEBUG] Extension is running\n")
logger.Debug("Will use the Serverless Agent")
em.isExtensionRunning = true

fmt.Printf("[DEBUG] universal instrumentation: %t\n", em.isUniversalInstrumentation)

// Tell the extension not to create an execution span if universal instrumentation is disabled
if !em.isUniversalInstrumentation {
req, _ := http.NewRequest(http.MethodGet, em.helloRoute, nil)
Expand All @@ -108,10 +113,12 @@ func (em *ExtensionManager) checkAgentRunning() {
}

func (em *ExtensionManager) SendStartInvocationRequest(ctx context.Context, eventPayload json.RawMessage) context.Context {
fmt.Println("[DEBUG] SendStartInvocationRequest()")
body := bytes.NewBuffer(eventPayload)
req, _ := http.NewRequest(http.MethodPost, em.startInvocationUrl, body)

if response, err := em.httpClient.Do(req); err == nil && response.StatusCode == 200 {
fmt.Printf("[DEBUG] SendStartInvocationRequest succeeded\n")
// Propagate dd-trace context from the extension response if found in the response headers
traceId := response.Header.Get(string(DdTraceId))
if traceId != "" {
Expand Down
2 changes: 2 additions & 0 deletions internal/trace/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (l *Listener) HandlerStarted(ctx context.Context, msg json.RawMessage) cont
return ctx
}

fmt.Printf("[DEBUG] universal instrumentation: %t\v", l.universalInstrumentation)
fmt.Printf("[DEBUG] extension running: %t\v", l.extensionManager.IsExtensionRunning())
if l.universalInstrumentation && l.extensionManager.IsExtensionRunning() {
ctx = l.extensionManager.SendStartInvocationRequest(ctx, msg)
}
Expand Down

0 comments on commit eb2e8d6

Please sign in to comment.