mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-01 22:09:57 +02:00
Drop the registry package (#130)
This is to shrink the PR #100. The only place where the registry.Variable type was used was metrics, so just inline that type into its only user. The use of the registry.Variable type in core.Key was limited to the Name field. The stats package also used the registry.Variable type, but seems that also only the Name field was used and the package is going to be dropped anyway.
This commit is contained in:
parent
0583d26d0b
commit
3362421c9b
@ -3,12 +3,10 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/api/registry"
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
Variable registry.Variable
|
||||
Name string
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
@ -148,7 +146,7 @@ func (k Key) Uint(v uint) KeyValue {
|
||||
}
|
||||
|
||||
func (k Key) Defined() bool {
|
||||
return k.Variable.Defined()
|
||||
return len(k.Name) != 0
|
||||
}
|
||||
|
||||
// TODO make this a lazy one-time conversion.
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"go.opentelemetry.io/api/core"
|
||||
"go.opentelemetry.io/api/registry"
|
||||
)
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
@ -306,15 +305,13 @@ func TestDefined(t *testing.T) {
|
||||
{
|
||||
name: "Key.Defined() returns true when len(v.Name) != 0",
|
||||
k: core.Key{
|
||||
registry.Variable{
|
||||
Name: "foo",
|
||||
},
|
||||
Name: "foo",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Key.Defined() returns false when len(v.Name) == 0",
|
||||
k: core.Key{registry.Variable{}},
|
||||
k: core.Key{},
|
||||
want: false,
|
||||
},
|
||||
} {
|
||||
|
@ -2,22 +2,10 @@ package key
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/api/core"
|
||||
"go.opentelemetry.io/api/registry"
|
||||
)
|
||||
|
||||
type AnyValue struct{}
|
||||
|
||||
func (AnyValue) String() string {
|
||||
return "AnyValue"
|
||||
}
|
||||
|
||||
func New(name string, opts ...registry.Option) core.Key {
|
||||
func New(name string) core.Key {
|
||||
return core.Key{
|
||||
Variable: registry.Register(name, AnyValue{}, opts...),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
WithDescription = registry.WithDescription
|
||||
WithUnit = registry.WithUnit
|
||||
)
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/api/core"
|
||||
"go.opentelemetry.io/api/registry"
|
||||
"go.opentelemetry.io/api/unit"
|
||||
)
|
||||
|
||||
@ -40,31 +39,33 @@ type Float64Gauge interface {
|
||||
}
|
||||
|
||||
type Handle struct {
|
||||
Variable registry.Variable
|
||||
Name string
|
||||
Description string
|
||||
Unit unit.Unit
|
||||
|
||||
Type MetricType
|
||||
Keys []core.Key
|
||||
}
|
||||
|
||||
type Option func(*Handle, *[]registry.Option)
|
||||
type Option func(*Handle)
|
||||
|
||||
// WithDescription applies provided description.
|
||||
func WithDescription(desc string) Option {
|
||||
return func(_ *Handle, to *[]registry.Option) {
|
||||
*to = append(*to, registry.WithDescription(desc))
|
||||
return func(m *Handle) {
|
||||
m.Description = desc
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnit applies provided unit.
|
||||
func WithUnit(unit unit.Unit) Option {
|
||||
return func(_ *Handle, to *[]registry.Option) {
|
||||
*to = append(*to, registry.WithUnit(unit))
|
||||
return func(m *Handle) {
|
||||
m.Unit = unit
|
||||
}
|
||||
}
|
||||
|
||||
// WithKeys applies the provided dimension keys.
|
||||
func WithKeys(keys ...core.Key) Option {
|
||||
return func(m *Handle, _ *[]registry.Option) {
|
||||
return func(m *Handle) {
|
||||
m.Keys = keys
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,11 @@
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/api/registry"
|
||||
)
|
||||
|
||||
func registerMetric(name string, mtype MetricType, opts []Option, metric *Handle) {
|
||||
var varOpts []registry.Option
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(metric, &varOpts)
|
||||
opt(metric)
|
||||
}
|
||||
|
||||
metric.Variable = registry.Register(name, mtype, varOpts...)
|
||||
metric.Name = name
|
||||
metric.Type = mtype
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2019, OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package registry // import "go.opentelemetry.io/api/registry"
|
@ -1,69 +0,0 @@
|
||||
// Copyright 2019, OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package registry
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/api/unit"
|
||||
)
|
||||
|
||||
type Sequence uint64
|
||||
|
||||
type Option func(Variable) Variable
|
||||
|
||||
type Variable struct {
|
||||
Name string
|
||||
Description string
|
||||
Unit unit.Unit
|
||||
Type Type
|
||||
}
|
||||
|
||||
type Type interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
func Register(name string, vtype Type, opts ...Option) Variable {
|
||||
return newVar(name, vtype, opts...)
|
||||
}
|
||||
|
||||
func newVar(name string, vtype Type, opts ...Option) Variable {
|
||||
v := Variable{
|
||||
Name: name,
|
||||
Type: vtype,
|
||||
}
|
||||
for _, o := range opts {
|
||||
v = o(v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Variable) Defined() bool {
|
||||
return len(v.Name) != 0
|
||||
}
|
||||
|
||||
// WithDescription applies the provided description.
|
||||
func WithDescription(desc string) Option {
|
||||
return func(v Variable) Variable {
|
||||
v.Description = desc
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnit applies the provided unit.
|
||||
func WithUnit(unit unit.Unit) Option {
|
||||
return func(v Variable) Variable {
|
||||
v.Unit = unit
|
||||
return v
|
||||
}
|
||||
}
|
@ -19,15 +19,14 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/api/core"
|
||||
"go.opentelemetry.io/api/registry"
|
||||
)
|
||||
|
||||
type MeasureHandle struct {
|
||||
Variable registry.Variable
|
||||
Name string
|
||||
}
|
||||
|
||||
type Measure interface {
|
||||
V() registry.Variable
|
||||
N() string
|
||||
M(value float64) Measurement
|
||||
}
|
||||
|
||||
@ -71,20 +70,9 @@ func RecordSingle(ctx context.Context, m Measurement) {
|
||||
GlobalRecorder().RecordSingle(ctx, m)
|
||||
}
|
||||
|
||||
type AnyStatistic struct{}
|
||||
|
||||
func (AnyStatistic) String() string {
|
||||
return "AnyStatistic"
|
||||
}
|
||||
|
||||
var (
|
||||
WithDescription = registry.WithDescription
|
||||
WithUnit = registry.WithUnit
|
||||
)
|
||||
|
||||
func NewMeasure(name string, opts ...registry.Option) *MeasureHandle {
|
||||
func NewMeasure(name string) *MeasureHandle {
|
||||
return &MeasureHandle{
|
||||
Variable: registry.Register(name, AnyStatistic{}, opts...),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,8 +83,8 @@ func (m *MeasureHandle) M(value float64) Measurement {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MeasureHandle) V() registry.Variable {
|
||||
return m.Variable
|
||||
func (m *MeasureHandle) N() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
func (noopRecorder) Record(ctx context.Context, m ...Measurement) {
|
||||
@ -113,6 +101,6 @@ func (noopMeasure) M(float64) Measurement {
|
||||
return Measurement{}
|
||||
}
|
||||
|
||||
func (noopMeasure) V() registry.Variable {
|
||||
return registry.Variable{}
|
||||
func (noopMeasure) N() string {
|
||||
return ""
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func Do(ctx context.Context, f func(ctx context.Context)) {
|
||||
m := FromContext(ctx)
|
||||
keyvals := make([]string, 0, 2*len(m.m))
|
||||
for k, v := range m.m {
|
||||
keyvals = append(keyvals, k.Variable.Name, v.value.Emit())
|
||||
keyvals = append(keyvals, k.Name, v.value.Emit())
|
||||
}
|
||||
pprof.Do(ctx, pprof.Labels(keyvals...), f)
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
|
||||
"go.opentelemetry.io/api/key"
|
||||
"go.opentelemetry.io/api/metric"
|
||||
"go.opentelemetry.io/api/registry"
|
||||
"go.opentelemetry.io/api/stats"
|
||||
"go.opentelemetry.io/api/tag"
|
||||
"go.opentelemetry.io/api/trace"
|
||||
@ -34,9 +33,9 @@ var (
|
||||
|
||||
meter = metric.GlobalMeter() // TODO: should share resources ^^^?
|
||||
|
||||
fooKey = key.New("ex.com/foo", registry.WithDescription("A Foo var"))
|
||||
barKey = key.New("ex.com/bar", registry.WithDescription("A Bar var"))
|
||||
lemonsKey = key.New("ex.com/lemons", registry.WithDescription("A Lemons var"))
|
||||
fooKey = key.New("ex.com/foo")
|
||||
barKey = key.New("ex.com/bar")
|
||||
lemonsKey = key.New("ex.com/lemons")
|
||||
anotherKey = key.New("ex.com/another")
|
||||
|
||||
oneMetric = metric.NewFloat64Gauge("ex.com/one",
|
||||
|
@ -37,7 +37,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
|
||||
if skipIf && data.Attributes.HasValue(kv.Key) {
|
||||
return true
|
||||
}
|
||||
buf.WriteString(" " + kv.Key.Variable.Name + "=" + kv.Value.Emit())
|
||||
buf.WriteString(" " + kv.Key.Name + "=" + kv.Value.Emit())
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
|
||||
buf.WriteString(data.Message)
|
||||
buf.WriteString(" (")
|
||||
data.Attributes.Foreach(func(kv core.KeyValue) bool {
|
||||
buf.WriteString(" " + kv.Key.Variable.Name + "=" + kv.Value.Emit())
|
||||
buf.WriteString(" " + kv.Key.Name + "=" + kv.Value.Emit())
|
||||
return true
|
||||
})
|
||||
buf.WriteString(")")
|
||||
@ -86,7 +86,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
|
||||
|
||||
for _, s := range data.Stats {
|
||||
f(false)(core.Key{
|
||||
Variable: s.Measure.V(),
|
||||
Name: s.Measure.N(),
|
||||
}.Float64(s.Value))
|
||||
|
||||
buf.WriteString(" {")
|
||||
@ -96,7 +96,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
i++
|
||||
buf.WriteString(kv.Key.Variable.Name)
|
||||
buf.WriteString(kv.Key.Name)
|
||||
buf.WriteString("=")
|
||||
buf.WriteString(kv.Value.Emit())
|
||||
return true
|
||||
|
@ -37,9 +37,7 @@ var (
|
||||
ErrorKey = key.New("error")
|
||||
SpanIDKey = key.New("span_id")
|
||||
TraceIDKey = key.New("trace_id")
|
||||
MessageKey = key.New("message",
|
||||
key.WithDescription("message text: info, error, etc"),
|
||||
)
|
||||
MessageKey = key.New("message")
|
||||
)
|
||||
|
||||
func New() trace.Tracer {
|
||||
|
@ -187,7 +187,7 @@ func spanDataToThrift(data *trace.SpanData) *gen.Span {
|
||||
for _, a := range data.MessageEvents {
|
||||
fields := make([]*gen.Tag, 0, len(a.Attributes))
|
||||
for _, kv := range a.Attributes {
|
||||
tag := attributeToTag(kv.Key.Variable.Name, kv.Value.Emit())
|
||||
tag := attributeToTag(kv.Key.Name, kv.Value.Emit())
|
||||
if tag != nil {
|
||||
fields = append(fields, tag)
|
||||
}
|
||||
|
@ -35,9 +35,7 @@ var (
|
||||
HTTPHeaderMIME = key.New("http.mime")
|
||||
HTTPRemoteAddr = key.New("http.remote")
|
||||
HTTPLocalAddr = key.New("http.local")
|
||||
MessageKey = key.New("message",
|
||||
key.WithDescription("message text: info, error, etc"),
|
||||
)
|
||||
MessageKey = key.New("message")
|
||||
)
|
||||
|
||||
type clientTracer struct {
|
||||
|
@ -91,7 +91,7 @@ func (h hinjector) Inject(sc core.SpanContext, tags tag.Map) {
|
||||
// TODO: implement MaxHops
|
||||
tc.TraceState = append(tc.TraceState, tracestate.Member{
|
||||
Vendor: Vendor,
|
||||
Tenant: kv.Key.Variable.Name,
|
||||
Tenant: kv.Key.Name,
|
||||
Value: kv.Value.Emit(),
|
||||
})
|
||||
return true
|
||||
|
@ -227,7 +227,7 @@ func (s *span) lruAttributesToAttributeMap() map[string]interface{} {
|
||||
value, ok := s.lruAttributes.simpleLruMap.Get(key)
|
||||
if ok {
|
||||
key := key.(core.Key)
|
||||
attributes[key.Variable.Name] = value
|
||||
attributes[key.Name] = value
|
||||
}
|
||||
}
|
||||
return attributes
|
||||
|
Loading…
Reference in New Issue
Block a user