Skip to content

Commit 98f7693

Browse files
bachgarashdmathieu
andauthored
chore: flatten bridge/opentracing/internal package (#6916)
This commit moves `bridge/opentracing/internal/mock.go` to `bridge/opentracing/mock_test.go`, makes all exported types private and removes unnecessary `bridge/open/internal` package. Closes #6563 --------- Co-authored-by: Damien Mathieu <[email protected]>
1 parent 1b803e1 commit 98f7693

File tree

11 files changed

+117
-189
lines changed

11 files changed

+117
-189
lines changed

bridge/opentracing/test/bridge_grpc_test.go renamed to bridge/opentracing/bridge_grpc_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package test
4+
package opentracing
55

66
import (
77
"context"
@@ -17,8 +17,6 @@ import (
1717
"google.golang.org/grpc"
1818
"google.golang.org/grpc/credentials/insecure"
1919

20-
ototel "go.opentelemetry.io/otel/bridge/opentracing"
21-
"go.opentelemetry.io/otel/bridge/opentracing/internal"
2220
"go.opentelemetry.io/otel/propagation"
2321
)
2422

@@ -56,9 +54,8 @@ func startTestGRPCServer(t *testing.T, tracer ot.Tracer) (*grpc.Server, net.Addr
5654
}
5755

5856
func TestBridgeTracer_ExtractAndInject_gRPC(t *testing.T) {
59-
tracer := internal.NewMockTracer()
60-
61-
bridge := ototel.NewBridgeTracer()
57+
tracer := newMockTracer()
58+
bridge := NewBridgeTracer()
6259
bridge.SetOpenTelemetryTracer(tracer)
6360
bridge.SetTextMapPropagator(propagation.TraceContext{})
6461

bridge/opentracing/bridge_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"go.opentelemetry.io/otel"
2222
"go.opentelemetry.io/otel/attribute"
23-
"go.opentelemetry.io/otel/bridge/opentracing/internal"
2423
"go.opentelemetry.io/otel/propagation"
2524
"go.opentelemetry.io/otel/trace"
2625
)
@@ -467,7 +466,7 @@ func Test_otTagToOTelAttr(t *testing.T) {
467466
}
468467

469468
func TestBridgeSpan_SetTag(t *testing.T) {
470-
tracer := internal.NewMockTracer()
469+
tracer := newMockTracer()
471470
b, _ := NewTracerPair(tracer)
472471

473472
testCases := []struct {
@@ -513,7 +512,7 @@ func TestBridgeSpan_SetTag(t *testing.T) {
513512
span := b.StartSpan("test")
514513

515514
span.SetTag(tc.tagKey, tc.tagValue)
516-
mockSpan := span.(*bridgeSpan).otelSpan.(*internal.MockSpan)
515+
mockSpan := span.(*bridgeSpan).otelSpan.(*mockSpan)
517516
if tc.expected != nil {
518517
assert.Contains(t, mockSpan.Attributes, tc.expected)
519518
} else {
@@ -524,7 +523,7 @@ func TestBridgeSpan_SetTag(t *testing.T) {
524523
}
525524

526525
func Test_otTagsToOTelAttributesKindAndError(t *testing.T) {
527-
tracer := internal.NewMockTracer()
526+
tracer := newMockTracer()
528527
sc := &bridgeSpanContext{}
529528

530529
testCases := []struct {
@@ -559,7 +558,7 @@ func Test_otTagsToOTelAttributesKindAndError(t *testing.T) {
559558
b, _ := NewTracerPair(tracer)
560559

561560
s := b.StartSpan(tc.name, tc.opt...)
562-
assert.Equal(t, tc.expected, s.(*bridgeSpan).otelSpan.(*internal.MockSpan).SpanKind)
561+
assert.Equal(t, tc.expected, s.(*bridgeSpan).otelSpan.(*mockSpan).SpanKind)
563562
})
564563
}
565564
}
@@ -584,7 +583,7 @@ func TestBridge_SpanContext_IsSampled(t *testing.T) {
584583

585584
for _, tc := range testCases {
586585
t.Run(tc.name, func(t *testing.T) {
587-
tracer := internal.NewMockTracer()
586+
tracer := newMockTracer()
588587
tracer.TraceFlags = tc.flags
589588

590589
b, _ := NewTracerPair(tracer)
@@ -688,7 +687,7 @@ func TestBridgeCarrierBaggagePropagation(t *testing.T) {
688687
for _, c := range carriers {
689688
for _, tc := range testCases {
690689
t.Run(fmt.Sprintf("%s %s", c.name, tc.name), func(t *testing.T) {
691-
mockOtelTracer := internal.NewMockTracer()
690+
mockOtelTracer := newMockTracer()
692691
b, _ := NewTracerPair(mockOtelTracer)
693692
b.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
694693
propagation.TraceContext{},
@@ -881,12 +880,12 @@ func TestBridgeSpan_LogFields(t *testing.T) {
881880

882881
for _, tc := range testCases {
883882
t.Run(tc.name, func(t *testing.T) {
884-
tracer := internal.NewMockTracer()
883+
tracer := newMockTracer()
885884
b, _ := NewTracerPair(tracer)
886885
span := b.StartSpan("test")
887886

888887
span.LogFields(tc.field)
889-
mockSpan := span.(*bridgeSpan).otelSpan.(*internal.MockSpan)
888+
mockSpan := span.(*bridgeSpan).otelSpan.(*mockSpan)
890889
event := mockSpan.Events[0]
891890
assert.Contains(t, event.Attributes, tc.expected)
892891
})
@@ -983,11 +982,11 @@ func TestBridgeSpan_LogKV(t *testing.T) {
983982

984983
for _, tc := range testCases {
985984
t.Run(tc.name, func(t *testing.T) {
986-
tracer := internal.NewMockTracer()
985+
tracer := newMockTracer()
987986
b, _ := NewTracerPair(tracer)
988987
span := b.StartSpan("test")
989988
span.LogKV(tc.kv[0], tc.kv[1])
990-
mockSpan := span.(*bridgeSpan).otelSpan.(*internal.MockSpan)
989+
mockSpan := span.(*bridgeSpan).otelSpan.(*mockSpan)
991990
event := mockSpan.Events[0]
992991
assert.Contains(t, event.Attributes, tc.expected)
993992
})

bridge/opentracing/go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ replace go.opentelemetry.io/otel => ../..
77
replace go.opentelemetry.io/otel/trace => ../../trace
88

99
require (
10+
github.com/opentracing-contrib/go-grpc v0.1.1
11+
github.com/opentracing-contrib/go-grpc/test v0.0.0-20250122020132-2f9c7e3db032
1012
github.com/opentracing/opentracing-go v1.2.0
1113
github.com/stretchr/testify v1.10.0
1214
go.opentelemetry.io/otel v1.36.0
1315
go.opentelemetry.io/otel/trace v1.36.0
16+
google.golang.org/grpc v1.73.0
1417
)
1518

1619
require (
1720
github.com/davecgh/go-spew v1.1.1 // indirect
1821
github.com/go-logr/logr v1.4.3 // indirect
1922
github.com/go-logr/stdr v1.2.2 // indirect
23+
github.com/golang/protobuf v1.5.4 // indirect
2024
github.com/pmezard/go-difflib v1.0.0 // indirect
2125
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
2226
go.opentelemetry.io/otel/metric v1.36.0 // indirect
27+
golang.org/x/net v0.38.0 // indirect
28+
golang.org/x/sys v0.31.0 // indirect
29+
golang.org/x/text v0.23.0 // indirect
30+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
31+
google.golang.org/protobuf v1.36.6 // indirect
2332
gopkg.in/yaml.v3 v3.0.1 // indirect
2433
)
2534

bridge/opentracing/go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
66
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
77
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
88
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
9+
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
10+
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
911
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1012
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
13+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
14+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1115
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1216
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1317
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1418
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
19+
github.com/opentracing-contrib/go-grpc v0.1.1 h1:Ws7IN1zyiL1DFqKQPhRXuKe5pLYzMfdxnC1qtajE2PE=
20+
github.com/opentracing-contrib/go-grpc v0.1.1/go.mod h1:Nu6sz+4zzgxXu8rvKfnwjBEmHsuhTigxRwV2RhELrS8=
21+
github.com/opentracing-contrib/go-grpc/test v0.0.0-20250122020132-2f9c7e3db032 h1:HGsK6KQUCjUB/wh0h7kxtNWu8AMmiGTFMiv9s9JrDSs=
22+
github.com/opentracing-contrib/go-grpc/test v0.0.0-20250122020132-2f9c7e3db032/go.mod h1:lGUfQ7UdqHsl7maAepZ2isMI1odCvxR62U2m/Jfi0oQ=
1523
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
1624
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
1725
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -24,6 +32,22 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
2432
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2533
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
2634
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
35+
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
36+
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
37+
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
38+
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
39+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
40+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
41+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
42+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
43+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
44+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
45+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g=
46+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
47+
google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
48+
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
49+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
50+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
2751
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2852
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
2953
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

bridge/opentracing/internal/doc.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

bridge/opentracing/mix_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ import (
1313
"go.opentelemetry.io/otel"
1414
"go.opentelemetry.io/otel/attribute"
1515
"go.opentelemetry.io/otel/baggage"
16-
"go.opentelemetry.io/otel/bridge/opentracing/internal"
1716
"go.opentelemetry.io/otel/trace"
1817
)
1918

2019
type mixedAPIsTestCase struct {
2120
desc string
2221

23-
setup func(*testing.T, *internal.MockTracer)
22+
setup func(*testing.T, *mockTracer)
2423
run func(*testing.T, context.Context)
25-
check func(*testing.T, *internal.MockTracer)
24+
check func(*testing.T, *mockTracer)
2625
}
2726

2827
func getMixedAPIsTestCases() []mixedAPIsTestCase {
@@ -99,7 +98,7 @@ func getMixedAPIsTestCases() []mixedAPIsTestCase {
9998
func TestMixedAPIs(t *testing.T) {
10099
for idx, tc := range getMixedAPIsTestCases() {
101100
t.Logf("Running test case %d: %s", idx, tc.desc)
102-
mockOtelTracer := internal.NewMockTracer()
101+
mockOtelTracer := newMockTracer()
103102
ctx, otTracer, otelProvider := NewTracerPairWithContext(context.Background(), mockOtelTracer)
104103
otTracer.SetWarningHandler(func(msg string) {
105104
t.Log(msg)
@@ -128,12 +127,12 @@ func newSimpleTest() *simpleTest {
128127
}
129128
}
130129

131-
func (st *simpleTest) setup(t *testing.T, tracer *internal.MockTracer) {
130+
func (st *simpleTest) setup(t *testing.T, tracer *mockTracer) {
132131
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, st.traceID)
133132
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, st.spanIDs...)
134133
}
135134

136-
func (st *simpleTest) check(t *testing.T, tracer *internal.MockTracer) {
135+
func (st *simpleTest) check(t *testing.T, tracer *mockTracer) {
137136
checkTraceAndSpans(t, tracer, st.traceID, st.spanIDs)
138137
}
139138

@@ -166,15 +165,15 @@ func newCurrentActiveSpanTest() *currentActiveSpanTest {
166165
}
167166
}
168167

169-
func (cast *currentActiveSpanTest) setup(t *testing.T, tracer *internal.MockTracer) {
168+
func (cast *currentActiveSpanTest) setup(t *testing.T, tracer *mockTracer) {
170169
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, cast.traceID)
171170
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, cast.spanIDs...)
172171

173172
cast.recordedCurrentOtelSpanIDs = nil
174173
cast.recordedActiveOTSpanIDs = nil
175174
}
176175

177-
func (cast *currentActiveSpanTest) check(t *testing.T, tracer *internal.MockTracer) {
176+
func (cast *currentActiveSpanTest) check(t *testing.T, tracer *mockTracer) {
178177
checkTraceAndSpans(t, tracer, cast.traceID, cast.spanIDs)
179178
if len(cast.recordedCurrentOtelSpanIDs) != len(cast.spanIDs) {
180179
t.Errorf(
@@ -236,7 +235,7 @@ func (cast *currentActiveSpanTest) recordSpans(t *testing.T, ctx context.Context
236235
// context intact test
237236

238237
type contextIntactTest struct {
239-
contextKeyValues []internal.MockContextKeyValue
238+
contextKeyValues []mockContextKeyValue
240239

241240
recordedContextValues []interface{}
242241
recordIdx int
@@ -256,7 +255,7 @@ type coin3Value struct{}
256255

257256
func newContextIntactTest() *contextIntactTest {
258257
return &contextIntactTest{
259-
contextKeyValues: []internal.MockContextKeyValue{
258+
contextKeyValues: []mockContextKeyValue{
260259
{
261260
Key: coin1Key{},
262261
Value: coin1Value{},
@@ -273,14 +272,14 @@ func newContextIntactTest() *contextIntactTest {
273272
}
274273
}
275274

276-
func (coin *contextIntactTest) setup(t *testing.T, tracer *internal.MockTracer) {
275+
func (coin *contextIntactTest) setup(t *testing.T, tracer *mockTracer) {
277276
tracer.SpareContextKeyValues = append(tracer.SpareContextKeyValues, coin.contextKeyValues...)
278277

279278
coin.recordedContextValues = nil
280279
coin.recordIdx = 0
281280
}
282281

283-
func (coin *contextIntactTest) check(t *testing.T, tracer *internal.MockTracer) {
282+
func (coin *contextIntactTest) check(t *testing.T, tracer *mockTracer) {
284283
if len(coin.recordedContextValues) != len(coin.contextKeyValues) {
285284
t.Errorf(
286285
"Expected to have %d recorded context values, got %d",
@@ -352,12 +351,12 @@ func newBaggageItemsPreservationTest() *baggageItemsPreservationTest {
352351
}
353352
}
354353

355-
func (bip *baggageItemsPreservationTest) setup(t *testing.T, tracer *internal.MockTracer) {
354+
func (bip *baggageItemsPreservationTest) setup(t *testing.T, tracer *mockTracer) {
356355
bip.step = 0
357356
bip.recordedBaggage = nil
358357
}
359358

360-
func (bip *baggageItemsPreservationTest) check(t *testing.T, tracer *internal.MockTracer) {
359+
func (bip *baggageItemsPreservationTest) check(t *testing.T, tracer *mockTracer) {
361360
if len(bip.recordedBaggage) != len(bip.baggageItems) {
362361
t.Errorf("Expected %d recordings, got %d", len(bip.baggageItems), len(bip.recordedBaggage))
363362
}
@@ -450,13 +449,13 @@ func newBaggageInteroperationTest() *baggageInteroperationTest {
450449
}
451450
}
452451

453-
func (bio *baggageInteroperationTest) setup(t *testing.T, tracer *internal.MockTracer) {
452+
func (bio *baggageInteroperationTest) setup(t *testing.T, tracer *mockTracer) {
454453
bio.step = 0
455454
bio.recordedOTBaggage = nil
456455
bio.recordedOtelBaggage = nil
457456
}
458457

459-
func (bio *baggageInteroperationTest) check(t *testing.T, tracer *internal.MockTracer) {
458+
func (bio *baggageInteroperationTest) check(t *testing.T, tracer *mockTracer) {
460459
checkBIORecording(t, "OT", bio.baggageItems, bio.recordedOTBaggage)
461460
checkBIORecording(t, "Otel", bio.baggageItems, bio.recordedOtelBaggage)
462461
}
@@ -579,7 +578,7 @@ func generateBaggageKeys(key string) (otKey, otelKey string) {
579578

580579
func checkTraceAndSpans(
581580
t *testing.T,
582-
tracer *internal.MockTracer,
581+
tracer *mockTracer,
583582
expectedTraceID trace.TraceID,
584583
expectedSpanIDs []trace.SpanID,
585584
) {

0 commit comments

Comments
 (0)