Skip to content

Commit

Permalink
Eliminate Scope/ScopeID, separate API from SDK for metrics/stats (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#48)

* Move scope.Active to trace.CurrentSpan

* Remove scope / does not build

* Global tracer

* Checkpoint

* Checkpoint

* Add key/key.go for key.New

* Comments

* Remove more EventID and ScopeID

* Use Handle to describe static objects

* TODOs

* Remove empty file

* Remove singletons

* Update TODOs

* TODO about map update

* Make stats package option aliases (like key has)

* Rename experimental/streaming

* streaming SDK builds w/ many TODOs

* Get the examples building

* Tidy up metric API / add interface check

* Remove logic from the registry; this is now a placeholder
  • Loading branch information
jmacd authored and rghetia committed Jul 11, 2019
1 parent 50f16dd commit 9611216
Show file tree
Hide file tree
Showing 49 changed files with 829 additions and 1,075 deletions.
153 changes: 0 additions & 153 deletions api/core/core.go

This file was deleted.

171 changes: 171 additions & 0 deletions api/core/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package core

import (
"fmt"
"unsafe"

"github.com/open-telemetry/opentelemetry-go/api/registry"
)

type Key struct {
Variable registry.Variable
}

type KeyValue struct {
Key Key
Value Value
}

type ValueType int

type Value struct {
Type ValueType
Bool bool
Int64 int64
Uint64 uint64
Float64 float64
String string
Bytes []byte

// TODO Lazy value type?
}

const (
INVALID ValueType = iota
BOOL
INT32
INT64
UINT32
UINT64
FLOAT32
FLOAT64
STRING
BYTES
)

func (k Key) Bool(v bool) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: BOOL,
Bool: v,
},
}
}

func (k Key) Int64(v int64) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: INT64,
Int64: v,
},
}
}

func (k Key) Uint64(v uint64) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: UINT64,
Uint64: v,
},
}
}

func (k Key) Float64(v float64) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: FLOAT64,
Float64: v,
},
}
}

func (k Key) Int32(v int32) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: INT32,
Int64: int64(v),
},
}
}

func (k Key) Uint32(v uint32) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: UINT32,
Uint64: uint64(v),
},
}
}

func (k Key) Float32(v float32) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: FLOAT32,
Float64: float64(v),
},
}
}

func (k Key) String(v string) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: STRING,
String: v,
},
}
}

func (k Key) Bytes(v []byte) KeyValue {
return KeyValue{
Key: k,
Value: Value{
Type: BYTES,
Bytes: v,
},
}
}

func (k Key) Int(v int) KeyValue {
if unsafe.Sizeof(v) == 4 {
return k.Int32(int32(v))
}
return k.Int64(int64(v))
}

func (k Key) Uint(v uint) KeyValue {
if unsafe.Sizeof(v) == 4 {
return k.Uint32(uint32(v))
}
return k.Uint64(uint64(v))
}

func (k Key) Defined() bool {
return k.Variable.Defined()
}

// TODO make this a lazy one-time conversion.
func (v Value) Emit() string {
switch v.Type {
case BOOL:
return fmt.Sprint(v.Bool)
case INT32, INT64:
return fmt.Sprint(v.Int64)
case UINT32, UINT64:
return fmt.Sprint(v.Uint64)
case FLOAT32, FLOAT64:
return fmt.Sprint(v.Float64)
case STRING:
return v.String
case BYTES:
return string(v.Bytes)
}
return "unknown"
}
19 changes: 0 additions & 19 deletions api/core/span_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"fmt"
)

type EventID uint64

type TraceID struct {
High uint64
Low uint64
Expand All @@ -30,17 +28,6 @@ type SpanContext struct {
SpanID uint64
}

type ScopeID struct {
EventID
SpanContext
}

func (e EventID) Scope() ScopeID {
return ScopeID{
EventID: e,
}
}

var (
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
// conditions.
Expand All @@ -65,9 +52,3 @@ func (sc SpanContext) TraceIDString() string {
p2 := fmt.Sprintf("%.16x", sc.TraceID.Low)
return p1[0:3] + ".." + p2[13:16]
}

func (s SpanContext) Scope() ScopeID {
return ScopeID{
SpanContext: s,
}
}
23 changes: 23 additions & 0 deletions api/key/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package key

import (
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/registry"
)

type AnyValue struct{}

func (AnyValue) String() string {
return "AnyValue"
}

func New(name string, opts ...registry.Option) core.Key {
return core.Key{
Variable: registry.Register(name, AnyValue{}, opts...),
}
}

var (
WithDescription = registry.WithDescription
WithUnit = registry.WithUnit
)
Loading

0 comments on commit 9611216

Please sign in to comment.