| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package entity // import "go.opentelemetry.io/collector/pdata/xpdata/entity" |
| 5 |
|
| 6 |
import ( |
| 7 |
"go.opentelemetry.io/collector/pdata/pcommon" |
| 8 |
) |
| 9 |
|
| 10 |
// Entity is a helper struct that represents an entity in a more user-friendly way than the underlying |
| 11 |
// EntityRef protobuf message. After adding an entity to a resource, the entity shares the resource's |
| 12 |
// attributes map, so modifications to the entity's attributes are immediately reflected in the resource. |
| 13 |
// To create an Entity, use the EntityMap's PutEmpty method. |
| 14 |
type Entity struct { |
| 15 |
ref EntityRef |
| 16 |
attributes pcommon.Map |
| 17 |
} |
| 18 |
|
| 19 |
func (e Entity) Type() string { |
| 20 |
return e.ref.Type() |
| 21 |
} |
| 22 |
|
| 23 |
func (e Entity) SchemaURL() string { |
| 24 |
return e.ref.SchemaUrl() |
| 25 |
} |
| 26 |
|
| 27 |
func (e Entity) SetSchemaURL(schemaURL string) { |
| 28 |
e.ref.SetSchemaUrl(schemaURL) |
| 29 |
} |
| 30 |
|
| 31 |
// IDAttributes returns an EntityAttributeMap for managing the entity's id attributes. |
| 32 |
func (e Entity) IDAttributes() EntityAttributeMap { |
| 33 |
return EntityAttributeMap{ |
| 34 |
keys: e.ref.IdKeys(), |
| 35 |
attributes: e.attributes, |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
// DescriptionAttributes returns an EntityAttributeMap for managing the entity's description attributes. |
| 40 |
func (e Entity) DescriptionAttributes() EntityAttributeMap { |
| 41 |
return EntityAttributeMap{ |
| 42 |
keys: e.ref.DescriptionKeys(), |
| 43 |
attributes: e.attributes, |
| 44 |
} |
| 45 |
} |