Debian Codegraph @

exporter/debugexporter/internal/otlptext/test_helpers.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otlptext // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/otlptext"
5
6 import (
7 "go.opentelemetry.io/collector/pdata/pcommon"
8 "go.opentelemetry.io/collector/pdata/xpdata/entity"
9 )
10
11 func addEntityRefsToResource(resource pcommon.Resource) {
12 entityRefs := entity.ResourceEntityRefs(resource)
13
14 serviceRef := entityRefs.AppendEmpty()
15 serviceRef.SetType("service")
16 serviceRef.SetSchemaUrl("https://opentelemetry.io/schemas/1.21.0")
17 serviceRef.IdKeys().Append("service.name")
18 serviceRef.DescriptionKeys().Append("service.version")
19
20 if _, exists := resource.Attributes().Get("host.name"); exists {
21 hostRef := entityRefs.AppendEmpty()
22 hostRef.SetType("host")
23 hostRef.IdKeys().Append("host.name")
24 }
25 }
26
27 func setupResourceWithEntityRefs(resource pcommon.Resource) {
28 resource.Attributes().PutStr("service.name", "my-service")
29 resource.Attributes().PutStr("service.version", "1.0.0")
30 resource.Attributes().PutStr("host.name", "server-01")
31
32 addEntityRefsToResource(resource)
33 }