From 36f51385ff9d2a8e46928e919cf90ad119072d0a Mon Sep 17 00:00:00 2001 From: thinkerou Date: Fri, 28 Jun 2019 12:26:16 +0800 Subject: [PATCH] update type style (#29) --- api/core/core.go | 138 ++++++++++++++++--------------- api/event/event.go | 16 ++-- api/metric/api.go | 25 +++--- api/metric/common.go | 28 +++---- api/metric/gauge.go | 16 ++-- api/metric/registry.go | 20 ++--- api/scope/scope.go | 30 ++++--- api/stats/stats.go | 16 ++-- api/tag/api.go | 20 ++--- api/tag/map.go | 12 ++- api/tag/tag.go | 22 +++-- api/trace/api.go | 140 ++++++++++++++++---------------- api/trace/noop_trace.go | 12 ++- api/unit/unit.go | 4 +- exporter/buffer/buffer.go | 16 ++-- exporter/observer/observer.go | 68 ++++++++-------- exporter/reader/reader.go | 122 ++++++++++++++-------------- exporter/spandata/spandata.go | 22 +++-- exporter/spanlog/spanlog.go | 4 +- exporter/stderr/stderr.go | 4 +- exporter/stdout/stdout.go | 4 +- plugin/httptrace/clienttrace.go | 24 +++--- plugin/httptrace/httptrace.go | 11 +-- 23 files changed, 362 insertions(+), 412 deletions(-) diff --git a/api/core/core.go b/api/core/core.go index 0fa0bd002f7..0a258324290 100644 --- a/api/core/core.go +++ b/api/core/core.go @@ -24,98 +24,96 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/unit" ) -type ( - ScopeID struct { - EventID - SpanContext - } +type ScopeID struct { + EventID + SpanContext +} - SpanContext struct { - TraceIDHigh uint64 - TraceIDLow uint64 - SpanID uint64 - } +type SpanContext struct { + TraceIDHigh uint64 + TraceIDLow uint64 + SpanID uint64 +} - EventID uint64 +type EventID uint64 - BaseMeasure interface { - Name() string - Description() string - Unit() unit.Unit +type BaseMeasure interface { + Name() string + Description() string + Unit() unit.Unit - DefinitionID() EventID - } + DefinitionID() EventID +} - Measure interface { - BaseMeasure +type Measure interface { + BaseMeasure - M(float64) Measurement - V(float64) KeyValue - } + M(float64) Measurement + V(float64) KeyValue +} - 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 - } +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 { - BaseMeasure +type Key interface { + BaseMeasure - Value(ctx context.Context) KeyValue + Value(ctx context.Context) KeyValue - Bool(v bool) KeyValue + Bool(v bool) KeyValue - Int(v int) KeyValue - Int32(v int32) KeyValue - Int64(v int64) KeyValue + Int(v int) KeyValue + Int32(v int32) KeyValue + Int64(v int64) KeyValue - Uint(v uint) KeyValue - Uint32(v uint32) KeyValue - Uint64(v uint64) KeyValue + Uint(v uint) KeyValue + Uint32(v uint32) KeyValue + Uint64(v uint64) KeyValue - Float32(v float32) KeyValue - Float64(v float64) KeyValue + Float32(v float32) KeyValue + Float64(v float64) KeyValue - String(v string) KeyValue - Bytes(v []byte) KeyValue - } + String(v string) KeyValue + Bytes(v []byte) KeyValue +} - KeyValue struct { - Key Key - Value Value - } +type KeyValue struct { + Key Key + Value Value +} - ValueType int +type ValueType int - Value struct { - Type ValueType - Bool bool - Int64 int64 - Uint64 uint64 - Float64 float64 - String string - Bytes []byte +type Value struct { + Type ValueType + Bool bool + Int64 int64 + Uint64 uint64 + Float64 float64 + String string + Bytes []byte - // TODO Lazy value type? - } + // TODO Lazy value type? +} - MutatorOp int +type MutatorOp int - Mutator struct { - MutatorOp - KeyValue - MeasureMetadata - } +type Mutator struct { + MutatorOp + KeyValue + MeasureMetadata +} - MeasureMetadata struct { - MaxHops int // -1 == infinite, 0 == do not propagate +type MeasureMetadata struct { + MaxHops int // -1 == infinite, 0 == do not propagate - // TODO time to live? - } -) + // TODO time to live? +} const ( INVALID ValueType = iota diff --git a/api/event/event.go b/api/event/event.go index f6a519290d3..523ab4cf545 100644 --- a/api/event/event.go +++ b/api/event/event.go @@ -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 + // Message interface retrieves message string of the Event. + Message() string - // Attributes interface returns a copy of attributes associated with the Event. - Attributes() []core.KeyValue - } -) + // Attributes interface returns a copy of attributes associated with the Event. + Attributes() []core.KeyValue +} diff --git a/api/metric/api.go b/api/metric/api.go index e52fb38941b..ab82bb5303b 100644 --- a/api/metric/api.go +++ b/api/metric/api.go @@ -20,21 +20,18 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/unit" ) -type ( - Metric interface { - Measure() core.Measure +type Metric interface { + Measure() core.Measure - DefinitionID() core.EventID + DefinitionID() core.EventID - Type() MetricType - Fields() []core.Key - Err() error + Type() MetricType + Fields() []core.Key + Err() error - base() *baseMetric - } - - MetricType int -) + base() *baseMetric +} +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 { diff --git a/api/metric/common.go b/api/metric/common.go index 7e1b78f2bf5..f7ef45b4d49 100644 --- a/api/metric/common.go +++ b/api/metric/common.go @@ -21,22 +21,20 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - baseMetric struct { - measure core.Measure - - mtype MetricType - keys []core.Key - eventID core.EventID - status error // Indicates registry conflict - } +type baseMetric struct { + measure core.Measure - baseEntry struct { - base *baseMetric - metric Metric - eventID core.EventID - } -) + mtype MetricType + keys []core.Key + eventID core.EventID + status error // Indicates registry conflict +} + +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 diff --git a/api/metric/gauge.go b/api/metric/gauge.go index 59236c89faa..291021bc74e 100644 --- a/api/metric/gauge.go +++ b/api/metric/gauge.go @@ -21,15 +21,13 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/stats" ) -type ( - Float64Gauge struct { - baseMetric - } - - Float64Entry struct { - baseEntry - } -) +type Float64Gauge struct { + baseMetric +} + +type Float64Entry struct { + baseEntry +} func NewFloat64Gauge(name string, mos ...Option) *Float64Gauge { m := initBaseMetric(name, GaugeFloat64, mos, &Float64Gauge{}).(*Float64Gauge) diff --git a/api/metric/registry.go b/api/metric/registry.go index d67a061ba7e..ec1e5e09b0d 100644 --- a/api/metric/registry.go +++ b/api/metric/registry.go @@ -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 { - RegisterMetric(Metric) (Metric, error) - ForeachMetric(func(string, Metric)) - } +// 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 { - nameType sync.Map // map[string]Metric - } -) +type registry struct { + nameType sync.Map // map[string]Metric +} var ( registryLock sync.Mutex diff --git a/api/scope/scope.go b/api/scope/scope.go index 9f975e8c325..208d0939c0b 100644 --- a/api/scope/scope.go +++ b/api/scope/scope.go @@ -21,27 +21,25 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - Scope interface { - ScopeID() core.ScopeID - } +type Scope interface { + ScopeID() core.ScopeID +} - Mutable interface { - Scope +type Mutable interface { + Scope - SetAttribute(core.KeyValue) - SetAttributes(...core.KeyValue) + SetAttribute(core.KeyValue) + SetAttributes(...core.KeyValue) - ModifyAttribute(core.Mutator) - ModifyAttributes(...core.Mutator) - } + ModifyAttribute(core.Mutator) + ModifyAttributes(...core.Mutator) +} - scopeIdent struct { - id core.ScopeID - } +type scopeIdent struct { + id core.ScopeID +} - scopeKeyType struct{} -) +type scopeKeyType struct{} var ( scopeKey = &scopeKeyType{} diff --git a/api/stats/stats.go b/api/stats/stats.go index 16f208d7e43..2213f2a2393 100644 --- a/api/stats/stats.go +++ b/api/stats/stats.go @@ -22,16 +22,14 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - Interface interface { - Record(ctx context.Context, m ...core.Measurement) - RecordSingle(ctx context.Context, m core.Measurement) - } +type Interface interface { + Record(ctx context.Context, m ...core.Measurement) + RecordSingle(ctx context.Context, m core.Measurement) +} - Recorder struct { - core.ScopeID - } -) +type Recorder struct { + core.ScopeID +} func With(scope scope.Scope) Recorder { return Recorder{scope.ScopeID()} diff --git a/api/tag/api.go b/api/tag/api.go index ae0a3516382..76cd2b359d0 100644 --- a/api/tag/api.go +++ b/api/tag/api.go @@ -21,21 +21,19 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/unit" ) -type ( - Map interface { - // TODO combine these four into a struct - Apply(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map +type Map interface { + // TODO combine these four into a struct + Apply(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map - Value(core.Key) (core.Value, bool) - HasValue(core.Key) bool + Value(core.Key) (core.Value, bool) + HasValue(core.Key) bool - Len() int + Len() int - Foreach(func(kv core.KeyValue) bool) - } + Foreach(func(kv core.KeyValue) bool) +} - Option func(*registeredKey) -) +type Option func(*registeredKey) var ( EmptyMap = NewMap(core.KeyValue{}, nil, core.Mutator{}, nil) diff --git a/api/tag/map.go b/api/tag/map.go index 4f57ae29cfa..3bbef1dc2c3 100644 --- a/api/tag/map.go +++ b/api/tag/map.go @@ -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 { - value core.Value - meta core.MeasureMetadata - } -) +type tagContent struct { + value core.Value + meta core.MeasureMetadata +} func (m tagMap) HasValue(k core.Key) bool { _, has := m.Value(k) diff --git a/api/tag/tag.go b/api/tag/tag.go index b521d965713..beef4782981 100644 --- a/api/tag/tag.go +++ b/api/tag/tag.go @@ -23,20 +23,18 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - registeredKey struct { - name string - desc string - unit unit.Unit - eventID core.EventID - } +type registeredKey struct { + name string + desc string + unit unit.Unit + eventID core.EventID +} - ctxTagsType struct{} +type ctxTagsType struct{} - measure struct { - rk *registeredKey - } -) +type measure struct { + rk *registeredKey +} var ( ctxTagsKey = &ctxTagsType{} diff --git a/api/trace/api.go b/api/trace/api.go index 809c5b8c9f6..d697239f487 100644 --- a/api/trace/api.go +++ b/api/trace/api.go @@ -28,90 +28,88 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/tag" ) -type ( - Tracer interface { - Start(context.Context, string, ...SpanOption) (context.Context, Span) - - // WithSpan wraps the execution of the function body with a span. - // It starts a new span and sets it as an active span in the context. - // It then executes the body. It closes the span before returning the execution result. - // TODO: Should it restore the previous span? - WithSpan( - ctx context.Context, - operation string, - body func(ctx context.Context) error, - ) error - - // TODO: Do we need WithService and WithComponent? - WithService(name string) Tracer - WithComponent(name string) Tracer - - // WithResources attaches resource attributes to the Tracer. - WithResources(res ...core.KeyValue) Tracer - - // Note: see https://github.com/opentracing/opentracing-go/issues/127 - Inject(context.Context, Span, Injector) - - // ScopeID returns the resource scope of this tracer. - scope.Scope - } +type Tracer interface { + Start(context.Context, string, ...SpanOption) (context.Context, Span) + + // WithSpan wraps the execution of the function body with a span. + // It starts a new span and sets it as an active span in the context. + // It then executes the body. It closes the span before returning the execution result. + // TODO: Should it restore the previous span? + WithSpan( + ctx context.Context, + operation string, + body func(ctx context.Context) error, + ) error + + // TODO: Do we need WithService and WithComponent? + WithService(name string) Tracer + WithComponent(name string) Tracer + + // WithResources attaches resource attributes to the Tracer. + WithResources(res ...core.KeyValue) Tracer + + // Note: see https://github.com/opentracing/opentracing-go/issues/127 + Inject(context.Context, Span, Injector) + + // ScopeID returns the resource scope of this tracer. + scope.Scope +} - Span interface { - scope.Mutable +type Span interface { + scope.Mutable - stats.Interface + stats.Interface - // Tracer returns tracer used to create this span. Tracer cannot be nil. - Tracer() Tracer + // Tracer returns tracer used to create this span. Tracer cannot be nil. + Tracer() Tracer - // Finish completes the span. No updates are allowed to span after it - // finishes. The only exception is setting status of the span. - Finish() + // Finish completes the span. No updates are allowed to span after it + // finishes. The only exception is setting status of the span. + Finish() - // AddEvent adds an event to the span. - AddEvent(ctx context.Context, event event.Event) + // AddEvent adds an event to the span. + AddEvent(ctx context.Context, event event.Event) - // IsRecordingEvents returns true if the span is active and recording events is enabled. - IsRecordingEvents() bool + // IsRecordingEvents returns true if the span is active and recording events is enabled. + IsRecordingEvents() bool - // SpancContext returns span context of the span. Return SpanContext is usable - // even after the span is finished. - SpanContext() core.SpanContext + // SpancContext returns span context of the span. Return SpanContext is usable + // even after the span is finished. + SpanContext() core.SpanContext - // SetStatus sets the status of the span. The status of the span can be updated - // even after span is finished. - SetStatus(codes.Code) - } + // 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 { - // 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) - } +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 { - Attributes []core.KeyValue - StartTime time.Time - Reference Reference - RecordEvent bool - } +// 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 { - core.SpanContext - RelationshipType - } +// 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 diff --git a/api/trace/noop_trace.go b/api/trace/noop_trace.go index 21426f31a0e..29bc5b5789c 100644 --- a/api/trace/noop_trace.go +++ b/api/trace/noop_trace.go @@ -21,14 +21,12 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/scope" ) -type ( - noopSpan struct { - } +type noopSpan struct { +} - noopTracer struct { - resources core.EventID - } -) +type noopTracer struct { + resources core.EventID +} var _ Tracer = (*noopTracer)(nil) diff --git a/api/unit/unit.go b/api/unit/unit.go index 260cd239e76..3266e383a45 100644 --- a/api/unit/unit.go +++ b/api/unit/unit.go @@ -14,9 +14,7 @@ package unit -type ( - Unit string -) +type Unit string const ( Dimensionless Unit = "1" diff --git a/exporter/buffer/buffer.go b/exporter/buffer/buffer.go index 5c06966646f..b9c32a710e2 100644 --- a/exporter/buffer/buffer.go +++ b/exporter/buffer/buffer.go @@ -21,15 +21,13 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - Buffer struct { - observers []observer.Observer - events chan observer.Event - dropped uint64 - wait sync.WaitGroup - close chan 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{ diff --git a/exporter/observer/observer.go b/exporter/observer/observer.go index 7a93e37b235..ef99afdba1f 100644 --- a/exporter/observer/observer.go +++ b/exporter/observer/observer.go @@ -26,43 +26,41 @@ import ( "github.com/open-telemetry/opentelemetry-go/api/event" ) -type ( - EventType int - - // TODO: this Event is confusing with event.Event. - Event struct { - // Automatic fields - Sequence core.EventID // Auto-filled - Time time.Time // Auto-filled - - // Type, Scope, Context - Type EventType // All events - Scope core.ScopeID // All events - Context context.Context // core.FromContext() and scope.Active() - - // Arguments (type-specific) - Attribute core.KeyValue // SET_ATTRIBUTE - Attributes []core.KeyValue // SET_ATTRIBUTES - Mutator core.Mutator // SET_ATTRIBUTE - Mutators []core.Mutator // SET_ATTRIBUTES - Event event.Event // ADD_EVENT - Recovered interface{} // FINISH_SPAN - Status codes.Code // SET_STATUS - - // Values - String string // START_SPAN, EVENT, ... - Float64 float64 - Parent core.ScopeID // START_SPAN - Stats []core.Measurement - Stat core.Measurement - } +type EventType int + +// TODO: this Event is confusing with event.Event. +type Event struct { + // Automatic fields + Sequence core.EventID // Auto-filled + Time time.Time // Auto-filled + + // Type, Scope, Context + Type EventType // All events + Scope core.ScopeID // All events + Context context.Context // core.FromContext() and scope.Active() + + // Arguments (type-specific) + Attribute core.KeyValue // SET_ATTRIBUTE + Attributes []core.KeyValue // SET_ATTRIBUTES + Mutator core.Mutator // SET_ATTRIBUTE + Mutators []core.Mutator // SET_ATTRIBUTES + Event event.Event // ADD_EVENT + Recovered interface{} // FINISH_SPAN + Status codes.Code // SET_STATUS + + // Values + String string // START_SPAN, EVENT, ... + Float64 float64 + Parent core.ScopeID // START_SPAN + Stats []core.Measurement + Stat core.Measurement +} - Observer interface { - Observe(data Event) - } +type Observer interface { + Observe(data Event) +} - observersMap map[Observer]struct{} -) +type observersMap map[Observer]struct{} //go:generate stringer -type=EventType const ( diff --git a/exporter/reader/reader.go b/exporter/reader/reader.go index ecc3a2fae9b..1e96ebb3b86 100644 --- a/exporter/reader/reader.go +++ b/exporter/reader/reader.go @@ -30,79 +30,77 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/observer" ) -type ( - Reader interface { - Read(Event) - } +type Reader interface { + Read(Event) +} - EventType int - - Event struct { - Type EventType - Time time.Time - Sequence core.EventID - SpanContext core.SpanContext - Tags tag.Map - Attributes tag.Map - Event event.Event - Stats []Measurement - - Parent core.SpanContext - ParentAttributes tag.Map - - Duration time.Duration - Name string - Message string - Status codes.Code - } +type EventType int + +type Event struct { + Type EventType + Time time.Time + Sequence core.EventID + SpanContext core.SpanContext + Tags tag.Map + Attributes tag.Map + Event event.Event + Stats []Measurement + + Parent core.SpanContext + ParentAttributes tag.Map + + Duration time.Duration + Name string + Message string + Status codes.Code +} - Measurement struct { - Measure core.Measure - Value float64 - Tags tag.Map - } +type Measurement struct { + Measure core.Measure + Value float64 + Tags tag.Map +} - readerObserver struct { - readers []Reader +type readerObserver struct { + readers []Reader - // core.EventID -> *readerSpan or *readerScope - scopes sync.Map + // core.EventID -> *readerSpan or *readerScope + scopes sync.Map - // core.EventID -> *readerMeasure - measures sync.Map + // core.EventID -> *readerMeasure + measures sync.Map - // core.EventID -> *readerMetric - metrics sync.Map - } + // core.EventID -> *readerMetric + metrics sync.Map +} - readerSpan struct { - name string - start time.Time - startTags tag.Map - spanContext core.SpanContext - status codes.Code +type readerSpan struct { + name string + start time.Time + startTags tag.Map + spanContext core.SpanContext + status codes.Code - *readerScope - } + *readerScope +} - readerMeasure struct { - name string - desc string - unit unit.Unit - } +type readerMeasure struct { + name string + desc string + unit unit.Unit +} - readerMetric struct { - *readerMeasure - mtype metric.MetricType - fields []core.Measure - } +type readerMetric struct { + *readerMeasure + mtype metric.MetricType + fields []core.Measure +} - readerScope struct { - span *readerSpan - parent core.EventID - attributes tag.Map - } -) +type readerScope struct { + span *readerSpan + parent core.EventID + attributes tag.Map +} const ( INVALID EventType = iota diff --git a/exporter/spandata/spandata.go b/exporter/spandata/spandata.go index 5a88d3966e7..52c7f68021e 100644 --- a/exporter/spandata/spandata.go +++ b/exporter/spandata/spandata.go @@ -20,20 +20,18 @@ import ( "github.com/open-telemetry/opentelemetry-go/exporter/reader" ) -type ( - Reader interface { - Read(*Span) - } +type Reader interface { + Read(*Span) +} - Span struct { - Events []reader.Event - } +type Span struct { + Events []reader.Event +} - spanReader struct { - spans map[core.SpanContext]*Span - readers []Reader - } -) +type spanReader struct { + spans map[core.SpanContext]*Span + readers []Reader +} func NewReaderObserver(readers ...Reader) observer.Observer { return reader.NewReaderObserver(&spanReader{ diff --git a/exporter/spanlog/spanlog.go b/exporter/spanlog/spanlog.go index e005c4e59b8..bd3eac7712e 100644 --- a/exporter/spanlog/spanlog.go +++ b/exporter/spanlog/spanlog.go @@ -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{})) diff --git a/exporter/stderr/stderr.go b/exporter/stderr/stderr.go index 3a291ecbd2a..8c5f28656a8 100644 --- a/exporter/stderr/stderr.go +++ b/exporter/stderr/stderr.go @@ -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{}) diff --git a/exporter/stdout/stdout.go b/exporter/stdout/stdout.go index 37c0c9f2907..bcc0efd3737 100644 --- a/exporter/stdout/stdout.go +++ b/exporter/stdout/stdout.go @@ -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{}) diff --git a/plugin/httptrace/clienttrace.go b/plugin/httptrace/clienttrace.go index bc72d3d19bb..628170c9569 100644 --- a/plugin/httptrace/clienttrace.go +++ b/plugin/httptrace/clienttrace.go @@ -29,19 +29,10 @@ import ( "github.com/open-telemetry/opentelemetry-go/sdk/event" ) -type ( - clientLevel struct { - trace.Span - ident string - } - - clientTracer struct { - context.Context - httptrace.ClientTrace - - levels []clientLevel - } -) +type clientLevel struct { + trace.Span + ident string +} 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, diff --git a/plugin/httptrace/httptrace.go b/plugin/httptrace/httptrace.go index 9cd9c210284..d6014fe95b8 100644 --- a/plugin/httptrace/httptrace.go +++ b/plugin/httptrace/httptrace.go @@ -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