Skip to content

Commit 1837301

Browse files
authored
Merge branch 'main' into deprecate-otelkit
2 parents 22da99e + 33c3a8f commit 1837301

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2727
- `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`
2828
- `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`
2929
- Do not modify the origin request in RoundTripper in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#4033)
30+
- Handle empty value of `OTEL_PROPAGATORS` environment variable the same way as when the variable is unset in `go.opentelemetry.io/contrib/propagators/autoprop`. (#4101)
3031

3132
### Deprecated
3233

exporters/autoexport/registry_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package autoexport
1717
import (
1818
"context"
1919
"fmt"
20+
"sync"
2021
"testing"
2122

2223
"github.com/stretchr/testify/assert"
@@ -59,19 +60,27 @@ func TestRegistryIsConcurrentSafe(t *testing.T) {
5960
require.NoError(t, r.store(exporterName, stdoutFactory))
6061
})
6162

63+
var wg sync.WaitGroup
64+
65+
wg.Add(1)
6266
go func() {
67+
defer wg.Done()
6368
assert.NotPanics(t, func() {
6469
require.ErrorIs(t, r.store(exporterName, stdoutFactory), errDuplicateRegistration)
6570
})
6671
}()
6772

73+
wg.Add(1)
6874
go func() {
75+
defer wg.Done()
6976
assert.NotPanics(t, func() {
7077
exp, err := r.load(context.Background(), exporterName)
7178
assert.Nil(t, err, "missing exporter in registry")
7279
assert.IsType(t, &stdouttrace.Exporter{}, exp)
7380
})
7481
}()
82+
83+
wg.Wait()
7584
}
7685

7786
func TestSubsequentCallsToGetExporterReturnsNewInstances(t *testing.T) {

propagators/autoprop/propagator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ var errUnknownPropagator = errors.New("unknown propagator")
8282
// TextMapPropagator will be returned if "none" is defined anywhere in the
8383
// environment variable.
8484
func parseEnv() (propagation.TextMapPropagator, error) {
85-
propStrs, defined := os.LookupEnv(otelPropagatorsEnvKey)
86-
if !defined {
85+
propStrs := os.Getenv(otelPropagatorsEnvKey)
86+
if propStrs == "" {
8787
return nil, nil
8888
}
8989
return TextMapPropagator(strings.Split(propStrs, ",")...)

propagators/autoprop/registry_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package autoprop
1616

1717
import (
1818
"fmt"
19+
"sync"
1920
"testing"
2021

2122
"github.com/stretchr/testify/assert"
@@ -50,19 +51,27 @@ func TestRegistryConcurrentSafe(t *testing.T) {
5051
require.NoError(t, r.store(propName, noop))
5152
})
5253

54+
var wg sync.WaitGroup
55+
56+
wg.Add(1)
5357
go func() {
58+
defer wg.Done()
5459
assert.NotPanics(t, func() {
5560
require.ErrorIs(t, r.store(propName, noop), errDupReg)
5661
})
5762
}()
5863

64+
wg.Add(1)
5965
go func() {
66+
defer wg.Done()
6067
assert.NotPanics(t, func() {
6168
v, ok := r.load(propName)
6269
assert.True(t, ok, "missing propagator in registry")
6370
assert.Equal(t, noop, v, "wrong propagator retuned")
6471
})
6572
}()
73+
74+
wg.Wait()
6675
}
6776

6877
func TestRegisterTextMapPropagator(t *testing.T) {

samplers/aws/xray/internal/manifest_test.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package internal
1717
import (
1818
"context"
1919
"net/url"
20+
"sync"
2021
"testing"
2122
"time"
2223

@@ -1492,7 +1493,7 @@ func TestGenerateClientID(t *testing.T) {
14921493
}
14931494

14941495
// validate no data race is happening when updating rule properties in manifest while matching.
1495-
func TestRaceUpdatingRulesWhileMatching(t *testing.T) {
1496+
func TestUpdatingRulesWhileMatchingConcurrentSafe(t *testing.T) {
14961497
// getSamplingRules response
14971498
ruleRecords := samplingRuleRecords{
14981499
SamplingRule: &ruleProperties{
@@ -1546,7 +1547,9 @@ func TestRaceUpdatingRulesWhileMatching(t *testing.T) {
15461547
}
15471548

15481549
// async rule updates
1550+
done := make(chan struct{})
15491551
go func() {
1552+
defer close(done)
15501553
for i := 0; i < 100; i++ {
15511554
m.updateRules(s)
15521555
time.Sleep(time.Millisecond)
@@ -1559,10 +1562,11 @@ func TestRaceUpdatingRulesWhileMatching(t *testing.T) {
15591562
require.NoError(t, err)
15601563
require.False(t, match)
15611564
}
1565+
<-done
15621566
}
15631567

15641568
// validate no data race is happening when updating rule properties and rule targets in manifest while matching.
1565-
func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
1569+
func TestUpdatingRulesAndTargetsWhileMatchingConcurrentSafe(t *testing.T) {
15661570
// getSamplingRules response to update existing manifest rule
15671571
ruleRecords := samplingRuleRecords{
15681572
SamplingRule: &ruleProperties{
@@ -1610,8 +1614,12 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
16101614
clock: clock,
16111615
}
16121616

1617+
var wg sync.WaitGroup
1618+
16131619
// async rule updates
1620+
wg.Add(1)
16141621
go func() {
1622+
defer wg.Done()
16151623
for i := 0; i < 100; i++ {
16161624
m.updateRules(&getSamplingRulesOutput{
16171625
SamplingRuleRecords: []*samplingRuleRecords{&ruleRecords},
@@ -1621,7 +1629,9 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
16211629
}()
16221630

16231631
// async target updates
1632+
wg.Add(1)
16241633
go func() {
1634+
defer wg.Done()
16251635
for i := 0; i < 100; i++ {
16261636
manifest := m.deepCopy()
16271637

@@ -1642,6 +1652,8 @@ func TestRaceUpdatingRulesAndTargetsWhileMatching(t *testing.T) {
16421652
require.False(t, match)
16431653
time.Sleep(time.Millisecond)
16441654
}
1655+
1656+
wg.Wait()
16451657
}
16461658

16471659
// Validate Rules are preserved when a rule is updated with the same ruleProperties.
@@ -1782,7 +1794,7 @@ func TestDoNotPreserveRulesWithDifferentRuleProperties(t *testing.T) {
17821794
}
17831795

17841796
// validate no data race is when capturing sampling statistics in manifest while sampling.
1785-
func TestRaceUpdatingSamplingStatisticsWhenSampling(t *testing.T) {
1797+
func TestUpdatingSamplingStatisticsWhenSamplingConcurrentSafe(t *testing.T) {
17861798
// existing rule already present in manifest
17871799
r1 := Rule{
17881800
ruleProperties: ruleProperties{
@@ -1819,7 +1831,9 @@ func TestRaceUpdatingSamplingStatisticsWhenSampling(t *testing.T) {
18191831
}
18201832

18211833
// async snapshot updates
1834+
done := make(chan struct{})
18221835
go func() {
1836+
defer close(done)
18231837
for i := 0; i < 100; i++ {
18241838
manifest := m.deepCopy()
18251839

@@ -1838,4 +1852,5 @@ func TestRaceUpdatingSamplingStatisticsWhenSampling(t *testing.T) {
18381852
_ = r1.Sample(sdktrace.SamplingParameters{}, time.Unix(clock.nowTime+int64(i), 0))
18391853
time.Sleep(time.Millisecond)
18401854
}
1855+
<-done
18411856
}

samplers/aws/xray/internal/rule_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ func TestMatchAgainstManifestRulesNoAttributeMatch(t *testing.T) {
563563
}
564564

565565
// validate no data race is happening when updating rule properties and rule targets in manifest while sampling.
566-
func TestRaceUpdatingRulesAndTargetsWhileSampling(t *testing.T) {
566+
func TestUpdatingRulesAndTargetsWhileSamplingConcurrentSafe(t *testing.T) {
567567
// getSamplingRules response to update existing manifest rule
568568
ruleRecords := samplingRuleRecords{
569569
SamplingRule: &ruleProperties{

samplers/jaegerremote/sampler_remote_test.go

+20-21
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/binary"
2121
"errors"
2222
"fmt"
23+
"sync"
2324
"testing"
2425
"time"
2526

@@ -33,7 +34,7 @@ import (
3334
oteltrace "go.opentelemetry.io/otel/trace"
3435
)
3536

36-
func TestRemotelyControlledSampler_updateRace(t *testing.T) {
37+
func TestRemotelyControlledSampler_updateConcurrentSafe(t *testing.T) {
3738
initSampler := newProbabilisticSampler(0.123)
3839
fetcher := &testSamplingStrategyFetcher{response: []byte("probabilistic")}
3940
parser := new(testSamplingStrategyParser)
@@ -50,31 +51,25 @@ func TestRemotelyControlledSampler_updateRace(t *testing.T) {
5051
withUpdaters(updaters...),
5152
)
5253

54+
defer sampler.Close()
55+
5356
s := makeSamplingParameters(1, "test")
54-
end := make(chan struct{})
5557

56-
accessor := func(f func()) {
57-
for {
58-
select {
59-
case <-end:
60-
return
61-
default:
62-
f()
63-
}
64-
}
65-
}
58+
var wg sync.WaitGroup
6659

67-
go accessor(func() {
60+
wg.Add(1)
61+
go func() {
62+
defer wg.Done()
6863
sampler.UpdateSampler()
69-
})
64+
}()
7065

71-
go accessor(func() {
66+
wg.Add(1)
67+
go func() {
68+
defer wg.Done()
7269
sampler.ShouldSample(s)
73-
})
70+
}()
7471

75-
time.Sleep(100 * time.Millisecond)
76-
close(end)
77-
sampler.Close()
72+
wg.Wait()
7873
}
7974

8075
type testSamplingStrategyFetcher struct {
@@ -200,11 +195,15 @@ func TestRemotelyControlledSampler(t *testing.T) {
200195
ticker := &time.Ticker{C: c}
201196
// reset closed so the next call to Close() correctly stops the polling goroutine
202197
remoteSampler.closed = 0
203-
go remoteSampler.pollControllerWithTicker(ticker)
198+
done := make(chan struct{})
199+
go func() {
200+
defer close(done)
201+
remoteSampler.pollControllerWithTicker(ticker)
202+
}()
204203

205204
c <- time.Now() // force update based on timer
206-
time.Sleep(10 * time.Millisecond)
207205
remoteSampler.Close()
206+
<-done
208207

209208
s2, ok := remoteSampler.sampler.(*probabilisticSampler)
210209
assert.True(t, ok)

0 commit comments

Comments
 (0)