@@ -15,14 +15,19 @@ import (
15
15
"github.com/stretchr/testify/assert"
16
16
)
17
17
18
+ func getInstanaCollector () instana.TracerLogger {
19
+ c , _ := instana .GetCollector ()
20
+ return c
21
+ }
22
+
18
23
func Test_Collector_Noop (t * testing.T ) {
19
- assert .NotNil (t , instana . GetC (), "instana collector should never be nil and be initialized as noop" )
24
+ assert .NotNil (t , getInstanaCollector (), "instana collector should never be nil and be initialized as noop" )
20
25
21
- sc , err := instana . GetC ().Extract (nil , nil )
26
+ sc , err := getInstanaCollector ().Extract (nil , nil )
22
27
assert .Nil (t , sc )
23
28
assert .Error (t , err )
24
- assert .Nil (t , instana . GetC ().StartSpan ("" ))
25
- assert .Nil (t , instana . GetC ().LegacySensor ())
29
+ assert .Nil (t , getInstanaCollector ().StartSpan ("" ))
30
+ assert .Nil (t , getInstanaCollector ().LegacySensor ())
26
31
}
27
32
28
33
func Test_Collector_LegacySensor (t * testing.T ) {
@@ -31,7 +36,7 @@ func Test_Collector_LegacySensor(t *testing.T) {
31
36
s := c .LegacySensor ()
32
37
defer instana .ShutdownCollector ()
33
38
34
- assert .NotNil (t , instana . GetC ().LegacySensor ())
39
+ assert .NotNil (t , getInstanaCollector ().LegacySensor ())
35
40
36
41
h := instana .TracingHandlerFunc (s , "/{action}" , func (w http.ResponseWriter , req * http.Request ) {
37
42
fmt .Fprintln (w , "Ok" )
@@ -41,7 +46,7 @@ func Test_Collector_LegacySensor(t *testing.T) {
41
46
42
47
h .ServeHTTP (httptest .NewRecorder (), req )
43
48
44
- assert .Len (t , recorder .GetQueuedSpans (), 1 , "Instrumentations should still work fine with instana.GetC ().LegacySensor()" )
49
+ assert .Len (t , recorder .GetQueuedSpans (), 1 , "Instrumentations should still work fine with getInstanaCollector ().LegacySensor()" )
45
50
}
46
51
47
52
func Test_Collector_Singleton (t * testing.T ) {
@@ -50,17 +55,17 @@ func Test_Collector_Singleton(t *testing.T) {
50
55
51
56
defer instana .ShutdownCollector ()
52
57
53
- _ , ok = instana . GetC ().(* instana.Collector )
58
+ _ , ok = getInstanaCollector ().(* instana.Collector )
54
59
assert .False (t , ok , "instana collector is noop before InitCollector is called" )
55
60
56
61
instana .InitCollector (instana .DefaultOptions ())
57
62
58
- instance , ok = instana . GetC ().(* instana.Collector )
63
+ instance , ok = getInstanaCollector ().(* instana.Collector )
59
64
assert .True (t , ok , "instana collector is of type instana.Collector after InitCollector is called" )
60
65
61
66
instana .InitCollector (instana .DefaultOptions ())
62
67
63
- assert .Equal (t , instana . GetC (), instance , "instana collector is singleton and should not be reassigned if InitCollector is called again" )
68
+ assert .Equal (t , getInstanaCollector (), instance , "instana collector is singleton and should not be reassigned if InitCollector is called again" )
64
69
}
65
70
66
71
func Test_Collector_EmbeddedTracer (t * testing.T ) {
@@ -98,13 +103,15 @@ func Test_Collector_Logger(t *testing.T) {
98
103
99
104
l := & mylogger {}
100
105
101
- instana .GetC ().SetLogger (l )
106
+ c := getInstanaCollector ()
107
+
108
+ c .SetLogger (l )
102
109
103
- instana . GetC () .Debug ()
104
- instana . GetC () .Info ()
105
- instana . GetC () .Warn ()
106
- instana . GetC () .Error ()
107
- instana . GetC () .Error ()
110
+ c .Debug ()
111
+ c .Info ()
112
+ c .Warn ()
113
+ c .Error ()
114
+ c .Error ()
108
115
109
116
assert .Equal (t , 1 , l .counter ["debug" ])
110
117
assert .Equal (t , 1 , l .counter ["info" ])
0 commit comments