diff --git a/exporter/newrelicexporter/metrics.go b/exporter/newrelicexporter/metrics.go index 30a5bbe687a8..1a94c941c995 100644 --- a/exporter/newrelicexporter/metrics.go +++ b/exporter/newrelicexporter/metrics.go @@ -17,6 +17,7 @@ package newrelicexporter import ( "context" "strconv" + "strings" "time" "go.opencensus.io/stats" @@ -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{ @@ -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] } diff --git a/exporter/newrelicexporter/metrics_test.go b/exporter/newrelicexporter/metrics_test.go index b0cb73f119d2..94b7f9fb0942 100644 --- a/exporter/newrelicexporter/metrics_test.go +++ b/exporter/newrelicexporter/metrics_test.go @@ -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) { diff --git a/exporter/newrelicexporter/newrelic.go b/exporter/newrelicexporter/newrelic.go index 48013d28325b..6db55933836a 100644 --- a/exporter/newrelicexporter/newrelic.go +++ b/exporter/newrelicexporter/newrelic.go @@ -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 diff --git a/exporter/newrelicexporter/newrelic_test.go b/exporter/newrelicexporter/newrelic_test.go index 4c72b15d9ee4..2b9f566b7963 100644 --- a/exporter/newrelicexporter/newrelic_test.go +++ b/exporter/newrelicexporter/newrelic_test.go @@ -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) {