1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-09 13:37:12 +02:00

rename tag package to distributedContext (#178)

* rename package tag to package distributedContext

* rename Tag -> Entry

* change distributed context -> dctx to avoid capitalization collision

* change dctx -> distributedcontext

* update stackdriver client example
This commit is contained in:
Alyson van Hardenberg 2019-10-10 14:30:22 -07:00 committed by rghetia
parent f863bfbd86
commit 384b4bb86a
21 changed files with 126 additions and 126 deletions

View File

@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package tag package distributedcontext
import ( import (
"context" "context"
"runtime/pprof" "runtime/pprof"
) )
type ctxTagsType struct{} type ctxEntriesType struct{}
var ( var (
ctxTagsKey = &ctxTagsType{} ctxEntriesKey = &ctxEntriesType{}
) )
func WithMap(ctx context.Context, m Map) context.Context { func WithMap(ctx context.Context, m Map) context.Context {
return context.WithValue(ctx, ctxTagsKey, m) return context.WithValue(ctx, ctxEntriesKey, m)
} }
func NewContext(ctx context.Context, mutators ...Mutator) context.Context { func NewContext(ctx context.Context, mutators ...Mutator) context.Context {
@ -36,7 +36,7 @@ func NewContext(ctx context.Context, mutators ...Mutator) context.Context {
} }
func FromContext(ctx context.Context) Map { func FromContext(ctx context.Context) Map {
if m, ok := ctx.Value(ctxTagsKey).(Map); ok { if m, ok := ctx.Value(ctxEntriesKey).(Map); ok {
return m return m
} }
return NewEmptyMap() return NewEmptyMap()

View File

@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package tag // import "go.opentelemetry.io/api/tag" package distributedcontext // import "go.opentelemetry.io/api/distributedcontext"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package tag package distributedcontext
import ( import (
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
@ -22,12 +22,12 @@ type MeasureMetadata struct {
TTL int // -1 == infinite, 0 == do not propagate TTL int // -1 == infinite, 0 == do not propagate
} }
type tagContent struct { type entry struct {
value core.Value value core.Value
meta MeasureMetadata meta MeasureMetadata
} }
type rawMap map[core.Key]tagContent type rawMap map[core.Key]entry
type Map struct { type Map struct {
m rawMap m rawMap
@ -60,12 +60,12 @@ func (m Map) Apply(update MapUpdate) Map {
r[k] = v r[k] = v
} }
if update.SingleKV.Key.Defined() { if update.SingleKV.Key.Defined() {
r[update.SingleKV.Key] = tagContent{ r[update.SingleKV.Key] = entry{
value: update.SingleKV.Value, value: update.SingleKV.Value,
} }
} }
for _, kv := range update.MultiKV { for _, kv := range update.MultiKV {
r[kv.Key] = tagContent{ r[kv.Key] = entry{
value: kv.Value, value: kv.Value,
} }
} }
@ -111,7 +111,7 @@ func (m Map) Foreach(f func(kv core.KeyValue) bool) {
func (r rawMap) apply(mutator Mutator) { func (r rawMap) apply(mutator Mutator) {
key := mutator.KeyValue.Key key := mutator.KeyValue.Key
content := tagContent{ content := entry{
value: mutator.KeyValue.Value, value: mutator.KeyValue.Value,
meta: mutator.MeasureMetadata, meta: mutator.MeasureMetadata,
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package tag package distributedcontext
import ( import (
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"

View File

@ -21,7 +21,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
) )
type Tracer interface { type Tracer interface {
@ -90,8 +90,8 @@ type Span interface {
SetAttributes(...core.KeyValue) SetAttributes(...core.KeyValue)
// Modify and delete span attributes // Modify and delete span attributes
ModifyAttribute(tag.Mutator) ModifyAttribute(distributedcontext.Mutator)
ModifyAttributes(...tag.Mutator) ModifyAttributes(...distributedcontext.Mutator)
} }
// SpanOption apply changes to SpanOptions. // SpanOption apply changes to SpanOptions.

View File

@ -8,7 +8,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
) )
@ -89,11 +89,11 @@ func (mockSpan) SetAttributes(attributes ...core.KeyValue) {
} }
// ModifyAttribute does nothing. // ModifyAttribute does nothing.
func (mockSpan) ModifyAttribute(mutator tag.Mutator) { func (mockSpan) ModifyAttribute(mutator distributedcontext.Mutator) {
} }
// ModifyAttributes does nothing. // ModifyAttributes does nothing.
func (mockSpan) ModifyAttributes(mutators ...tag.Mutator) { func (mockSpan) ModifyAttributes(mutators ...distributedcontext.Mutator) {
} }
// End does nothing. // End does nothing.

View File

@ -21,7 +21,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
) )
type NoopSpan struct { type NoopSpan struct {
@ -56,11 +56,11 @@ func (NoopSpan) SetAttributes(attributes ...core.KeyValue) {
} }
// ModifyAttribute does nothing. // ModifyAttribute does nothing.
func (NoopSpan) ModifyAttribute(mutator tag.Mutator) { func (NoopSpan) ModifyAttribute(mutator distributedcontext.Mutator) {
} }
// ModifyAttributes does nothing. // ModifyAttributes does nothing.
func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) { func (NoopSpan) ModifyAttributes(mutators ...distributedcontext.Mutator) {
} }
// End does nothing. // End does nothing.

View File

@ -17,9 +17,9 @@ package main
import ( import (
"context" "context"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/key" "go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/metric" "go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
) )
@ -44,9 +44,9 @@ var (
func main() { func main() {
ctx := context.Background() ctx := context.Background()
ctx = tag.NewContext(ctx, ctx = distributedcontext.NewContext(ctx,
tag.Insert(fooKey.String("foo1")), distributedcontext.Insert(fooKey.String("foo1")),
tag.Insert(barKey.String("bar1")), distributedcontext.Insert(barKey.String("bar1")),
) )
commonLabels := meter.DefineLabels(ctx, lemonsKey.Int(10)) commonLabels := meter.DefineLabels(ctx, lemonsKey.Int(10))
@ -64,9 +64,9 @@ func main() {
gauge.Set(ctx, 1) gauge.Set(ctx, 1)
meter.RecordBatch( meter.RecordBatch(
// Note: call-site variables added as context tags: // Note: call-site variables added as context Entries:
tag.NewContext(ctx, distributedcontext.NewContext(ctx,
tag.Insert(anotherKey.String("xyz"))), distributedcontext.Insert(anotherKey.String("xyz"))),
commonLabels, commonLabels,
oneMetric.Measurement(1.0), oneMetric.Measurement(1.0),

View File

@ -26,8 +26,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/key" "go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/exporter/trace/stackdriver" "go.opentelemetry.io/exporter/trace/stackdriver"
"go.opentelemetry.io/plugin/httptrace" "go.opentelemetry.io/plugin/httptrace"
@ -59,8 +59,8 @@ func main() {
initTracer() initTracer()
client := http.DefaultClient client := http.DefaultClient
ctx := tag.NewContext(context.Background(), ctx := distributedcontext.NewContext(context.Background(),
tag.Insert(key.New("username").String("donuts")), distributedcontext.Insert(key.New("username").String("donuts")),
) )
var body []byte var body []byte

View File

@ -20,7 +20,7 @@ import (
"net/http" "net/http"
"os" "os"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/exporter/trace/stackdriver" "go.opentelemetry.io/exporter/trace/stackdriver"
"go.opentelemetry.io/plugin/httptrace" "go.opentelemetry.io/plugin/httptrace"
@ -53,10 +53,10 @@ func main() {
initTracer() initTracer()
helloHandler := func(w http.ResponseWriter, req *http.Request) { helloHandler := func(w http.ResponseWriter, req *http.Request) {
attrs, tags, spanCtx := httptrace.Extract(req.Context(), req) attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
req = req.WithContext(tag.WithMap(req.Context(), tag.NewMap(tag.MapUpdate{ req = req.WithContext(distributedcontext.WithMap(req.Context(), distributedcontext.NewMap(distributedcontext.MapUpdate{
MultiKV: tags, MultiKV: entries,
}))) })))
ctx, span := trace.GlobalTracer().Start( ctx, span := trace.GlobalTracer().Start(

View File

@ -25,8 +25,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/key" "go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/exporter/trace/stdout" "go.opentelemetry.io/exporter/trace/stdout"
"go.opentelemetry.io/plugin/httptrace" "go.opentelemetry.io/plugin/httptrace"
@ -57,8 +57,8 @@ func main() {
initTracer() initTracer()
client := http.DefaultClient client := http.DefaultClient
ctx := tag.NewContext(context.Background(), ctx := distributedcontext.NewContext(context.Background(),
tag.Insert(key.New("username").String("donuts")), distributedcontext.Insert(key.New("username").String("donuts")),
) )
var body []byte var body []byte

View File

@ -19,7 +19,7 @@ import (
"log" "log"
"net/http" "net/http"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/exporter/trace/stdout" "go.opentelemetry.io/exporter/trace/stdout"
"go.opentelemetry.io/plugin/httptrace" "go.opentelemetry.io/plugin/httptrace"
@ -49,10 +49,10 @@ func main() {
initTracer() initTracer()
helloHandler := func(w http.ResponseWriter, req *http.Request) { helloHandler := func(w http.ResponseWriter, req *http.Request) {
attrs, tags, spanCtx := httptrace.Extract(req.Context(), req) attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
req = req.WithContext(tag.WithMap(req.Context(), tag.NewMap(tag.MapUpdate{ req = req.WithContext(distributedcontext.WithMap(req.Context(), distributedcontext.NewMap(distributedcontext.MapUpdate{
MultiKV: tags, MultiKV: entries,
}))) })))
ctx, span := trace.GlobalTracer().Start( ctx, span := trace.GlobalTracer().Start(

View File

@ -23,8 +23,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
otelcore "go.opentelemetry.io/api/core" otelcore "go.opentelemetry.io/api/core"
oteldctx "go.opentelemetry.io/api/distributedcontext"
otelkey "go.opentelemetry.io/api/key" otelkey "go.opentelemetry.io/api/key"
oteltag "go.opentelemetry.io/api/tag"
oteltrace "go.opentelemetry.io/api/trace" oteltrace "go.opentelemetry.io/api/trace"
migration "go.opentelemetry.io/experimental/bridge/opentracing/migration" migration "go.opentelemetry.io/experimental/bridge/opentracing/migration"
@ -44,7 +44,7 @@ type MockContextKeyValue struct {
} }
type MockTracer struct { type MockTracer struct {
Resources oteltag.Map Resources oteldctx.Map
FinishedSpans []*MockSpan FinishedSpans []*MockSpan
SpareTraceIDs []otelcore.TraceID SpareTraceIDs []otelcore.TraceID
SpareSpanIDs []uint64 SpareSpanIDs []uint64
@ -59,7 +59,7 @@ var _ migration.DeferredContextSetupTracerExtension = &MockTracer{}
func NewMockTracer() *MockTracer { func NewMockTracer() *MockTracer {
return &MockTracer{ return &MockTracer{
Resources: oteltag.NewEmptyMap(), Resources: oteldctx.NewEmptyMap(),
FinishedSpans: nil, FinishedSpans: nil,
SpareTraceIDs: nil, SpareTraceIDs: nil,
SpareSpanIDs: nil, SpareSpanIDs: nil,
@ -107,7 +107,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S
officialTracer: t, officialTracer: t,
spanContext: spanContext, spanContext: spanContext,
recording: spanOpts.RecordEvent, recording: spanOpts.RecordEvent,
Attributes: oteltag.NewMap(upsertMultiMapUpdate(spanOpts.Attributes...)), Attributes: oteldctx.NewMap(upsertMultiMapUpdate(spanOpts.Attributes...)),
StartTime: startTime, StartTime: startTime,
EndTime: time.Time{}, EndTime: time.Time{},
ParentSpanID: t.getParentSpanID(ctx, &spanOpts), ParentSpanID: t.getParentSpanID(ctx, &spanOpts),
@ -201,10 +201,10 @@ func (t *MockTracer) DeferredContextSetupHook(ctx context.Context, span oteltrac
} }
type MockEvent struct { type MockEvent struct {
CtxAttributes oteltag.Map CtxAttributes oteldctx.Map
Timestamp time.Time Timestamp time.Time
Msg string Msg string
Attributes oteltag.Map Attributes oteldctx.Map
} }
type MockSpan struct { type MockSpan struct {
@ -213,7 +213,7 @@ type MockSpan struct {
spanContext otelcore.SpanContext spanContext otelcore.SpanContext
recording bool recording bool
Attributes oteltag.Map Attributes oteldctx.Map
StartTime time.Time StartTime time.Time
EndTime time.Time EndTime time.Time
ParentSpanID uint64 ParentSpanID uint64
@ -251,19 +251,19 @@ func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
s.applyUpdate(upsertMultiMapUpdate(attributes...)) s.applyUpdate(upsertMultiMapUpdate(attributes...))
} }
func (s *MockSpan) ModifyAttribute(mutator oteltag.Mutator) { func (s *MockSpan) ModifyAttribute(mutator oteldctx.Mutator) {
s.applyUpdate(oteltag.MapUpdate{ s.applyUpdate(oteldctx.MapUpdate{
SingleMutator: mutator, SingleMutator: mutator,
}) })
} }
func (s *MockSpan) ModifyAttributes(mutators ...oteltag.Mutator) { func (s *MockSpan) ModifyAttributes(mutators ...oteldctx.Mutator) {
s.applyUpdate(oteltag.MapUpdate{ s.applyUpdate(oteldctx.MapUpdate{
MultiMutator: mutators, MultiMutator: mutators,
}) })
} }
func (s *MockSpan) applyUpdate(update oteltag.MapUpdate) { func (s *MockSpan) applyUpdate(update oteldctx.MapUpdate) {
s.Attributes = s.Attributes.Apply(update) s.Attributes = s.Attributes.Apply(update)
} }
@ -295,10 +295,10 @@ func (s *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...otelcore.K
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...otelcore.KeyValue) { func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...otelcore.KeyValue) {
s.Events = append(s.Events, MockEvent{ s.Events = append(s.Events, MockEvent{
CtxAttributes: oteltag.FromContext(ctx), CtxAttributes: oteldctx.FromContext(ctx),
Timestamp: timestamp, Timestamp: timestamp,
Msg: msg, Msg: msg,
Attributes: oteltag.NewMap(upsertMultiMapUpdate(attrs...)), Attributes: oteldctx.NewMap(upsertMultiMapUpdate(attrs...)),
}) })
} }
@ -314,36 +314,36 @@ func (s *MockSpan) OverrideTracer(tracer oteltrace.Tracer) {
s.officialTracer = tracer s.officialTracer = tracer
} }
func upsertMapUpdate(kv otelcore.KeyValue) oteltag.MapUpdate { func upsertMapUpdate(kv otelcore.KeyValue) oteldctx.MapUpdate {
return singleMutatorMapUpdate(oteltag.UPSERT, kv) return singleMutatorMapUpdate(oteldctx.UPSERT, kv)
} }
func upsertMultiMapUpdate(kvs ...otelcore.KeyValue) oteltag.MapUpdate { func upsertMultiMapUpdate(kvs ...otelcore.KeyValue) oteldctx.MapUpdate {
return multiMutatorMapUpdate(oteltag.UPSERT, kvs...) return multiMutatorMapUpdate(oteldctx.UPSERT, kvs...)
} }
func singleMutatorMapUpdate(op oteltag.MutatorOp, kv otelcore.KeyValue) oteltag.MapUpdate { func singleMutatorMapUpdate(op oteldctx.MutatorOp, kv otelcore.KeyValue) oteldctx.MapUpdate {
return oteltag.MapUpdate{ return oteldctx.MapUpdate{
SingleMutator: keyValueToMutator(op, kv), SingleMutator: keyValueToMutator(op, kv),
} }
} }
func multiMutatorMapUpdate(op oteltag.MutatorOp, kvs ...otelcore.KeyValue) oteltag.MapUpdate { func multiMutatorMapUpdate(op oteldctx.MutatorOp, kvs ...otelcore.KeyValue) oteldctx.MapUpdate {
return oteltag.MapUpdate{ return oteldctx.MapUpdate{
MultiMutator: keyValuesToMutators(op, kvs...), MultiMutator: keyValuesToMutators(op, kvs...),
} }
} }
func keyValuesToMutators(op oteltag.MutatorOp, kvs ...otelcore.KeyValue) []oteltag.Mutator { func keyValuesToMutators(op oteldctx.MutatorOp, kvs ...otelcore.KeyValue) []oteldctx.Mutator {
var mutators []oteltag.Mutator var mutators []oteldctx.Mutator
for _, kv := range kvs { for _, kv := range kvs {
mutators = append(mutators, keyValueToMutator(op, kv)) mutators = append(mutators, keyValueToMutator(op, kv))
} }
return mutators return mutators
} }
func keyValueToMutator(op oteltag.MutatorOp, kv otelcore.KeyValue) oteltag.Mutator { func keyValueToMutator(op oteldctx.MutatorOp, kv otelcore.KeyValue) oteldctx.Mutator {
return oteltag.Mutator{ return oteldctx.Mutator{
MutatorOp: op, MutatorOp: op,
KeyValue: kv, KeyValue: kv,
} }

View File

@ -17,9 +17,9 @@ package main
import ( import (
"context" "context"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/key" "go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/metric" "go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/experimental/streaming/exporter/spanlog" "go.opentelemetry.io/experimental/streaming/exporter/spanlog"
@ -47,9 +47,9 @@ var (
func main() { func main() {
ctx := context.Background() ctx := context.Background()
ctx = tag.NewContext(ctx, ctx = distributedcontext.NewContext(ctx,
tag.Insert(fooKey.String("foo1")), distributedcontext.Insert(fooKey.String("foo1")),
tag.Insert(barKey.String("bar1")), distributedcontext.Insert(barKey.String("bar1")),
) )
commonLabels := meter.DefineLabels(ctx, lemonsKey.Int(10)) commonLabels := meter.DefineLabels(ctx, lemonsKey.Int(10))
@ -67,9 +67,9 @@ func main() {
gauge.Set(ctx, 1) gauge.Set(ctx, 1)
meter.RecordBatch( meter.RecordBatch(
// Note: call-site variables added as context tags: // Note: call-site variables added as context entries:
tag.NewContext(ctx, distributedcontext.NewContext(ctx,
tag.Insert(anotherKey.String("xyz"))), distributedcontext.Insert(anotherKey.String("xyz"))),
commonLabels, commonLabels,
oneMetric.Measurement(1.0), oneMetric.Measurement(1.0),

View File

@ -8,8 +8,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/metric" "go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/tag"
) )
type EventType int type EventType int
@ -32,12 +32,12 @@ type Event struct {
Context context.Context // core.FromContext() and scope.Active() Context context.Context // core.FromContext() and scope.Active()
// Arguments (type-specific) // Arguments (type-specific)
Attribute core.KeyValue // SET_ATTRIBUTE Attribute core.KeyValue // SET_ATTRIBUTE
Attributes []core.KeyValue // SET_ATTRIBUTES Attributes []core.KeyValue // SET_ATTRIBUTES
Mutator tag.Mutator // SET_ATTRIBUTE Mutator distributedcontext.Mutator // SET_ATTRIBUTE
Mutators []tag.Mutator // SET_ATTRIBUTES Mutators []distributedcontext.Mutator // SET_ATTRIBUTES
Recovered interface{} // END_SPAN Recovered interface{} // END_SPAN
Status codes.Code // SET_STATUS Status codes.Code // SET_STATUS
// Values // Values
String string // START_SPAN, EVENT, SET_NAME, ... String string // START_SPAN, EVENT, SET_NAME, ...

View File

@ -19,9 +19,9 @@ import (
"strings" "strings"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/key" "go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/metric" "go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/experimental/streaming/exporter" "go.opentelemetry.io/experimental/streaming/exporter"
"go.opentelemetry.io/experimental/streaming/exporter/reader" "go.opentelemetry.io/experimental/streaming/exporter/reader"
@ -116,13 +116,13 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
buf.WriteString(fmt.Sprintf("WAT? %d", data.Type)) buf.WriteString(fmt.Sprintf("WAT? %d", data.Type))
} }
// Attach the scope (span) attributes and context tags. // Attach the scope (span) attributes and context entries.
buf.WriteString(" [") buf.WriteString(" [")
if data.Attributes.Len() > 0 { if data.Attributes.Len() > 0 {
data.Attributes.Foreach(f(false)) data.Attributes.Foreach(f(false))
} }
if data.Tags.Len() > 0 { if data.Entries.Len() > 0 {
data.Tags.Foreach(f(true)) data.Entries.Foreach(f(true))
} }
if data.SpanContext.HasSpanID() { if data.SpanContext.HasSpanID() {
f(false)(sdk.SpanIDKey.String(data.SpanContext.SpanIDString())) f(false)(sdk.SpanIDKey.String(data.SpanContext.SpanIDString()))
@ -142,7 +142,7 @@ func formatMetricUpdate(buf *strings.Builder, m metric.Measurement) {
buf.WriteString(m.Value.Emit(m.Descriptor.ValueKind())) buf.WriteString(m.Value.Emit(m.Descriptor.ValueKind()))
} }
func formatMetricLabels(buf *strings.Builder, l tag.Map) { func formatMetricLabels(buf *strings.Builder, l distributedcontext.Map) {
buf.WriteString(" {") buf.WriteString(" {")
i := 0 i := 0
l.Foreach(func(kv core.KeyValue) bool { l.Foreach(func(kv core.KeyValue) bool {

View File

@ -22,8 +22,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/metric" "go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/experimental/streaming/exporter" "go.opentelemetry.io/experimental/streaming/exporter"
) )
@ -37,13 +37,13 @@ type Event struct {
Time time.Time Time time.Time
Sequence exporter.EventID Sequence exporter.EventID
SpanContext core.SpanContext SpanContext core.SpanContext
Tags tag.Map // context tags Entries distributedcontext.Map // context entries
Attributes tag.Map // span attributes, metric labels Attributes distributedcontext.Map // span attributes, metric labels
Measurement metric.Measurement Measurement metric.Measurement
Measurements []metric.Measurement Measurements []metric.Measurement
Parent core.SpanContext Parent core.SpanContext
ParentAttributes tag.Map ParentAttributes distributedcontext.Map
Duration time.Duration Duration time.Duration
Name string Name string
@ -59,11 +59,11 @@ type readerObserver struct {
} }
type readerSpan struct { type readerSpan struct {
name string name string
start time.Time start time.Time
startTags tag.Map startEntries distributedcontext.Map
spanContext core.SpanContext spanContext core.SpanContext
status codes.Code status codes.Code
*readerScope *readerScope
} }
@ -71,7 +71,7 @@ type readerSpan struct {
type readerScope struct { type readerScope struct {
span *readerSpan span *readerSpan
parent exporter.EventID parent exporter.EventID
attributes tag.Map attributes distributedcontext.Map
} }
// NewReaderObserver returns an implementation that computes the // NewReaderObserver returns an implementation that computes the
@ -93,23 +93,23 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
read := Event{ read := Event{
Time: event.Time, Time: event.Time,
Sequence: event.Sequence, Sequence: event.Sequence,
Attributes: tag.NewEmptyMap(), Attributes: distributedcontext.NewEmptyMap(),
Tags: tag.NewEmptyMap(), Entries: distributedcontext.NewEmptyMap(),
} }
if event.Context != nil { if event.Context != nil {
read.Tags = tag.FromContext(event.Context) read.Entries = distributedcontext.FromContext(event.Context)
} }
switch event.Type { switch event.Type {
case exporter.START_SPAN: case exporter.START_SPAN:
// Save the span context tags, initial attributes, start time, and name. // Save the span context entries, initial attributes, start time, and name.
span := &readerSpan{ span := &readerSpan{
name: event.String, name: event.String,
start: event.Time, start: event.Time,
startTags: tag.FromContext(event.Context), startEntries: distributedcontext.FromContext(event.Context),
spanContext: event.Scope.SpanContext, spanContext: event.Scope.SpanContext,
readerScope: &readerScope{}, readerScope: &readerScope{},
} }
rattrs, _ := ro.readScope(event.Scope) rattrs, _ := ro.readScope(event.Scope)
@ -150,19 +150,19 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
read.Attributes = attrs read.Attributes = attrs
read.Duration = event.Time.Sub(span.start) read.Duration = event.Time.Sub(span.start)
read.Tags = span.startTags read.Entries = span.startEntries
read.SpanContext = span.spanContext read.SpanContext = span.spanContext
// TODO: recovered // TODO: recovered
case exporter.NEW_SCOPE, exporter.MODIFY_ATTR: case exporter.NEW_SCOPE, exporter.MODIFY_ATTR:
var span *readerSpan var span *readerSpan
var m tag.Map var m distributedcontext.Map
sid := event.Scope sid := event.Scope
if sid.EventID == 0 { if sid.EventID == 0 {
m = tag.NewEmptyMap() m = distributedcontext.NewEmptyMap()
} else { } else {
parentI, has := ro.scopes.Load(sid.EventID) parentI, has := ro.scopes.Load(sid.EventID)
if !has { if !has {
@ -181,7 +181,7 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
span: span, span: span,
parent: sid.EventID, parent: sid.EventID,
attributes: m.Apply( attributes: m.Apply(
tag.MapUpdate{ distributedcontext.MapUpdate{
SingleKV: event.Attribute, SingleKV: event.Attribute,
MultiKV: event.Attributes, MultiKV: event.Attributes,
SingleMutator: event.Mutator, SingleMutator: event.Mutator,
@ -201,7 +201,7 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
if span != nil { if span != nil {
read.SpanContext = span.spanContext read.SpanContext = span.spanContext
read.Tags = span.startTags read.Entries = span.startEntries
} }
case exporter.ADD_EVENT: case exporter.ADD_EVENT:
@ -209,7 +209,7 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
read.Message = event.String read.Message = event.String
attrs, span := ro.readScope(event.Scope) attrs, span := ro.readScope(event.Scope)
read.Attributes = attrs.Apply(tag.MapUpdate{ read.Attributes = attrs.Apply(distributedcontext.MapUpdate{
MultiKV: event.Attributes, MultiKV: event.Attributes,
}) })
if span != nil { if span != nil {
@ -270,9 +270,9 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
} }
} }
func (ro *readerObserver) readScope(id exporter.ScopeID) (tag.Map, *readerSpan) { func (ro *readerObserver) readScope(id exporter.ScopeID) (distributedcontext.Map, *readerSpan) {
if id.EventID == 0 { if id.EventID == 0 {
return tag.NewEmptyMap(), nil return distributedcontext.NewEmptyMap(), nil
} }
ev, has := ro.scopes.Load(id.EventID) ev, has := ro.scopes.Load(id.EventID)
if !has { if !has {
@ -283,7 +283,7 @@ func (ro *readerObserver) readScope(id exporter.ScopeID) (tag.Map, *readerSpan)
} else if sp, ok := ev.(*readerSpan); ok { } else if sp, ok := ev.(*readerSpan); ok {
return sp.attributes, sp return sp.attributes, sp
} }
return tag.NewEmptyMap(), nil return distributedcontext.NewEmptyMap(), nil
} }
func (ro *readerObserver) cleanupSpan(id exporter.EventID) { func (ro *readerObserver) cleanupSpan(id exporter.EventID) {

View File

@ -21,7 +21,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
"go.opentelemetry.io/api/trace" "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/experimental/streaming/exporter" "go.opentelemetry.io/experimental/streaming/exporter"
) )
@ -71,7 +71,7 @@ func (sp *span) SetAttributes(attributes ...core.KeyValue) {
}) })
} }
func (sp *span) ModifyAttribute(mutator tag.Mutator) { func (sp *span) ModifyAttribute(mutator distributedcontext.Mutator) {
sp.sdk.exporter.Record(exporter.Event{ sp.sdk.exporter.Record(exporter.Event{
Type: exporter.MODIFY_ATTR, Type: exporter.MODIFY_ATTR,
Scope: sp.ScopeID(), Scope: sp.ScopeID(),
@ -79,7 +79,7 @@ func (sp *span) ModifyAttribute(mutator tag.Mutator) {
}) })
} }
func (sp *span) ModifyAttributes(mutators ...tag.Mutator) { func (sp *span) ModifyAttributes(mutators ...distributedcontext.Mutator) {
sp.sdk.exporter.Record(exporter.Event{ sp.sdk.exporter.Record(exporter.Event{
Type: exporter.MODIFY_ATTR, Type: exporter.MODIFY_ATTR,
Scope: sp.ScopeID(), Scope: sp.ScopeID(),

View File

@ -21,7 +21,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag" "go.opentelemetry.io/api/distributedcontext"
apitrace "go.opentelemetry.io/api/trace" apitrace "go.opentelemetry.io/api/trace"
) )
@ -64,11 +64,11 @@ func (ms *MockSpan) SetAttributes(attributes ...core.KeyValue) {
} }
// ModifyAttribute does nothing. // ModifyAttribute does nothing.
func (ms *MockSpan) ModifyAttribute(mutator tag.Mutator) { func (ms *MockSpan) ModifyAttribute(mutator distributedcontext.Mutator) {
} }
// ModifyAttributes does nothing. // ModifyAttributes does nothing.
func (ms *MockSpan) ModifyAttributes(mutators ...tag.Mutator) { func (ms *MockSpan) ModifyAttributes(mutators ...distributedcontext.Mutator) {
} }
// End does nothing. // End does nothing.

View File

@ -34,7 +34,7 @@ var (
propagator = propagation.HttpTraceContextPropagator() propagator = propagation.HttpTraceContextPropagator()
) )
// Returns the Attributes, Context Tags, and SpanContext that were encoded by Inject. // Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, core.SpanContext) { func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, core.SpanContext) {
sc := propagator.Extract(ctx, req.Header) sc := propagator.Extract(ctx, req.Header)

View File

@ -22,7 +22,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/api/core" "go.opentelemetry.io/api/core"
apitag "go.opentelemetry.io/api/tag" apidctx "go.opentelemetry.io/api/distributedcontext"
apitrace "go.opentelemetry.io/api/trace" apitrace "go.opentelemetry.io/api/trace"
"go.opentelemetry.io/sdk/export" "go.opentelemetry.io/sdk/export"
"go.opentelemetry.io/sdk/internal" "go.opentelemetry.io/sdk/internal"
@ -100,11 +100,11 @@ func (s *span) SetAttributes(attributes ...core.KeyValue) {
} }
// ModifyAttribute does nothing. // ModifyAttribute does nothing.
func (s *span) ModifyAttribute(mutator apitag.Mutator) { func (s *span) ModifyAttribute(mutator apidctx.Mutator) {
} }
// ModifyAttributes does nothing. // ModifyAttributes does nothing.
func (s *span) ModifyAttributes(mutators ...apitag.Mutator) { func (s *span) ModifyAttributes(mutators ...apidctx.Mutator) {
} }
func (s *span) End(options ...apitrace.EndOption) { func (s *span) End(options ...apitrace.EndOption) {