Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RO/RW span interfaces #1360

Merged
merged 10 commits into from
Dec 11, 2020
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/master' into johananl-johananl…
…/span-interfaces
  • Loading branch information
MrAlias committed Dec 11, 2020
commit 2b663668c496a46e5d45dd0b894f2132c1e51cb9
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- `trace.WithIDGenerator()` `TracerProviderOption`. (#1363)
- Add the `ReadOnlySpan` and `ReadWriteSpan` interfaces to provide better control for accessing span data. (#1360)

### Changed

- Zipkin exporter relies on the status code for success rather than body read but still read the response body. (#1328)
- Move the OpenCensus example into `example` directory. (#1359)
- Moved the SDK's `internal.IDGenerator` interface in to the `sdk/trace` package to enable support for externally-defined ID generators. (#1363)
- `NewExporter` and `Start` functions in `go.opentelemetry.io/otel/exporters/otlp` now receive `context.Context` as a first parameter. (#1357)
Expand All @@ -25,6 +27,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Remove `errUninitializedSpan` as its only usage is now obsolete. (#1360)

### Fixed

- Metric SDK `SumObserver` and `UpDownSumObserver` instruments correctness fixes. (#1381)

## [0.14.0] - 2020-11-19

### Added
Expand Down
10 changes: 7 additions & 3 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package trace // import "go.opentelemetry.io/otel/sdk/trace"

import (
"context"
"fmt"
"reflect"
"sync"
Expand Down Expand Up @@ -466,16 +467,19 @@ func (s *span) addChild() {
s.mu.Unlock()
}

func startSpanInternal(tr *tracer, name string, parent trace.SpanContext, remoteParent bool, o *trace.SpanConfig) *span {
func startSpanInternal(ctx context.Context, tr *tracer, name string, parent trace.SpanContext, remoteParent bool, o *trace.SpanConfig) *span {
span := &span{}
span.spanContext = parent

cfg := tr.provider.config.Load().(*Config)

if parent == emptySpanContext {
span.spanContext.TraceID = cfg.IDGenerator.NewTraceID()
// Generate both TraceID and SpanID
span.spanContext.TraceID, span.spanContext.SpanID = cfg.IDGenerator.NewIDs(ctx)
} else {
// TraceID already exists, just generate a SpanID
span.spanContext.SpanID = cfg.IDGenerator.NewSpanID(ctx, parent.TraceID)
}
span.spanContext.SpanID = cfg.IDGenerator.NewSpanID()

span.attributes = newAttributesMap(cfg.MaxAttributesPerSpan)
span.messageEvents = newEvictedQueue(cfg.MaxEventsPerSpan)
Expand Down
15 changes: 9 additions & 6 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,17 +1275,19 @@ func TestReadOnlySpan(t *testing.T) {
tr := tp.Tracer("ReadOnlySpan", trace.WithInstrumentationVersion("3"))

// Initialize parent context.
tID, sID := cfg.IDGenerator.NewIDs(context.Background())
parent := trace.SpanContext{
TraceID: cfg.IDGenerator.NewTraceID(),
SpanID: cfg.IDGenerator.NewSpanID(),
TraceID: tID,
SpanID: sID,
TraceFlags: 0x1,
}
ctx := trace.ContextWithRemoteSpanContext(context.Background(), parent)

// Initialize linked context.
tID, sID = cfg.IDGenerator.NewIDs(context.Background())
linked := trace.SpanContext{
TraceID: cfg.IDGenerator.NewTraceID(),
SpanID: cfg.IDGenerator.NewSpanID(),
TraceID: tID,
SpanID: sID,
TraceFlags: 0x1,
}

Expand Down Expand Up @@ -1353,9 +1355,10 @@ func TestReadWriteSpan(t *testing.T) {
tr := tp.Tracer("ReadWriteSpan")

// Initialize parent context.
tID, sID := cfg.IDGenerator.NewIDs(context.Background())
parent := trace.SpanContext{
TraceID: cfg.IDGenerator.NewTraceID(),
SpanID: cfg.IDGenerator.NewSpanID(),
TraceID: tID,
SpanID: sID,
TraceFlags: 0x1,
}
ctx := trace.ContextWithRemoteSpanContext(context.Background(), parent)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.