Debian Codegraph @

otelconf/v0.2.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.2.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, error) {
14 if res == nil || res.Attributes == nil {
15 return resource.Default(), nil
16 }
17 attrs := make([]attribute.KeyValue, 0, len(res.Attributes))
18
19 for k, v := range res.Attributes {
20 attrs = append(attrs, kv.FromNameValue(k, v))
21 }
22
23 return resource.Merge(resource.Default(),
24 resource.NewWithAttributes(*res.SchemaUrl,
25 attrs...,
26 ))
27 }