You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
update type style (#29)
This commit is contained in:
@@ -24,44 +24,43 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/unit"
|
||||
)
|
||||
|
||||
type (
|
||||
ScopeID struct {
|
||||
type ScopeID struct {
|
||||
EventID
|
||||
SpanContext
|
||||
}
|
||||
}
|
||||
|
||||
SpanContext struct {
|
||||
type SpanContext struct {
|
||||
TraceIDHigh uint64
|
||||
TraceIDLow uint64
|
||||
SpanID uint64
|
||||
}
|
||||
}
|
||||
|
||||
EventID uint64
|
||||
type EventID uint64
|
||||
|
||||
BaseMeasure interface {
|
||||
type BaseMeasure interface {
|
||||
Name() string
|
||||
Description() string
|
||||
Unit() unit.Unit
|
||||
|
||||
DefinitionID() EventID
|
||||
}
|
||||
}
|
||||
|
||||
Measure interface {
|
||||
type Measure interface {
|
||||
BaseMeasure
|
||||
|
||||
M(float64) Measurement
|
||||
V(float64) KeyValue
|
||||
}
|
||||
}
|
||||
|
||||
Measurement struct {
|
||||
type Measurement struct {
|
||||
// NOTE: If we add a ScopeID field this can carry
|
||||
// pre-aggregated measures via the stats.Record API.
|
||||
Measure Measure
|
||||
Value float64
|
||||
ScopeID ScopeID
|
||||
}
|
||||
}
|
||||
|
||||
Key interface {
|
||||
type Key interface {
|
||||
BaseMeasure
|
||||
|
||||
Value(ctx context.Context) KeyValue
|
||||
@@ -81,16 +80,16 @@ type (
|
||||
|
||||
String(v string) KeyValue
|
||||
Bytes(v []byte) KeyValue
|
||||
}
|
||||
}
|
||||
|
||||
KeyValue struct {
|
||||
type KeyValue struct {
|
||||
Key Key
|
||||
Value Value
|
||||
}
|
||||
}
|
||||
|
||||
ValueType int
|
||||
type ValueType int
|
||||
|
||||
Value struct {
|
||||
type Value struct {
|
||||
Type ValueType
|
||||
Bool bool
|
||||
Int64 int64
|
||||
@@ -100,22 +99,21 @@ type (
|
||||
Bytes []byte
|
||||
|
||||
// TODO Lazy value type?
|
||||
}
|
||||
}
|
||||
|
||||
MutatorOp int
|
||||
type MutatorOp int
|
||||
|
||||
Mutator struct {
|
||||
type Mutator struct {
|
||||
MutatorOp
|
||||
KeyValue
|
||||
MeasureMetadata
|
||||
}
|
||||
}
|
||||
|
||||
MeasureMetadata struct {
|
||||
type MeasureMetadata struct {
|
||||
MaxHops int // -1 == infinite, 0 == do not propagate
|
||||
|
||||
// TODO time to live?
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const (
|
||||
INVALID ValueType = iota
|
||||
|
||||
@@ -18,14 +18,12 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/core"
|
||||
)
|
||||
|
||||
type (
|
||||
// Event interface provides methods to retrieve Event properties.
|
||||
Event interface {
|
||||
// Event interface provides methods to retrieve Event properties.
|
||||
type Event interface {
|
||||
|
||||
// Message interface retrieves message string of the Event.
|
||||
Message() string
|
||||
|
||||
// Attributes interface returns a copy of attributes associated with the Event.
|
||||
Attributes() []core.KeyValue
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/unit"
|
||||
)
|
||||
|
||||
type (
|
||||
Metric interface {
|
||||
type Metric interface {
|
||||
Measure() core.Measure
|
||||
|
||||
DefinitionID() core.EventID
|
||||
@@ -31,10 +30,8 @@ type (
|
||||
Err() error
|
||||
|
||||
base() *baseMetric
|
||||
}
|
||||
|
||||
MetricType int
|
||||
)
|
||||
}
|
||||
type MetricType int
|
||||
|
||||
const (
|
||||
Invalid MetricType = iota
|
||||
@@ -48,9 +45,7 @@ const (
|
||||
DerivedCumulativeFloat64
|
||||
)
|
||||
|
||||
type (
|
||||
Option func(*baseMetric, *[]tag.Option)
|
||||
)
|
||||
type Option func(*baseMetric, *[]tag.Option)
|
||||
|
||||
// WithDescription applies provided description.
|
||||
func WithDescription(desc string) Option {
|
||||
|
||||
@@ -21,22 +21,20 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
baseMetric struct {
|
||||
type baseMetric struct {
|
||||
measure core.Measure
|
||||
|
||||
mtype MetricType
|
||||
keys []core.Key
|
||||
eventID core.EventID
|
||||
status error // Indicates registry conflict
|
||||
}
|
||||
}
|
||||
|
||||
baseEntry struct {
|
||||
type baseEntry struct {
|
||||
base *baseMetric
|
||||
metric Metric
|
||||
eventID core.EventID
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func initBaseMetric(name string, mtype MetricType, opts []Option, init Metric) Metric {
|
||||
var tagOpts []tag.Option
|
||||
|
||||
@@ -21,15 +21,13 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/stats"
|
||||
)
|
||||
|
||||
type (
|
||||
Float64Gauge struct {
|
||||
type Float64Gauge struct {
|
||||
baseMetric
|
||||
}
|
||||
}
|
||||
|
||||
Float64Entry struct {
|
||||
type Float64Entry struct {
|
||||
baseEntry
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func NewFloat64Gauge(name string, mos ...Option) *Float64Gauge {
|
||||
m := initBaseMetric(name, GaugeFloat64, mos, &Float64Gauge{}).(*Float64Gauge)
|
||||
|
||||
@@ -33,18 +33,16 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type (
|
||||
// Registry is a mechanism for avoiding duplicate registration
|
||||
// of different-type pre-aggregated metrics (in one process).
|
||||
Registry interface {
|
||||
// Registry is a mechanism for avoiding duplicate registration
|
||||
// of different-type pre-aggregated metrics (in one process).
|
||||
type Registry interface {
|
||||
RegisterMetric(Metric) (Metric, error)
|
||||
ForeachMetric(func(string, Metric))
|
||||
}
|
||||
}
|
||||
|
||||
registry struct {
|
||||
type registry struct {
|
||||
nameType sync.Map // map[string]Metric
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var (
|
||||
registryLock sync.Mutex
|
||||
|
||||
@@ -21,12 +21,11 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
Scope interface {
|
||||
type Scope interface {
|
||||
ScopeID() core.ScopeID
|
||||
}
|
||||
}
|
||||
|
||||
Mutable interface {
|
||||
type Mutable interface {
|
||||
Scope
|
||||
|
||||
SetAttribute(core.KeyValue)
|
||||
@@ -34,14 +33,13 @@ type (
|
||||
|
||||
ModifyAttribute(core.Mutator)
|
||||
ModifyAttributes(...core.Mutator)
|
||||
}
|
||||
}
|
||||
|
||||
scopeIdent struct {
|
||||
type scopeIdent struct {
|
||||
id core.ScopeID
|
||||
}
|
||||
}
|
||||
|
||||
scopeKeyType struct{}
|
||||
)
|
||||
type scopeKeyType struct{}
|
||||
|
||||
var (
|
||||
scopeKey = &scopeKeyType{}
|
||||
|
||||
@@ -22,16 +22,14 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
Interface interface {
|
||||
type Interface interface {
|
||||
Record(ctx context.Context, m ...core.Measurement)
|
||||
RecordSingle(ctx context.Context, m core.Measurement)
|
||||
}
|
||||
}
|
||||
|
||||
Recorder struct {
|
||||
type Recorder struct {
|
||||
core.ScopeID
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func With(scope scope.Scope) Recorder {
|
||||
return Recorder{scope.ScopeID()}
|
||||
|
||||
@@ -21,8 +21,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/unit"
|
||||
)
|
||||
|
||||
type (
|
||||
Map interface {
|
||||
type Map interface {
|
||||
// TODO combine these four into a struct
|
||||
Apply(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map
|
||||
|
||||
@@ -32,10 +31,9 @@ type (
|
||||
Len() int
|
||||
|
||||
Foreach(func(kv core.KeyValue) bool)
|
||||
}
|
||||
}
|
||||
|
||||
Option func(*registeredKey)
|
||||
)
|
||||
type Option func(*registeredKey)
|
||||
|
||||
var (
|
||||
EmptyMap = NewMap(core.KeyValue{}, nil, core.Mutator{}, nil)
|
||||
|
||||
@@ -21,14 +21,12 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/core"
|
||||
)
|
||||
|
||||
type (
|
||||
tagMap map[core.Key]tagContent
|
||||
type tagMap map[core.Key]tagContent
|
||||
|
||||
tagContent struct {
|
||||
type tagContent struct {
|
||||
value core.Value
|
||||
meta core.MeasureMetadata
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func (m tagMap) HasValue(k core.Key) bool {
|
||||
_, has := m.Value(k)
|
||||
|
||||
@@ -23,20 +23,18 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
registeredKey struct {
|
||||
type registeredKey struct {
|
||||
name string
|
||||
desc string
|
||||
unit unit.Unit
|
||||
eventID core.EventID
|
||||
}
|
||||
}
|
||||
|
||||
ctxTagsType struct{}
|
||||
type ctxTagsType struct{}
|
||||
|
||||
measure struct {
|
||||
type measure struct {
|
||||
rk *registeredKey
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var (
|
||||
ctxTagsKey = &ctxTagsType{}
|
||||
|
||||
@@ -28,8 +28,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/tag"
|
||||
)
|
||||
|
||||
type (
|
||||
Tracer interface {
|
||||
type Tracer interface {
|
||||
Start(context.Context, string, ...SpanOption) (context.Context, Span)
|
||||
|
||||
// WithSpan wraps the execution of the function body with a span.
|
||||
@@ -54,9 +53,9 @@ type (
|
||||
|
||||
// ScopeID returns the resource scope of this tracer.
|
||||
scope.Scope
|
||||
}
|
||||
}
|
||||
|
||||
Span interface {
|
||||
type Span interface {
|
||||
scope.Mutable
|
||||
|
||||
stats.Interface
|
||||
@@ -81,37 +80,36 @@ type (
|
||||
// SetStatus sets the status of the span. The status of the span can be updated
|
||||
// even after span is finished.
|
||||
SetStatus(codes.Code)
|
||||
}
|
||||
}
|
||||
|
||||
Injector interface {
|
||||
type Injector interface {
|
||||
// Inject serializes span context and tag.Map and inserts them in to
|
||||
// carrier associated with the injector. For example in case of http request,
|
||||
// span context could added to the request (carrier) as W3C Trace context header.
|
||||
Inject(core.SpanContext, tag.Map)
|
||||
}
|
||||
}
|
||||
|
||||
// SpanOption apply changes to SpanOptions.
|
||||
SpanOption func(*SpanOptions)
|
||||
// SpanOption apply changes to SpanOptions.
|
||||
type SpanOption func(*SpanOptions)
|
||||
|
||||
// SpanOptions provides options to set properties of span at the time of starting
|
||||
// a new span.
|
||||
SpanOptions struct {
|
||||
// SpanOptions provides options to set properties of span at the time of starting
|
||||
// a new span.
|
||||
type SpanOptions struct {
|
||||
Attributes []core.KeyValue
|
||||
StartTime time.Time
|
||||
Reference Reference
|
||||
RecordEvent bool
|
||||
}
|
||||
}
|
||||
|
||||
// Reference is used to establish relationship between newly created span and the
|
||||
// other span. The other span could be related as a parent or linked or any other
|
||||
// future relationship type.
|
||||
Reference struct {
|
||||
// Reference is used to establish relationship between newly created span and the
|
||||
// other span. The other span could be related as a parent or linked or any other
|
||||
// future relationship type.
|
||||
type Reference struct {
|
||||
core.SpanContext
|
||||
RelationshipType
|
||||
}
|
||||
}
|
||||
|
||||
RelationshipType int
|
||||
)
|
||||
type RelationshipType int
|
||||
|
||||
var (
|
||||
// The process global tracer could have process-wide resource
|
||||
|
||||
@@ -21,14 +21,12 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/scope"
|
||||
)
|
||||
|
||||
type (
|
||||
noopSpan struct {
|
||||
}
|
||||
type noopSpan struct {
|
||||
}
|
||||
|
||||
noopTracer struct {
|
||||
type noopTracer struct {
|
||||
resources core.EventID
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var _ Tracer = (*noopTracer)(nil)
|
||||
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
|
||||
package unit
|
||||
|
||||
type (
|
||||
Unit string
|
||||
)
|
||||
type Unit string
|
||||
|
||||
const (
|
||||
Dimensionless Unit = "1"
|
||||
|
||||
@@ -21,15 +21,13 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
Buffer struct {
|
||||
type Buffer struct {
|
||||
observers []observer.Observer
|
||||
events chan observer.Event
|
||||
dropped uint64
|
||||
wait sync.WaitGroup
|
||||
close chan struct{}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func NewBuffer(size int, observers ...observer.Observer) *Buffer {
|
||||
b := &Buffer{
|
||||
|
||||
@@ -26,11 +26,10 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/api/event"
|
||||
)
|
||||
|
||||
type (
|
||||
EventType int
|
||||
type EventType int
|
||||
|
||||
// TODO: this Event is confusing with event.Event.
|
||||
Event struct {
|
||||
// TODO: this Event is confusing with event.Event.
|
||||
type Event struct {
|
||||
// Automatic fields
|
||||
Sequence core.EventID // Auto-filled
|
||||
Time time.Time // Auto-filled
|
||||
@@ -55,14 +54,13 @@ type (
|
||||
Parent core.ScopeID // START_SPAN
|
||||
Stats []core.Measurement
|
||||
Stat core.Measurement
|
||||
}
|
||||
}
|
||||
|
||||
Observer interface {
|
||||
type Observer interface {
|
||||
Observe(data Event)
|
||||
}
|
||||
}
|
||||
|
||||
observersMap map[Observer]struct{}
|
||||
)
|
||||
type observersMap map[Observer]struct{}
|
||||
|
||||
//go:generate stringer -type=EventType
|
||||
const (
|
||||
|
||||
@@ -30,14 +30,13 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
Reader interface {
|
||||
type Reader interface {
|
||||
Read(Event)
|
||||
}
|
||||
}
|
||||
|
||||
EventType int
|
||||
type EventType int
|
||||
|
||||
Event struct {
|
||||
type Event struct {
|
||||
Type EventType
|
||||
Time time.Time
|
||||
Sequence core.EventID
|
||||
@@ -54,15 +53,15 @@ type (
|
||||
Name string
|
||||
Message string
|
||||
Status codes.Code
|
||||
}
|
||||
}
|
||||
|
||||
Measurement struct {
|
||||
type Measurement struct {
|
||||
Measure core.Measure
|
||||
Value float64
|
||||
Tags tag.Map
|
||||
}
|
||||
}
|
||||
|
||||
readerObserver struct {
|
||||
type readerObserver struct {
|
||||
readers []Reader
|
||||
|
||||
// core.EventID -> *readerSpan or *readerScope
|
||||
@@ -73,9 +72,9 @@ type (
|
||||
|
||||
// core.EventID -> *readerMetric
|
||||
metrics sync.Map
|
||||
}
|
||||
}
|
||||
|
||||
readerSpan struct {
|
||||
type readerSpan struct {
|
||||
name string
|
||||
start time.Time
|
||||
startTags tag.Map
|
||||
@@ -83,26 +82,25 @@ type (
|
||||
status codes.Code
|
||||
|
||||
*readerScope
|
||||
}
|
||||
}
|
||||
|
||||
readerMeasure struct {
|
||||
type readerMeasure struct {
|
||||
name string
|
||||
desc string
|
||||
unit unit.Unit
|
||||
}
|
||||
}
|
||||
|
||||
readerMetric struct {
|
||||
type readerMetric struct {
|
||||
*readerMeasure
|
||||
mtype metric.MetricType
|
||||
fields []core.Measure
|
||||
}
|
||||
}
|
||||
|
||||
readerScope struct {
|
||||
type readerScope struct {
|
||||
span *readerSpan
|
||||
parent core.EventID
|
||||
attributes tag.Map
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const (
|
||||
INVALID EventType = iota
|
||||
|
||||
@@ -20,20 +20,18 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/reader"
|
||||
)
|
||||
|
||||
type (
|
||||
Reader interface {
|
||||
type Reader interface {
|
||||
Read(*Span)
|
||||
}
|
||||
}
|
||||
|
||||
Span struct {
|
||||
type Span struct {
|
||||
Events []reader.Event
|
||||
}
|
||||
}
|
||||
|
||||
spanReader struct {
|
||||
type spanReader struct {
|
||||
spans map[core.SpanContext]*Span
|
||||
readers []Reader
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func NewReaderObserver(readers ...Reader) observer.Observer {
|
||||
return reader.NewReaderObserver(&spanReader{
|
||||
|
||||
@@ -24,9 +24,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/spandata/format"
|
||||
)
|
||||
|
||||
type (
|
||||
spanLog struct{}
|
||||
)
|
||||
type spanLog struct{}
|
||||
|
||||
func New() observer.Observer {
|
||||
return buffer.NewBuffer(1000, spandata.NewReaderObserver(&spanLog{}))
|
||||
|
||||
@@ -22,9 +22,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/reader/format"
|
||||
)
|
||||
|
||||
type (
|
||||
stderrLog struct{}
|
||||
)
|
||||
type stderrLog struct{}
|
||||
|
||||
func New() observer.Observer {
|
||||
return reader.NewReaderObserver(&stderrLog{})
|
||||
|
||||
@@ -22,9 +22,7 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/reader/format"
|
||||
)
|
||||
|
||||
type (
|
||||
stdoutLog struct{}
|
||||
)
|
||||
type stdoutLog struct{}
|
||||
|
||||
func New() observer.Observer {
|
||||
return reader.NewReaderObserver(&stdoutLog{})
|
||||
|
||||
@@ -29,19 +29,10 @@ import (
|
||||
"github.com/open-telemetry/opentelemetry-go/sdk/event"
|
||||
)
|
||||
|
||||
type (
|
||||
clientLevel struct {
|
||||
type clientLevel struct {
|
||||
trace.Span
|
||||
ident string
|
||||
}
|
||||
|
||||
clientTracer struct {
|
||||
context.Context
|
||||
httptrace.ClientTrace
|
||||
|
||||
levels []clientLevel
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var (
|
||||
HTTPStatus = tag.New("http.status")
|
||||
@@ -53,6 +44,13 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
type clientTracer struct {
|
||||
context.Context
|
||||
httptrace.ClientTrace
|
||||
|
||||
levels []clientLevel
|
||||
}
|
||||
|
||||
func newClientTracer(ctx context.Context) *clientTracer {
|
||||
ct := &clientTracer{
|
||||
Context: ctx,
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"encoding/binary"
|
||||
"net/http"
|
||||
|
||||
"github.com/lightstep/tracecontext.go"
|
||||
"github.com/lightstep/tracecontext.go/tracestate"
|
||||
|
||||
"github.com/open-telemetry/opentelemetry-go/api/core"
|
||||
@@ -29,12 +28,6 @@ const (
|
||||
Vendor = "ot"
|
||||
)
|
||||
|
||||
type (
|
||||
hinjector struct {
|
||||
*http.Request
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
HostKey = tag.New("http.host")
|
||||
URLKey = tag.New("http.url")
|
||||
@@ -74,6 +67,10 @@ func Extract(req *http.Request) ([]core.KeyValue, []core.KeyValue, core.SpanCont
|
||||
return attrs, tags, sc
|
||||
}
|
||||
|
||||
type hinjector struct {
|
||||
*http.Request
|
||||
}
|
||||
|
||||
func (h hinjector) Inject(sc core.SpanContext, tags tag.Map) {
|
||||
var tc tracecontext.TraceContext
|
||||
var sid [8]byte
|
||||
|
||||
Reference in New Issue
Block a user