Skip to content

Commit 6523c06

Browse files
authored
Return error from function posting to APM server (#30)
1 parent 4ab86cf commit 6523c06

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

apm-lambda-extension/extension/apm_server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// todo: can this be a streaming or streaming style call that keeps the
1212
// connection open across invocations?
1313
// func PostToApmServer(postBody []byte, apmServerEndpoint string, apmServerSecretToken string) {
14-
func PostToApmServer(postBody []byte, config *extensionConfig) {
14+
func PostToApmServer(postBody []byte, config *extensionConfig) error {
1515
var compressedBytes bytes.Buffer
1616
w := gzip.NewWriter(&compressedBytes)
1717
w.Write(postBody)
@@ -34,7 +34,7 @@ func PostToApmServer(postBody []byte, config *extensionConfig) {
3434
}
3535
resp, err := client.Do(req)
3636
if err != nil {
37-
log.Fatalf("An Error Occured calling client.Do %v", err)
37+
return err
3838
}
3939

4040
//Read the response body
@@ -49,4 +49,6 @@ func PostToApmServer(postBody []byte, config *extensionConfig) {
4949
sb := string(body)
5050
log.Printf("Response Headers: %v\n", resp.Header)
5151
log.Printf("Response Body: %v\n", sb)
52+
53+
return nil
5254
}

apm-lambda-extension/extension/process_events.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ func FlushAPMData(dataChannel chan []byte, config *extensionConfig) {
1414
log.Println("Checking for agent data")
1515
for {
1616
select {
17-
case agentBytes := <-dataChannel:
17+
case agentData := <-dataChannel:
1818
log.Println("Received bytes from data channel")
19-
PostToApmServer(agentBytes, config)
19+
err := PostToApmServer(agentData, config)
20+
if err != nil {
21+
log.Printf("Error sending to APM server: %v", err)
22+
}
2023
default:
2124
log.Println("No more agent data")
2225
return

apm-lambda-extension/extension/route_handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func handleIntakeV2Events(handler *serverHandler, w http.ResponseWriter, r *http
1010
if nil != err {
1111
log.Println("could not get bytes from body")
1212
} else {
13-
log.Println("Receiving bytes from request")
13+
log.Println("Receiving bytes from agent request")
1414
handler.data <- bodyBytes
1515
}
1616
w.WriteHeader(http.StatusAccepted)

apm-lambda-extension/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func main() {
8282
log.Println("Exiting")
8383
return
8484
}
85-
log.Printf("Received event: %v\n", extension.PrettyPrint(res))
85+
log.Printf("Received event: %v\n", extension.PrettyPrint(event))
8686

8787
// A shutdown event indicates the execution environment is shutting down.
8888
// This is usually due to inactivity.
@@ -111,7 +111,10 @@ func main() {
111111
log.Println("Function invocation is complete, not receiving any more agent data")
112112
return
113113
case agentData := <-dataChannel:
114-
extension.PostToApmServer(agentData, config)
114+
err := extension.PostToApmServer(agentData, config)
115+
if err != nil {
116+
log.Printf("Error sending to APM server: %v", err)
117+
}
115118
}
116119
}
117120
}()

0 commit comments

Comments
 (0)