Skip to content

Commit

Permalink
Add OC to OTLP translation functions
Browse files Browse the repository at this point in the history
This implements OC to OTLP protobuf message translation.
The code is currently reachable only from the tests.

We probably need a bit more coverage for this code but I am
submitting this change as is for the sake of keeping the
size of the PR managable for reviewing.

Contributes to #478
  • Loading branch information
Tigran Najaryan committed Feb 14, 2020
1 parent 2b71dbb commit d6c6e25
Show file tree
Hide file tree
Showing 9 changed files with 983 additions and 20 deletions.
8 changes: 6 additions & 2 deletions consumer/consumerdata/consumerdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ type TraceData struct {
// OTLPTraceData is a struct that groups proto spans with a resource. This is the
// newer version of TraceData, using OTLP-based representation.
type OTLPTraceData struct {
ResourceSpanList []*otlptrace.ResourceSpans
resourceSpanList []*otlptrace.ResourceSpans
}

func NewOTLPTraceData(resourceSpanList []*otlptrace.ResourceSpans) OTLPTraceData {
return OTLPTraceData{resourceSpanList}
}

// SpanCount calculates the total number of spans.
func (td OTLPTraceData) SpanCount() int {
spanCount := 0
for _, rsl := range td.ResourceSpanList {
for _, rsl := range td.resourceSpanList {
spanCount += len(rsl.Spans)
}
return spanCount
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/tracehelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func checkRecordedMetricsForOTLPTraceExporter(t *testing.T, te exporter.OTLPTrac
defer doneFn()

spans := make([]*otlptrace.Span, 2)
td := consumerdata.OTLPTraceData{ResourceSpanList: []*otlptrace.ResourceSpans{{Spans: spans}}}
td := consumerdata.NewOTLPTraceData([]*otlptrace.ResourceSpans{{Spans: spans}})
ctx := observability.ContextWithReceiverName(context.Background(), fakeTraceReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
Expand All @@ -361,7 +361,7 @@ func checkRecordedMetricsForOTLPTraceExporter(t *testing.T, te exporter.OTLPTrac
}

func generateOTLPTraceTraffic(t *testing.T, te exporter.OTLPTraceExporter, numRequests int, wantError error) {
td := consumerdata.OTLPTraceData{ResourceSpanList: []*otlptrace.ResourceSpans{{Spans: []*otlptrace.Span{{}}}}}
td := consumerdata.NewOTLPTraceData([]*otlptrace.ResourceSpans{{Spans: []*otlptrace.Span{{}}}})
ctx, span := trace.StartSpan(context.Background(), fakeTraceParentSpanName, trace.WithSampler(trace.AlwaysSample()))
defer span.End()
for i := 0; i < numRequests; i++ {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/jaegertracing/jaeger v1.14.0
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024
github.com/mitchellh/mapstructure v1.1.2
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200206071824-8310c432e51c
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200211051721-ff5f19c6217d
github.com/openzipkin/zipkin-go v0.2.1
github.com/orijtech/prometheus-go-metrics-exporter v0.0.3-0.20190313163149-b321c5297f60
github.com/pavius/impi v0.0.0-20180302134524-c1cbdcb8df2b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200206071824-8310c432e51c h1:nDOtl6j2Ei16tlnx/o4qKEelpHtGoZ9ArwU+tux4Ia8=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200206071824-8310c432e51c/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200211051721-ff5f19c6217d h1:hZcHR0at6tb3jBjaPHlfLr6yK7rTrA8xGCS6jlUSLcU=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200211051721-ff5f19c6217d/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
7 changes: 7 additions & 0 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ func TimeToTimestamp(t time.Time) *timestamp.Timestamp {
Nanos: int32(nanoTime % 1e9),
}
}

func TimestampToTime(ts *timestamp.Timestamp) (t time.Time) {
if ts == nil {
return
}
return time.Unix(ts.Seconds, int64(ts.Nanos))
}
2 changes: 2 additions & 0 deletions testbed/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200206071824-8310c432e51c h1:nDOtl6j2Ei16tlnx/o4qKEelpHtGoZ9ArwU+tux4Ia8=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200206071824-8310c432e51c/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200211051721-ff5f19c6217d h1:hZcHR0at6tb3jBjaPHlfLr6yK7rTrA8xGCS6jlUSLcU=
github.com/open-telemetry/opentelemetry-proto v0.0.0-20200211051721-ff5f19c6217d/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
Loading

0 comments on commit d6c6e25

Please sign in to comment.