Skip to content

Commit 940b8c2

Browse files
Move BigEndian helper functions in tracetranslator to an internal package (#3298)
* Move BigEndian helper functions in to an internal package * revert changelog * update changelog * Change to idutils and add doc.go * Update internal/idutils/doc.go Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
1 parent 1a1bad8 commit 940b8c2

File tree

13 files changed

+58
-31
lines changed

13 files changed

+58
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Remove unused logstest package (#3222)
88
- Introduce `AppSettings` instead of `Parameters` (#3163)
9+
- Move BigEndian helper functions in `tracetranslator` to an internal package.(#3298)
910

1011
## 💡 Enhancements 💡
1112

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package tracetranslator
15+
package idutils
1616

1717
import (
1818
"encoding/binary"

translator/trace/big_endian_converter_test.go renamed to internal/idutils/big_endian_converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package tracetranslator
15+
package idutils
1616

1717
import (
1818
"math"

internal/idutils/doc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package idutils provides a set of helper functions to convert ids.
16+
//
17+
// Functions in big_endian_converter.go help converting uint64 ids to TraceID
18+
// and SpanID using big endian, and vice versa.
19+
package idutils // import "go.opentelemetry.io/collector/internal/idutils"

processor/probabilisticsamplerprocessor/probabilisticsampler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
"go.opentelemetry.io/collector/consumer"
2828
"go.opentelemetry.io/collector/consumer/consumertest"
2929
"go.opentelemetry.io/collector/consumer/pdata"
30+
idutils "go.opentelemetry.io/collector/internal/idutils"
3031
"go.opentelemetry.io/collector/translator/conventions"
31-
tracetranslator "go.opentelemetry.io/collector/translator/trace"
3232
)
3333

3434
func TestNewTracesProcessor(t *testing.T) {
@@ -437,7 +437,7 @@ func Test_hash(t *testing.T) {
437437
// collisions, but, of course it is possible that they happen, a different random source
438438
// should avoid that.
439439
r := rand.New(rand.NewSource(1))
440-
fullKey := tracetranslator.UInt64ToTraceID(r.Uint64(), r.Uint64()).Bytes()
440+
fullKey := idutils.UInt64ToTraceID(r.Uint64(), r.Uint64()).Bytes()
441441
seen := make(map[uint32]bool)
442442
for i := 1; i <= len(fullKey); i++ {
443443
key := fullKey[:i]
@@ -467,8 +467,8 @@ func genRandomTestData(numBatches, numTracesPerBatch int, serviceName string, re
467467

468468
for k := 0; k < numTracesPerBatch; k++ {
469469
span := ils.Spans().At(k)
470-
span.SetTraceID(tracetranslator.UInt64ToTraceID(r.Uint64(), r.Uint64()))
471-
span.SetSpanID(tracetranslator.UInt64ToSpanID(r.Uint64()))
470+
span.SetTraceID(idutils.UInt64ToTraceID(r.Uint64(), r.Uint64()))
471+
span.SetSpanID(idutils.UInt64ToSpanID(r.Uint64()))
472472
attributes := make(map[string]pdata.AttributeValue)
473473
attributes[conventions.AttributeHTTPStatusCode] = pdata.NewAttributeValueInt(404)
474474
attributes[conventions.AttributeHTTPStatusText] = pdata.NewAttributeValueString("Not Found")

translator/trace/jaeger/jaegerproto_to_traces.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"
2626

2727
"go.opentelemetry.io/collector/consumer/pdata"
28+
idutils "go.opentelemetry.io/collector/internal/idutils"
2829
"go.opentelemetry.io/collector/internal/occonventions"
2930
"go.opentelemetry.io/collector/translator/conventions"
3031
tracetranslator "go.opentelemetry.io/collector/translator/trace"
@@ -164,15 +165,15 @@ type instrumentationLibrary struct {
164165

165166
func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) {
166167
dest := pdata.NewSpan()
167-
dest.SetTraceID(tracetranslator.UInt64ToTraceID(span.TraceID.High, span.TraceID.Low))
168-
dest.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(span.SpanID)))
168+
dest.SetTraceID(idutils.UInt64ToTraceID(span.TraceID.High, span.TraceID.Low))
169+
dest.SetSpanID(idutils.UInt64ToSpanID(uint64(span.SpanID)))
169170
dest.SetName(span.OperationName)
170171
dest.SetStartTimestamp(pdata.TimestampFromTime(span.StartTime))
171172
dest.SetEndTimestamp(pdata.TimestampFromTime(span.StartTime.Add(span.Duration)))
172173

173174
parentSpanID := span.ParentSpanID()
174175
if parentSpanID != model.SpanID(0) {
175-
dest.SetParentSpanID(tracetranslator.UInt64ToSpanID(uint64(parentSpanID)))
176+
dest.SetParentSpanID(idutils.UInt64ToSpanID(uint64(parentSpanID)))
176177
}
177178

178179
attrs := dest.Attributes()
@@ -357,8 +358,8 @@ func jReferencesToSpanLinks(refs []model.SpanRef, excludeParentID model.SpanID,
357358
continue
358359
}
359360

360-
link.SetTraceID(tracetranslator.UInt64ToTraceID(ref.TraceID.High, ref.TraceID.Low))
361-
link.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(ref.SpanID)))
361+
link.SetTraceID(idutils.UInt64ToTraceID(ref.TraceID.High, ref.TraceID.Low))
362+
link.SetSpanID(idutils.UInt64ToSpanID(uint64(ref.SpanID)))
362363
i++
363364
}
364365

translator/trace/jaeger/jaegerproto_to_traces_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/stretchr/testify/require"
2727

2828
"go.opentelemetry.io/collector/consumer/pdata"
29+
idutils "go.opentelemetry.io/collector/internal/idutils"
2930
"go.opentelemetry.io/collector/internal/testdata"
3031
"go.opentelemetry.io/collector/translator/conventions"
3132
tracetranslator "go.opentelemetry.io/collector/translator/trace"
@@ -843,8 +844,8 @@ func generateTraceDataTwoSpansFromTwoLibraries() pdata.Traces {
843844
rs0ils0.InstrumentationLibrary().SetName("library1")
844845
rs0ils0.InstrumentationLibrary().SetVersion("0.42.0")
845846
span1 := rs0ils0.Spans().AppendEmpty()
846-
span1.SetTraceID(tracetranslator.UInt64ToTraceID(0, 0))
847-
span1.SetSpanID(tracetranslator.UInt64ToSpanID(0))
847+
span1.SetTraceID(idutils.UInt64ToTraceID(0, 0))
848+
span1.SetSpanID(idutils.UInt64ToSpanID(0))
848849
span1.SetName("operation1")
849850
span1.SetStartTimestamp(testSpanStartTimestamp)
850851
span1.SetEndTimestamp(testSpanEndTimestamp)

translator/trace/jaeger/jaegerthrift_to_traces.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"
2323

2424
"go.opentelemetry.io/collector/consumer/pdata"
25+
idutils "go.opentelemetry.io/collector/internal/idutils"
2526
"go.opentelemetry.io/collector/translator/conventions"
2627
tracetranslator "go.opentelemetry.io/collector/translator/trace"
2728
)
@@ -95,15 +96,15 @@ func jThriftSpansToInternal(spans []*jaeger.Span, dest pdata.SpanSlice) {
9596
}
9697

9798
func jThriftSpanToInternal(span *jaeger.Span, dest pdata.Span) {
98-
dest.SetTraceID(tracetranslator.UInt64ToTraceID(uint64(span.TraceIdHigh), uint64(span.TraceIdLow)))
99-
dest.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(span.SpanId)))
99+
dest.SetTraceID(idutils.UInt64ToTraceID(uint64(span.TraceIdHigh), uint64(span.TraceIdLow)))
100+
dest.SetSpanID(idutils.UInt64ToSpanID(uint64(span.SpanId)))
100101
dest.SetName(span.OperationName)
101102
dest.SetStartTimestamp(microsecondsToUnixNano(span.StartTime))
102103
dest.SetEndTimestamp(microsecondsToUnixNano(span.StartTime + span.Duration))
103104

104105
parentSpanID := span.ParentSpanId
105106
if parentSpanID != 0 {
106-
dest.SetParentSpanID(tracetranslator.UInt64ToSpanID(uint64(parentSpanID)))
107+
dest.SetParentSpanID(idutils.UInt64ToSpanID(uint64(parentSpanID)))
107108
}
108109

109110
attrs := dest.Attributes()
@@ -184,8 +185,8 @@ func jThriftReferencesToSpanLinks(refs []*jaeger.SpanRef, excludeParentID int64,
184185
continue
185186
}
186187

187-
link.SetTraceID(tracetranslator.UInt64ToTraceID(uint64(ref.TraceIdHigh), uint64(ref.TraceIdLow)))
188-
link.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(ref.SpanId)))
188+
link.SetTraceID(idutils.UInt64ToTraceID(uint64(ref.TraceIdHigh), uint64(ref.TraceIdLow)))
189+
link.SetSpanID(idutils.UInt64ToSpanID(uint64(ref.SpanId)))
189190
i++
190191
}
191192

translator/trace/jaeger/traces_to_jaegerproto.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/jaegertracing/jaeger/model"
2121

2222
"go.opentelemetry.io/collector/consumer/pdata"
23+
idutils "go.opentelemetry.io/collector/internal/idutils"
2324
"go.opentelemetry.io/collector/translator/conventions"
2425
tracetranslator "go.opentelemetry.io/collector/translator/trace"
2526
)
@@ -252,7 +253,7 @@ func getJaegerProtoSpanTags(span pdata.Span, instrumentationLibrary pdata.Instru
252253
}
253254

254255
func traceIDToJaegerProto(traceID pdata.TraceID) (model.TraceID, error) {
255-
traceIDHigh, traceIDLow := tracetranslator.TraceIDToUInt64Pair(traceID)
256+
traceIDHigh, traceIDLow := idutils.TraceIDToUInt64Pair(traceID)
256257
if traceIDLow == 0 && traceIDHigh == 0 {
257258
return model.TraceID{}, errZeroTraceID
258259
}
@@ -263,7 +264,7 @@ func traceIDToJaegerProto(traceID pdata.TraceID) (model.TraceID, error) {
263264
}
264265

265266
func spanIDToJaegerProto(spanID pdata.SpanID) (model.SpanID, error) {
266-
uSpanID := tracetranslator.SpanIDToUInt64(spanID)
267+
uSpanID := idutils.SpanIDToUInt64(spanID)
267268
if uSpanID == 0 {
268269
return model.SpanID(0), errZeroSpanID
269270
}

translator/trace/zipkin/traces_to_zipkinv2.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
zipkinmodel "github.com/openzipkin/zipkin-go/model"
2626

2727
"go.opentelemetry.io/collector/consumer/pdata"
28+
idutils "go.opentelemetry.io/collector/internal/idutils"
2829
"go.opentelemetry.io/collector/translator/conventions"
2930
tracetranslator "go.opentelemetry.io/collector/translator/trace"
3031
)
@@ -358,10 +359,10 @@ func isIPv6Address(ipStr string) bool {
358359
}
359360

360361
func convertTraceID(t pdata.TraceID) zipkinmodel.TraceID {
361-
h, l := tracetranslator.TraceIDToUInt64Pair(t)
362+
h, l := idutils.TraceIDToUInt64Pair(t)
362363
return zipkinmodel.TraceID{High: h, Low: l}
363364
}
364365

365366
func convertSpanID(s pdata.SpanID) zipkinmodel.ID {
366-
return zipkinmodel.ID(tracetranslator.SpanIDToUInt64(s))
367+
return zipkinmodel.ID(idutils.SpanIDToUInt64(s))
367368
}

0 commit comments

Comments
 (0)