Debian Codegraph @

otelconf/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"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/otel/attribute"
10 "go.opentelemetry.io/otel/sdk/resource"
11
12 "go.opentelemetry.io/contrib/otelconf/internal/kv"
13 )
14
15 func newResource(r *Resource) (*resource.Resource, error) {
16 if r == nil {
17 return resource.Default(), nil
18 }
19
20 attrs := make([]attribute.KeyValue, 0, len(r.Attributes))
21 for _, v := range r.Attributes {
22 attrs = append(attrs, kv.FromNameValue(v.Name, v.Value))
23 }
24
25 var schema string
26 if r.SchemaUrl != nil {
27 schema = *r.SchemaUrl
28 }
29 opts := []resource.Option{
30 resource.WithAttributes(attrs...),
31 resource.WithSchemaURL(schema),
32 }
33
34 return resource.New(context.Background(), opts...)
35 }