Skip to content

Commit

Permalink
config: update schema to v0.2.0
Browse files Browse the repository at this point in the history
This updates changes the Attributes struct with a ServiceName and AdditionalProperties to a map[string]interface{}

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Jun 11, 2024
1 parent b368fc0 commit c760363
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ update-all-otel-deps:
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR=tmp/opentelememetry-configuration

# The SHA matching the current version of the opentelemetry-configuration schema to use
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=f38ac7c3a499ae5f81924ef9c455c27a56130562
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=v0.2.0

# Cleanup temporary directory
genjsonschema-cleanup:
Expand Down
46 changes: 39 additions & 7 deletions config/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.25.0"
)

func keyVal(k string, v any) attribute.KeyValue {
Expand Down Expand Up @@ -50,14 +49,10 @@ func newResource(res *Resource) (*resource.Resource, error) {
if res == nil || res.Attributes == nil {
return resource.Default(), nil
}
attrs := []attribute.KeyValue{
semconv.ServiceName(*res.Attributes.ServiceName),
}
var attrs []attribute.KeyValue

if props, ok := res.Attributes.AdditionalProperties.(map[string]any); ok {
for k, v := range props {
attrs = append(attrs, keyVal(k, v))
}
for k, v := range res.Attributes {
attrs = append(attrs, keyVal(k, v))
}

return resource.Merge(resource.Default(),
Expand Down
44 changes: 21 additions & 23 deletions config/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func TestNewResource(t *testing.T) {
name: "resource-with-attributes-invalid-schema",
config: &Resource{
SchemaUrl: ptr("https://opentelemetry.io/invalid-schema"),
Attributes: &Attributes{
ServiceName: ptr("service-a"),
Attributes: Attributes{
"service.name": "service-a",
},
},
wantResource: resource.NewSchemaless(res.Attributes()...),
Expand All @@ -73,8 +73,8 @@ func TestNewResource(t *testing.T) {
{
name: "resource-with-attributes-and-schema",
config: &Resource{
Attributes: &Attributes{
ServiceName: ptr("service-a"),
Attributes: Attributes{
"service.name": "service-a",
},
SchemaUrl: ptr(semconv.SchemaURL),
},
Expand All @@ -83,25 +83,23 @@ func TestNewResource(t *testing.T) {
{
name: "resource-with-additional-attributes-and-schema",
config: &Resource{
Attributes: &Attributes{
ServiceName: ptr("service-a"),
AdditionalProperties: map[string]any{
"attr-bool": true,
"attr-int64": int64(-164),
"attr-uint64": uint64(164),
"attr-float64": float64(64.0),
"attr-int8": int8(-18),
"attr-uint8": uint8(18),
"attr-int16": int16(-116),
"attr-uint16": uint16(116),
"attr-int32": int32(-132),
"attr-uint32": uint32(132),
"attr-float32": float32(32.0),
"attr-int": int(-1),
"attr-uint": uint(1),
"attr-string": "string-val",
"attr-default": other,
},
Attributes: Attributes{
"service.name": "service-a",
"attr-bool": true,
"attr-int64": int64(-164),
"attr-uint64": uint64(164),
"attr-float64": float64(64.0),
"attr-int8": int8(-18),
"attr-uint8": uint8(18),
"attr-int16": int16(-116),
"attr-uint16": uint16(116),
"attr-int32": int32(-132),
"attr-uint32": uint32(132),
"attr-float32": float32(32.0),
"attr-int": int(-1),
"attr-uint": uint(1),
"attr-string": "string-val",
"attr-default": other,
},
SchemaUrl: ptr(semconv.SchemaURL),
},
Expand Down

0 comments on commit c760363

Please sign in to comment.