Skip to content

Commit

Permalink
Merge sdk/export/trace into sdk/trace (#1778)
Browse files Browse the repository at this point in the history
* Merge sdk/export/trace into sdk/trace

* Update package move

* Add changes to changelog

* Add PR number to changelog
  • Loading branch information
MrAlias authored Apr 7, 2021
1 parent c61e654 commit 2817c09
Show file tree
Hide file tree
Showing 32 changed files with 165 additions and 187 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `DroppedAttributeCount` field of the `Span` in the `go.opentelemetry.io/otel` package now only represents the number of attributes dropped for the span itself.
It no longer is a conglomerate of itself, events, and link attributes that have been dropped. (#1771)
- Make `ExportSpans` in Jaeger Exporter honor context deadline. (#1773)
- The `go.opentelemetry.io/otel/sdk/export/trace` package is merged into the `go.opentelemetry.io/otel/sdk/trace` package. (#1778)

### Removed

Expand Down
3 changes: 1 addition & 2 deletions example/opencensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"go.opentelemetry.io/otel/bridge/opencensus"
"go.opentelemetry.io/otel/exporters/stdout"
otmetricexport "go.opentelemetry.io/otel/sdk/export/metric"
ottraceexport "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

Expand Down Expand Up @@ -63,7 +62,7 @@ func main() {

// tracing demonstrates overriding the OpenCensus DefaultTracer to send spans
// to the OpenTelemetry exporter by calling OpenCensus APIs.
func tracing(otExporter ottraceexport.SpanExporter) {
func tracing(otExporter sdktrace.SpanExporter) {
ctx := context.Background()

log.Println("Configuring OpenCensus. Not Registering any OpenCensus exporters.")
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/internal/otlptest/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -80,8 +80,8 @@ func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelect

// SingleSpanSnapshot returns a one-element slice with a snapshot. It
// may be useful for testing driver's trace export.
func SingleSpanSnapshot() []*exporttrace.SpanSnapshot {
sd := &exporttrace.SpanSnapshot{
func SingleSpanSnapshot() []*tracesdk.SpanSnapshot {
sd := &tracesdk.SpanSnapshot{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID{2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9},
SpanID: trace.SpanID{3, 4, 5, 6, 7, 8, 9, 0},
Expand Down Expand Up @@ -111,7 +111,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot {
Version: "0.0.0",
},
}
return []*exporttrace.SpanSnapshot{sd}
return []*tracesdk.SpanSnapshot{sd}
}

// EmptyCheckpointSet is a checkpointer that has no records at all.
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/internal/transform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"go.opentelemetry.io/otel/codes"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"

export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -30,7 +30,7 @@ const (

// SpanData transforms a slice of SpanSnapshot into a slice of OTLP
// ResourceSpans.
func SpanData(sdl []*export.SpanSnapshot) []*tracepb.ResourceSpans {
func SpanData(sdl []*tracesdk.SpanSnapshot) []*tracepb.ResourceSpans {
if len(sdl) == 0 {
return nil
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func SpanData(sdl []*export.SpanSnapshot) []*tracepb.ResourceSpans {
}

// span transforms a Span into an OTLP span.
func span(sd *export.SpanSnapshot) *tracepb.Span {
func span(sd *tracesdk.SpanSnapshot) *tracepb.Span {
if sd == nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions exporters/otlp/internal/transform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"

"go.opentelemetry.io/otel/codes"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)

func TestSpanKind(t *testing.T) {
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestSpanData(t *testing.T) {
startTime := time.Unix(1585674086, 1234)
endTime := startTime.Add(10 * time.Second)
traceState, _ := trace.TraceStateFromKeyValues(attribute.String("key1", "val1"), attribute.String("key2", "val2"))
spanData := &export.SpanSnapshot{
spanData := &tracesdk.SpanSnapshot{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestSpanData(t *testing.T) {
DroppedLinksCount: 3,
}

got := SpanData([]*export.SpanSnapshot{spanData})
got := SpanData([]*tracesdk.SpanSnapshot{spanData})
require.Len(t, got, 1)

assert.Equal(t, got[0].GetResource(), Resource(spanData.Resource))
Expand All @@ -302,7 +302,7 @@ func TestSpanData(t *testing.T) {

// Empty parent span ID should be treated as root span.
func TestRootSpanData(t *testing.T) {
sd := SpanData([]*export.SpanSnapshot{{}})
sd := SpanData([]*tracesdk.SpanSnapshot{{}})
require.Len(t, sd, 1)
rs := sd[0]
got := rs.GetInstrumentationLibrarySpans()[0].GetSpans()[0].GetParentSpanId()
Expand All @@ -312,5 +312,5 @@ func TestRootSpanData(t *testing.T) {
}

func TestSpanDataNilResource(t *testing.T) {
assert.NotPanics(t, func() { SpanData([]*export.SpanSnapshot{{}}) })
assert.NotPanics(t, func() { SpanData([]*tracesdk.SpanSnapshot{{}}) })
}
11 changes: 4 additions & 7 deletions exporters/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/otel/metric"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)

// Exporter is an OpenTelemetry exporter. It exports both traces and metrics
Expand Down Expand Up @@ -111,8 +111,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

// Export implements the "go.opentelemetry.io/otel/sdk/export/metric".Exporter
// interface. It transforms and batches metric Records into OTLP Metrics and
// Export transforms and batches metric Records into OTLP Metrics and
// transmits them to the configured collector.
func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) error {
return e.driver.ExportMetrics(parent, cps, e.cfg.exportKindSelector)
Expand All @@ -124,10 +123,8 @@ func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind)
return e.cfg.exportKindSelector.ExportKindFor(desc, kind)
}

// ExportSpans implements the
// "go.opentelemetry.io/otel/sdk/export/trace".SpanExporter interface. It
// transforms and batches trace SpanSnapshots into OTLP Trace and transmits them
// to the configured collector.
// ExportSpans transforms and batches trace SpanSnapshots into OTLP Trace and
// transmits them to the configured collector.
func (e *Exporter) ExportSpans(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
return e.driver.ExportTraces(ctx, ss)
}
2 changes: 1 addition & 1 deletion exporters/otlp/otlp_span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"

tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)

func TestExportSpans(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpgrpc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
Expand Down
15 changes: 7 additions & 8 deletions exporters/otlp/otlpgrpc/otlp_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/internal/otlptest"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
)
Expand Down Expand Up @@ -161,7 +160,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnectsWhenInRestMode(t *test
// trigger almost immediate reconnection
require.Error(
t,
exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "in the midst"}}),
exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "in the midst"}}),
"transport: Error while dialing dial tcp %s: connect: connection refused",
mc.endpoint,
)
Expand All @@ -173,7 +172,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnectsWhenInRestMode(t *test
// send message to disconnected channel but this time reconnection gouroutine will be in (rest mode, not listening to the disconnected channel)
require.Error(
t,
exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "in the midst"}}),
exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "in the midst"}}),
"transport: Error while dialing dial tcp %s: connect: connection refused2",
mc.endpoint,
)
Expand All @@ -191,7 +190,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnectsWhenInRestMode(t *test
for i := 0; i < n; i++ {
// when disconnected exp.ExportSpans doesnt send disconnected messages again
// it just quits and return last connection error
require.NoError(t, exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "Resurrected"}}))
require.NoError(t, exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "Resurrected"}}))
}

nmaSpans := nmc.getSpans()
Expand Down Expand Up @@ -231,7 +230,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnects(t *testing.T) {
// No endpoint up.
require.Error(
t,
exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "in the midst"}}),
exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "in the midst"}}),
"transport: Error while dialing dial tcp %s: connect: connection refused",
mc.endpoint,
)
Expand All @@ -245,7 +244,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnects(t *testing.T) {

n := 10
for i := 0; i < n; i++ {
require.NoError(t, exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "Resurrected"}}))
require.NoError(t, exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "Resurrected"}}))
}

nmaSpans := nmc.getSpans()
Expand Down Expand Up @@ -305,7 +304,7 @@ func TestNewExporter_withHeaders(t *testing.T) {
ctx := context.Background()
exp := newGRPCExporter(t, ctx, mc.endpoint,
otlpgrpc.WithHeaders(map[string]string{"header1": "value1"}))
require.NoError(t, exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "in the midst"}}))
require.NoError(t, exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "in the midst"}}))

defer func() {
_ = exp.Shutdown(ctx)
Expand All @@ -329,7 +328,7 @@ func TestNewExporter_withInvalidSecurityConfiguration(t *testing.T) {
t.Fatalf("failed to create a new collector exporter: %v", err)
}

err = exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "misconfiguration"}})
err = exp.ExportSpans(ctx, []*sdktrace.SpanSnapshot{{Name: "misconfiguration"}})
require.Equal(t, err.Error(), "exporter disconnected: grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)")

defer func() {
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlphttp/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
colmetricspb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/protocoldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"sync"

metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)

// ProtocolDriver is an interface used by OTLP exporter. It's
Expand Down
5 changes: 2 additions & 3 deletions exporters/stdout/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/export/metric"
exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
Expand All @@ -34,8 +33,8 @@ type Exporter struct {
}

var (
_ metric.Exporter = &Exporter{}
_ exporttrace.SpanExporter = &Exporter{}
_ metric.Exporter = &Exporter{}
_ sdktrace.SpanExporter = &Exporter{}
)

// NewExporter creates an Exporter with the passed options.
Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"sync"

"go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/trace"
)

// Exporter is an implementation of trace.SpanSyncer that writes spans to stdout.
Expand Down
6 changes: 3 additions & 3 deletions exporters/stdout/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/stdout"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -47,7 +47,7 @@ func TestExporter_ExportSpan(t *testing.T) {
doubleValue := 123.456
resource := resource.NewWithAttributes(attribute.String("rk1", "rv11"))

testSpan := &export.SpanSnapshot{
testSpan := &tracesdk.SpanSnapshot{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
Expand All @@ -69,7 +69,7 @@ func TestExporter_ExportSpan(t *testing.T) {
StatusMessage: "interesting",
Resource: resource,
}
if err := ex.ExportSpans(context.Background(), []*export.SpanSnapshot{testSpan}); err != nil {
if err := ex.ExportSpans(context.Background(), []*tracesdk.SpanSnapshot{testSpan}); err != nil {
t.Fatal(err)
}

Expand Down
15 changes: 7 additions & 8 deletions exporters/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger"
export "go.opentelemetry.io/otel/sdk/export/trace"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv"
Expand Down Expand Up @@ -121,8 +120,8 @@ func NewRawExporter(endpointOption EndpointOption, opts ...Option) (*Exporter, e
o: o,
defaultServiceName: defaultServiceName,
}
bundler := bundler.NewBundler((*export.SpanSnapshot)(nil), func(bundle interface{}) {
if err := e.upload(bundle.([]*export.SpanSnapshot)); err != nil {
bundler := bundler.NewBundler((*sdktrace.SpanSnapshot)(nil), func(bundle interface{}) {
if err := e.upload(bundle.([]*sdktrace.SpanSnapshot)); err != nil {
otel.Handle(err)
}
})
Expand Down Expand Up @@ -200,10 +199,10 @@ type Exporter struct {
defaultServiceName string
}

var _ export.SpanExporter = (*Exporter)(nil)
var _ sdktrace.SpanExporter = (*Exporter)(nil)

// ExportSpans exports SpanSnapshots to Jaeger.
func (e *Exporter) ExportSpans(ctx context.Context, ss []*export.SpanSnapshot) error {
func (e *Exporter) ExportSpans(ctx context.Context, ss []*sdktrace.SpanSnapshot) error {
e.stoppedMu.RLock()
stopped := e.stopped
e.stoppedMu.RUnlock()
Expand Down Expand Up @@ -258,7 +257,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return nil
}

func spanSnapshotToThrift(ss *export.SpanSnapshot) *gen.Span {
func spanSnapshotToThrift(ss *sdktrace.SpanSnapshot) *gen.Span {
tags := make([]*gen.Tag, 0, len(ss.Attributes))
for _, kv := range ss.Attributes {
tag := keyValueToTag(kv)
Expand Down Expand Up @@ -425,7 +424,7 @@ func (e *Exporter) Flush() {
flush(e)
}

func (e *Exporter) upload(spans []*export.SpanSnapshot) error {
func (e *Exporter) upload(spans []*sdktrace.SpanSnapshot) error {
batchList := jaegerBatchList(spans, e.defaultServiceName)
for _, batch := range batchList {
err := e.uploader.upload(batch)
Expand All @@ -439,7 +438,7 @@ func (e *Exporter) upload(spans []*export.SpanSnapshot) error {

// jaegerBatchList transforms a slice of SpanSnapshot into a slice of jaeger
// Batch.
func jaegerBatchList(ssl []*export.SpanSnapshot, defaultServiceName string) []*gen.Batch {
func jaegerBatchList(ssl []*sdktrace.SpanSnapshot, defaultServiceName string) []*gen.Batch {
if len(ssl) == 0 {
return nil
}
Expand Down
Loading

0 comments on commit 2817c09

Please sign in to comment.