diff --git a/instrumentation.go b/instrumentation.go index 82be5d832..0338b9198 100644 --- a/instrumentation.go +++ b/instrumentation.go @@ -74,7 +74,7 @@ func NewInstrumentation(opts ...InstrumentationOption) (*Instrumentation, error) log.Logger.Error(err, "unable to connect to OTLP endpoint") return nil, err } - r, err := orchestrator.New( + r, err := orchestrator.NewService( orchestrator.WithServiceName(c.serviceName), orchestrator.WithTarget(c.exePath), orchestrator.WithExporter(traceExporter), diff --git a/internal/pkg/orchestrator/orchestrator.go b/internal/pkg/orchestrator/orchestrator.go index ef5a3b262..7127bb14f 100644 --- a/internal/pkg/orchestrator/orchestrator.go +++ b/internal/pkg/orchestrator/orchestrator.go @@ -31,8 +31,8 @@ type pidServiceName struct { pid int } -// New creates a new Implementation of orchestrator Service. -func New( +// NewService creates a new Implementation of orchestrator Service. +func NewService( opts ...ServiceOpt, ) (*Service, error) { s := Service{ @@ -40,7 +40,7 @@ func New( processch: make(chan *pidServiceName, 10), deadProcess: make(chan int, 10), managers: make(map[int]*instrumentors.Manager), - pidTicker: time.NewTicker(2 * time.Second).C, + pidTicker: time.NewTicker(2 * time.Second), monitorAll: true, } for _, o := range opts { @@ -57,8 +57,9 @@ func (s *Service) Run(ctx context.Context) error { for { select { case <-ctx.Done(): - log.Logger.Info("Got context done") + s.pidTicker.Stop() + for _, m := range s.managers { m.Close() } @@ -167,7 +168,7 @@ func (s *Service) findProcess(ctx context.Context) { select { case <-ctx.Done(): return - case <-s.pidTicker: + case <-s.pidTicker.C: pids, err := s.analyzer.FindAllProcesses("") if err != nil { diff --git a/internal/pkg/orchestrator/service.go b/internal/pkg/orchestrator/service.go index 0de06d81d..bf32c0c58 100644 --- a/internal/pkg/orchestrator/service.go +++ b/internal/pkg/orchestrator/service.go @@ -41,7 +41,7 @@ type Service struct { managers map[int]*instrumentors.Manager exporter sdktrace.SpanExporter pid int - pidTicker <-chan time.Time + pidTicker *time.Ticker } // ServiceOpt applies a configuration option to [Service].