-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(trace): Move custom trace attributes to a trace package
Signed-off-by: Vincent Mercier <vmercier@gmail.com>
- Loading branch information
1 parent
a0743a0
commit f475a1a
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Package trace provides OTEL tracing resources | ||
package trace | ||
|
||
import "go.opentelemetry.io/otel/attribute" | ||
|
||
// Attribute Naming convention | ||
// | ||
// Use namespacing to avoid name clashes. Delimit the namespaces using a dot character. For example service.version denotes the service version where service is the namespace and version is an attribute in that namespace. | ||
// For each multi-word dot-delimited component of the attribute name separate the words by underscores (i.e. use snake_case). | ||
// See https://opentelemetry.io/docs/specs/semconv/general/attribute-naming/ | ||
|
||
const ( | ||
AWSServiceCodeOtelKey = attribute.Key("qonto.prometheus_rds_exporter.aws.quota.service_code") | ||
AWSQuotaCodeOtelKey = attribute.Key("qonto.prometheus_rds_exporter.aws.quota.code") | ||
AWSInstanceTypesCountKey = attribute.Key("qonto.prometheus_rds_exporter.aws.instance-types-count") | ||
) | ||
|
||
func AWSQuotaServiceCode(val string) attribute.KeyValue { | ||
return AWSServiceCodeOtelKey.String(val) | ||
} | ||
|
||
func AWSQuotaCode(val string) attribute.KeyValue { | ||
return AWSQuotaCodeOtelKey.String(val) | ||
} | ||
|
||
func AWSInstanceTypesCount(val int64) attribute.KeyValue { | ||
return AWSInstanceTypesCountKey.Int64(val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package trace_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/qonto/prometheus-rds-exporter/internal/app/trace" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
func TestOtelKeys(t *testing.T) { | ||
type test struct { | ||
name string | ||
want attribute.KeyValue | ||
key string | ||
value any | ||
} | ||
|
||
tests := []test{ | ||
{"QuotaServiceCode", trace.AWSQuotaServiceCode("unittest"), "qonto.prometheus_rds_exporter.aws.quota.service_code", "unittest"}, | ||
{"QuotaCode", trace.AWSQuotaCode("unittest"), "qonto.prometheus_rds_exporter.aws.quota.code", "unittest"}, | ||
{"InstanceTypesCount", trace.AWSInstanceTypesCount(42), "qonto.prometheus_rds_exporter.aws.instance-types-count", int64(42)}, | ||
} | ||
|
||
for _, tc := range tests { | ||
if !reflect.DeepEqual(string(tc.want.Key), tc.key) { | ||
t.Fatalf("%s: expected key: %v, got: %v", tc.name, tc.want.Key, tc.key) | ||
} | ||
|
||
switch tc.value.(type) { | ||
case string: | ||
if !reflect.DeepEqual(tc.want.Value.AsString(), tc.value) { | ||
t.Fatalf("%s: expected value: %v, got: %v", tc.name, tc.want.Value.AsString(), tc.value) | ||
} | ||
case int64: | ||
if !reflect.DeepEqual(tc.want.Value.AsInt64(), tc.value) { | ||
t.Fatalf("%s: expected value: %v, got: %v", tc.name, tc.want.Value.AsInt64(), tc.value) | ||
} | ||
default: | ||
t.Fatalf("%s: %s type is not implemented. Add it to the test suite", tc.name, reflect.TypeOf(tc.value)) | ||
} | ||
} | ||
} |