You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
move Apply method to map.go and check interface implement (#30)
* move Apply method to map.go * Update map.go
This commit is contained in:
@@ -54,30 +54,6 @@ func NewMap(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutat
|
||||
return t.Apply(a1, attributes, m1, mutators)
|
||||
}
|
||||
|
||||
func (input tagMap) Apply(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map {
|
||||
m := make(tagMap, len(input)+len(attributes)+len(mutators))
|
||||
for k, v := range input {
|
||||
m[k] = v
|
||||
}
|
||||
if a1.Key != nil {
|
||||
m[a1.Key] = tagContent{
|
||||
value: a1.Value,
|
||||
}
|
||||
}
|
||||
for _, kv := range attributes {
|
||||
m[kv.Key] = tagContent{
|
||||
value: kv.Value,
|
||||
}
|
||||
}
|
||||
if m1.KeyValue.Key != nil {
|
||||
m.apply(m1)
|
||||
}
|
||||
for _, mutator := range mutators {
|
||||
m.apply(mutator)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func WithMap(ctx context.Context, m Map) context.Context {
|
||||
return context.WithValue(ctx, ctxTagsKey, m)
|
||||
}
|
||||
|
||||
+44
-18
@@ -28,9 +28,28 @@ type tagContent struct {
|
||||
meta core.MeasureMetadata
|
||||
}
|
||||
|
||||
func (m tagMap) HasValue(k core.Key) bool {
|
||||
_, has := m.Value(k)
|
||||
return has
|
||||
func (t tagMap) Apply(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map {
|
||||
m := make(tagMap, len(t)+len(attributes)+len(mutators))
|
||||
for k, v := range t {
|
||||
m[k] = v
|
||||
}
|
||||
if a1.Key != nil {
|
||||
m[a1.Key] = tagContent{
|
||||
value: a1.Value,
|
||||
}
|
||||
}
|
||||
for _, kv := range attributes {
|
||||
m[kv.Key] = tagContent{
|
||||
value: kv.Value,
|
||||
}
|
||||
}
|
||||
if m1.KeyValue.Key != nil {
|
||||
m.apply(m1)
|
||||
}
|
||||
for _, mutator := range mutators {
|
||||
m.apply(mutator)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m tagMap) Value(k core.Key) (core.Value, bool) {
|
||||
@@ -41,6 +60,28 @@ func (m tagMap) Value(k core.Key) (core.Value, bool) {
|
||||
return entry.value, ok
|
||||
}
|
||||
|
||||
func (m tagMap) HasValue(k core.Key) bool {
|
||||
_, has := m.Value(k)
|
||||
return has
|
||||
}
|
||||
|
||||
func (m tagMap) Len() int {
|
||||
return len(m)
|
||||
}
|
||||
|
||||
func (m tagMap) Foreach(f func(kv core.KeyValue) bool) {
|
||||
for k, v := range m {
|
||||
if !f(core.KeyValue{
|
||||
Key: k,
|
||||
Value: v.value,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _ Map = (*tagMap)(nil)
|
||||
|
||||
func (m tagMap) apply(mutator core.Mutator) {
|
||||
if m == nil {
|
||||
return
|
||||
@@ -106,18 +147,3 @@ func Do(ctx context.Context, f func(ctx context.Context)) {
|
||||
}
|
||||
pprof.Do(ctx, pprof.Labels(keyvals...), f)
|
||||
}
|
||||
|
||||
func (m tagMap) Foreach(f func(kv core.KeyValue) bool) {
|
||||
for k, v := range m {
|
||||
if !f(core.KeyValue{
|
||||
Key: k,
|
||||
Value: v.value,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m tagMap) Len() int {
|
||||
return len(m)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user