Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Fix error logged by Jaeger remote sampler on empty or unset `OTEL_TRACES_SAMPLER_ARG` environment variable (#6511)
- Relax minimum Go version to 1.22.0 in various modules. (#6595)
- `NewSDK` handles empty `OpenTelemetryConfiguration.Resource` properly in `go.opentelemetry.io/contrib/config/v0.3.0`. (#6606)
- Fix a possible nil dereference panic in `NewSDK` of `go.opentelemetry.io/contrib/config/v0.3.0`. (#6606)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
11 changes: 6 additions & 5 deletions config/v0.3.0/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ func keyVal(k string, v any) attribute.KeyValue {
}

func newResource(res *Resource) *resource.Resource {
if res == nil || res.Attributes == nil {
if res == nil {
Comment thread
MrAlias marked this conversation as resolved.
return resource.Default()
}
var attrs []attribute.KeyValue

var attrs []attribute.KeyValue
for _, v := range res.Attributes {
attrs = append(attrs, keyVal(v.Name, v.Value))
}

return resource.NewWithAttributes(*res.SchemaUrl,
attrs...,
)
if res.SchemaUrl == nil {
return resource.NewSchemaless(attrs...)
}
return resource.NewWithAttributes(*res.SchemaUrl, attrs...)
}
63 changes: 39 additions & 24 deletions config/v0.3.0/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,7 @@ import (
type mockType struct{}

func TestNewResource(t *testing.T) {
res := resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("service-a"),
)
other := mockType{}
resWithAttrs := resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("service-a"),
attribute.Bool("attr-bool", true),
attribute.String("attr-uint64", fmt.Sprintf("%d", 164)),
attribute.Int64("attr-int64", int64(-164)),
attribute.Float64("attr-float64", float64(64.0)),
attribute.Int64("attr-int8", int64(-18)),
attribute.Int64("attr-uint8", int64(18)),
attribute.Int64("attr-int16", int64(-116)),
attribute.Int64("attr-uint16", int64(116)),
attribute.Int64("attr-int32", int64(-132)),
attribute.Int64("attr-uint32", int64(132)),
attribute.Float64("attr-float32", float64(32.0)),
attribute.Int64("attr-int", int64(-1)),
attribute.String("attr-uint", fmt.Sprintf("%d", 1)),
attribute.String("attr-string", "string-val"),
attribute.String("attr-default", fmt.Sprintf("%v", other)),
)
tests := []struct {
name string
config *Resource
Expand All @@ -51,7 +30,25 @@ func TestNewResource(t *testing.T) {
{
name: "resource-no-attributes",
config: &Resource{},
wantResource: resource.Default(),
wantResource: resource.NewSchemaless(),
},
{
name: "resource-with-schema",
config: &Resource{
SchemaUrl: ptr(semconv.SchemaURL),
},
wantResource: resource.NewWithAttributes(semconv.SchemaURL),
},
{
name: "resource-with-attributes",
config: &Resource{
Attributes: []AttributeNameValue{
{Name: "service.name", Value: "service-a"},
},
},
wantResource: resource.NewWithAttributes("",
semconv.ServiceName("service-a"),
),
},
{
name: "resource-with-attributes-and-schema",
Expand All @@ -61,7 +58,9 @@ func TestNewResource(t *testing.T) {
},
SchemaUrl: ptr(semconv.SchemaURL),
},
wantResource: res,
wantResource: resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("service-a"),
),
},
{
name: "resource-with-additional-attributes-and-schema",
Expand All @@ -86,7 +85,23 @@ func TestNewResource(t *testing.T) {
},
SchemaUrl: ptr(semconv.SchemaURL),
},
wantResource: resWithAttrs,
wantResource: resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("service-a"),
attribute.Bool("attr-bool", true),
attribute.String("attr-uint64", fmt.Sprintf("%d", 164)),
attribute.Int64("attr-int64", int64(-164)),
attribute.Float64("attr-float64", float64(64.0)),
attribute.Int64("attr-int8", int64(-18)),
attribute.Int64("attr-uint8", int64(18)),
attribute.Int64("attr-int16", int64(-116)),
attribute.Int64("attr-uint16", int64(116)),
attribute.Int64("attr-int32", int64(-132)),
attribute.Int64("attr-uint32", int64(132)),
attribute.Float64("attr-float32", float64(32.0)),
attribute.Int64("attr-int", int64(-1)),
attribute.String("attr-uint", fmt.Sprintf("%d", 1)),
attribute.String("attr-string", "string-val"),
attribute.String("attr-default", fmt.Sprintf("%v", other))),
},
}
for _, tt := range tests {
Expand Down