-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
scope.go
43 lines (33 loc) · 884 Bytes
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package identity // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics/identity"
import (
"hash"
"go.opentelemetry.io/collector/pdata/pcommon"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil"
)
type scope = Scope
type Scope struct {
resource resource
name string
version string
attrs [16]byte
}
func (s Scope) Hash() hash.Hash64 {
sum := s.resource.Hash()
sum.Write([]byte(s.name))
sum.Write([]byte(s.version))
sum.Write(s.attrs[:])
return sum
}
func (s Scope) Resource() Resource {
return s.resource
}
func OfScope(res Resource, scope pcommon.InstrumentationScope) Scope {
return Scope{
resource: res,
name: scope.Name(),
version: scope.Version(),
attrs: pdatautil.MapHash(scope.Attributes()),
}
}