mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
Introduce `Entity`, `EntitySlice`, and `EntityAttributeMap` types that provide a user-friendly interface for working with resource entities. The new API ensures consistency between entity and resource attributes by sharing the underlying attribute map, and prevents attribute conflicts between entities. This API should eventually replace the generated protobuf-based API for better usability. Resolves https://github.com/open-telemetry/opentelemetry-collector/issues/14042
39 lines
843 B
Go
39 lines
843 B
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package entity
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
|
)
|
|
|
|
func TestResourceEntityRefs(t *testing.T) {
|
|
res := pcommon.NewResource()
|
|
refs := ResourceEntityRefs(res)
|
|
assert.Equal(t, 0, refs.Len())
|
|
|
|
ref := refs.AppendEmpty()
|
|
ref.SetType("service")
|
|
|
|
assert.Equal(t, 1, refs.Len())
|
|
assert.Equal(t, "service", refs.At(0).Type())
|
|
}
|
|
|
|
func TestResourceEntities(t *testing.T) {
|
|
res := pcommon.NewResource()
|
|
entities := ResourceEntities(res)
|
|
assert.Equal(t, 0, entities.Len())
|
|
|
|
e := entities.PutEmpty("service")
|
|
|
|
assert.Equal(t, 1, entities.Len())
|
|
retrieved, ok := entities.Get("service")
|
|
assert.True(t, ok)
|
|
assert.Equal(t, "service", retrieved.Type())
|
|
assert.Equal(t, "service", e.Type())
|
|
}
|