Skip to content

Commit

Permalink
[connector/datadog] fix start logic to start if tracesConsumer is pre…
Browse files Browse the repository at this point in the history
…sent; make shutdown work even if start was not called
  • Loading branch information
atoulme committed Jan 12, 2024
1 parent 93f7f52 commit 50c4a19
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
7 changes: 5 additions & 2 deletions connector/datadogconnector/connector.go
Expand Up @@ -67,15 +67,15 @@ func newConnector(set component.TelemetrySettings, _ component.Config, metricsCo
in: in,
metricsConsumer: metricsConsumer,
tracesConsumer: tracesConsumer,
exit: make(chan struct{}),
}, nil
}

// Start implements the component.Component interface.
func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
c.logger.Info("Starting datadogconnector")
c.agent.Start()
if c.metricsConsumer != nil {
c.exit = make(chan struct{})
if c.metricsConsumer != nil || c.tracesConsumer != nil {
go c.run()
}
return nil
Expand All @@ -84,6 +84,9 @@ func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
// Shutdown implements the component.Component interface.
func (c *connectorImp) Shutdown(context.Context) error {
c.logger.Info("Shutting down datadog connector")
if c.exit == nil {
return nil
}
c.agent.Stop()
c.exit <- struct{}{} // signal exit
<-c.exit // wait for close
Expand Down
93 changes: 93 additions & 0 deletions connector/datadogconnector/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connector/datadogconnector/go.mod
Expand Up @@ -9,6 +9,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog v0.92.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/connector v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/consumer v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/pdata v1.0.2-0.20240110091511-bf804d6c4ecc
Expand Down Expand Up @@ -72,7 +73,6 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/collector v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/featuregate v1.0.2-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/semconv v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions connector/datadogconnector/metadata.yaml
Expand Up @@ -8,3 +8,6 @@ status:
codeowners:
active: [mx-psi, dineshg13]
emeritus: [gbbr]

tests:
config:

0 comments on commit 50c4a19

Please sign in to comment.