@@ -38,19 +38,38 @@ func ExampleRegisterService() {
38
38
shutdown := Init (cfg )
39
39
defer shutdown ()
40
40
41
- _ , _ , err := RegisterService ("custom_service" , map [string ]string {"test1" : "val1" })
41
+ _ , _ , err := RegisterService ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" })
42
42
if err != nil {
43
43
log .Fatalf ("Error while initializing service: %v" , err )
44
44
}
45
45
}
46
46
47
+ func TestMultiRegisterService (t * testing.T ) {
48
+ cfg := config .Load ()
49
+ cfg .ServiceName = config .String ("my_example_svc" )
50
+ cfg .DataCapture .HttpHeaders .Request = config .Bool (true )
51
+ cfg .Reporting .TraceReporterType = config .TraceReporterType_LOGGING
52
+
53
+ shutdown := Init (cfg )
54
+ defer shutdown ()
55
+
56
+ _ , _ , err := RegisterService ("custom_env" , "custom_service" , map [string ]string {"test1" : "val1" })
57
+ assert .Nil (t , err )
58
+
59
+ _ , _ , err = RegisterService ("custom_env" , "custom_service_2" , map [string ]string {"test2" : "val2" })
60
+ assert .Nil (t , err )
61
+
62
+ _ , _ , err = RegisterService ("custom_env_1" , "custom_service" , map [string ]string {"test3" : "val3" })
63
+ assert .Nil (t , err )
64
+ }
65
+
47
66
func TestInitDisabledAgent (t * testing.T ) {
48
67
cfg := config .Load ()
49
68
cfg .Enabled = config .Bool (false )
50
69
shutdown := Init (cfg )
51
70
defer shutdown ()
52
71
53
- startSpan , tp , err := RegisterService ("test_service" , nil )
72
+ startSpan , tp , err := RegisterService ("custom_env" , " test_service" , nil )
54
73
require .NoError (t , err )
55
74
assert .Equal (t , noop .NewTracerProvider (), tp )
56
75
_ , s , _ := startSpan (context .Background (), "test_span" , nil )
@@ -80,7 +99,7 @@ func TestOtlpService(t *testing.T) {
80
99
shutdown := Init (cfg )
81
100
defer shutdown ()
82
101
83
- startSpan , tp , err := RegisterService ("custom_service" , map [string ]string {"test1" : "val1" })
102
+ startSpan , tp , err := RegisterService ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" })
84
103
_ , s , _ := startSpan (context .Background (), "test_span" , nil )
85
104
assert .False (t , s .IsNoop ())
86
105
assert .NotEqual (t , noop .NewTracerProvider (), tp )
@@ -102,7 +121,7 @@ func TestGrpcLoadBalancingConfig(t *testing.T) {
102
121
defer shutdown ()
103
122
104
123
assert .Equal (t , resolver .GetDefaultScheme (), "dns" )
105
- _ , tp , err := RegisterService ("custom_service" , map [string ]string {"test1" : "val1" })
124
+ _ , tp , err := RegisterService ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" })
106
125
assert .NotEqual (t , noop .NewTracerProvider (), tp )
107
126
if err != nil {
108
127
log .Fatalf ("Error while initializing service: %v" , err )
@@ -165,7 +184,7 @@ func TestMultipleTraceProviders(t *testing.T) {
165
184
_ , _ , spanEnder := StartSpan (context .Background (), "example_span" , nil )
166
185
spanEnder ()
167
186
168
- startServiceSpan , tp , err := RegisterService ("custom_service" , map [string ]string {"test1" : "val1" })
187
+ startServiceSpan , tp , err := RegisterService ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" })
169
188
assert .NoError (t , err )
170
189
assert .NotNil (t , startServiceSpan )
171
190
assert .True (t , initialized )
@@ -208,7 +227,7 @@ func TestMultipleTraceProvidersCallAfterShutdown(t *testing.T) {
208
227
assert .True (t , initialized )
209
228
assert .Equal (t , 0 , len (traceProviders ))
210
229
211
- startServiceSpan , _ , err := RegisterService ("custom_service" , map [string ]string {"test1" : "val1" })
230
+ startServiceSpan , _ , err := RegisterService ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" })
212
231
assert .NoError (t , err )
213
232
assert .NotNil (t , startServiceSpan )
214
233
assert .True (t , initialized )
@@ -379,7 +398,7 @@ func TestInitWithSpanProcessorWrapper(t *testing.T) {
379
398
assert .Equal (t , 2 , wrapper .onEndCount )
380
399
381
400
// test wrapper is called for spans created by service trace provider
382
- startSpan , _ , err := RegisterServiceWithSpanProcessorWrapper ("custom_service" , map [string ]string {"test1" : "val1" }, wrapper ,
401
+ startSpan , _ , err := RegisterServiceWithSpanProcessorWrapper ("custom_env" , " custom_service" , map [string ]string {"test1" : "val1" }, wrapper ,
383
402
versionInfoAttributes )
384
403
if err != nil {
385
404
log .Fatalf ("Error while initializing service: %v" , err )
0 commit comments