Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update New Relic logging. #3690

Merged
merged 3 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion exporter/newrelicexporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package newrelicexporter
import (
"context"
"strconv"
"strings"
"time"

"go.opencensus.io/stats"
Expand Down Expand Up @@ -54,6 +55,8 @@ var (
statAttributeMetadata = stats.Int64("newrelicexporter_attribute_metadata_count", "Number of attributes processed", stats.UnitDimensionless)
)

const EuKeyPrefix = "eu01xx"

// MetricViews return metric views for Kafka receiver.
func MetricViews() []*view.View {
return []*view.View{
Expand Down Expand Up @@ -242,5 +245,9 @@ func sanitizeAPIKeyForLogging(apiKey string) string {
if len(apiKey) <= 8 {
return apiKey
}
return apiKey[:8]
end := 8
if strings.HasPrefix(apiKey, EuKeyPrefix) {
end += len(EuKeyPrefix)
}
return apiKey[:end]
}
1 change: 1 addition & 0 deletions exporter/newrelicexporter/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ func TestSanitizeApiKeyForLogging(t *testing.T) {
assert.Equal(t, "", sanitizeAPIKeyForLogging(""))
assert.Equal(t, "foo", sanitizeAPIKeyForLogging("foo"))
assert.Equal(t, "foobarba", sanitizeAPIKeyForLogging("foobarbazqux"))
assert.Equal(t, "eu01xxfoobarba", sanitizeAPIKeyForLogging("eu01xxfoobarbazqux"))
}

func TestMetadataHasDefaultValuesSet(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions exporter/newrelicexporter/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ func (e exporter) doRequest(details *exportMetadata, req *http.Request) error {
} else if response.StatusCode == http.StatusForbidden {
// The data has been lost, but it is due to an invalid api key
e.logger.Debug("HTTP Forbidden response", zap.String("Status", response.Status))
} else if response.StatusCode == http.StatusTooManyRequests {
// The data has been lost, but it is due to rate limiting
e.logger.Debug("HTTP Too Many Requests", zap.String("Status", response.Status))
} else {
// The data has been lost due to an error in our payload
details.dataOutputCount = 0
Expand Down
10 changes: 8 additions & 2 deletions exporter/newrelicexporter/newrelic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,14 @@ func TestExportTraceWithNot202StatusCode(t *testing.T) {
},
})

_, err := runTraceMock(context.Background(), ptrace, mockConfig{statusCode: 403})
require.Error(t, err)
{
_, err := runTraceMock(context.Background(), ptrace, mockConfig{statusCode: 403})
require.Error(t, err)
}
{
_, err := runTraceMock(context.Background(), ptrace, mockConfig{statusCode: 429})
require.Error(t, err)
}
}

func TestExportTraceWithBadPayload(t *testing.T) {
Expand Down