Debian Codegraph @

otelconf/v0.3.0/resource.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otelconf // import "go.opentelemetry.io/contrib/otelconf/v0.3.0"
5
6 import (
7 "go.opentelemetry.io/otel/attribute"
8 "go.opentelemetry.io/otel/sdk/resource"
9
10 "go.opentelemetry.io/contrib/otelconf/internal/kv"
11 )
12
13 func newResource(res *Resource) *resource.Resource {
14 if res == nil {
15 return resource.Default()
16 }
17
18 attrs := make([]attribute.KeyValue, 0, len(res.Attributes))
19
20 for _, v := range res.Attributes {
21 attrs = append(attrs, kv.FromNameValue(v.Name, v.Value))
22 }
23
24 if res.SchemaUrl == nil {
25 return resource.NewSchemaless(attrs...)
26 }
27 return resource.NewWithAttributes(*res.SchemaUrl, attrs...)
28 }