feat: support optional otel global initialization for #3284 (#3292)

This commit is contained in:
MiNG 2023-05-28 19:41:48 +08:00 committed by GitHub
parent 28d3905731
commit 1b5946346e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -33,6 +33,11 @@ var (
// StartAgent starts an opentelemetry agent.
func StartAgent(c Config) {
if c.Disabled {
return
}
lock.Lock()
defer lock.Unlock()

View File

@ -16,6 +16,7 @@ func TestStartAgent(t *testing.T) {
endpoint3 = "localhost:1235"
endpoint4 = "localhost:1236"
endpoint5 = "udp://localhost:6831"
endpoint6 = "localhost:1237"
)
c1 := Config{
Name: "foo",
@ -57,6 +58,11 @@ func TestStartAgent(t *testing.T) {
Endpoint: endpoint5,
Batcher: kindJaeger,
}
c8 := Config{
Disabled: true,
Endpoint: endpoint6,
Batcher: kindJaeger,
}
StartAgent(c1)
StartAgent(c1)
@ -66,6 +72,7 @@ func TestStartAgent(t *testing.T) {
StartAgent(c5)
StartAgent(c6)
StartAgent(c7)
StartAgent(c8)
lock.Lock()
defer lock.Unlock()
@ -80,4 +87,6 @@ func TestStartAgent(t *testing.T) {
assert.False(t, ok)
_, ok = agents[endpoint5]
assert.True(t, ok)
_, ok = agents[endpoint6]
assert.False(t, ok)
}

View File

@ -17,4 +17,7 @@ type Config struct {
// For example
// /v1/traces
OtlpHttpPath string `json:",optional"`
// Disabled indicates whether StartAgent should be called when starting the server.
Disabled bool
}