Skip to content

Commit

Permalink
Merge pull request #27 from newrelic/mwhelan/missingFName
Browse files Browse the repository at this point in the history
Workaround for missing function name
  • Loading branch information
Matt Whelan authored Nov 24, 2020
2 parents 0cd117b + 5376799 commit ecbc801
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions lambda/extension/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (rc *RegistrationClient) Register(registrationRequest api.RegistrationReque
if err != nil {
return nil, nil, err
}
util.Debugf("Registration response: %s", bodyBytes)

var registrationResponse api.RegistrationResponse
err = json.Unmarshal(bodyBytes, &registrationResponse)
Expand Down
10 changes: 10 additions & 0 deletions telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *Client) SendTelemetry(invokedFunctionARN string, telemetry [][]byte) er
logEvents = append(logEvents, logEvent)
}

if len(c.functionName) == 0 {
nameStart := strings.Index(invokedFunctionARN, ":function:") + len(":function:")
nameLen := strings.Index(invokedFunctionARN[nameStart:], ":")
if nameLen < 0 {
nameLen = len(invokedFunctionARN) - nameStart
}
c.functionName = invokedFunctionARN[nameStart : nameStart+nameLen]
util.Debugf("Recovered missing function name: %s", c.functionName)
}

compressedPayloads, err := CompressedPayloadsForLogEvents(logEvents, c.functionName, invokedFunctionARN)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion telemetry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestClientSend(t *testing.T) {
client := NewWithHTTPClient(srv.Client(), "", "a mock license key", &srv.URL)

bytes := []byte("foobar")
err := client.SendTelemetry("fakeArn", [][]byte{bytes})
err := client.SendTelemetry("arn:aws:lambda:us-east-1:1234:function:newrelic-example-go", [][]byte{bytes})

assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion telemetry/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CompressedPayloadsForLogEvents(logsEvents []LogsEvent, functionName string,
FunctionName: functionName,
InvokedFunctionARN: invokedFunctionARN,
LogGroupName: logGroupName,
LogStreamName: "newrelic-lambda-extension:1.0.1",
LogStreamName: "newrelic-lambda-extension:1.0.2",
}
data := RequestData{Context: context, Entry: string(entry)}

Expand Down

0 comments on commit ecbc801

Please sign in to comment.