diff --git a/receiver/m365receiver/logs.go b/receiver/m365receiver/logs.go index 2b34ec906..e90e7afae 100644 --- a/receiver/m365receiver/logs.go +++ b/receiver/m365receiver/logs.go @@ -136,7 +136,9 @@ func (l *m365LogsReceiver) Start(ctx context.Context, host component.Host) error func (l *m365LogsReceiver) Shutdown(ctx context.Context) error { l.logger.Debug("shutting down logs receiver") - l.cancel() + if l.cancel != nil { + l.cancel() + } l.wg.Wait() return l.checkpoint(ctx) } @@ -285,6 +287,9 @@ func (l *m365LogsReceiver) transformLogs(now pcommon.Timestamp, audit *auditMeta // sets the checkpoint func (l *m365LogsReceiver) checkpoint(ctx context.Context) error { + if l.record == nil { + return nil + } bytes, err := json.Marshal(l.record) if err != nil { return fmt.Errorf("unable to write checkpoint: %w", err) diff --git a/receiver/m365receiver/scraper.go b/receiver/m365receiver/scraper.go index d3cf959b1..220fc4a41 100644 --- a/receiver/m365receiver/scraper.go +++ b/receiver/m365receiver/scraper.go @@ -295,7 +295,10 @@ func (m *m365Scraper) start(ctx context.Context, host component.Host) error { } func (m *m365Scraper) shutdown(_ context.Context) error { - return m.client.shutdown() + if m.client != nil { + return m.client.shutdown() + } + return nil } // retrieves data, builds metrics & emits them