mem0
mem0 copied to clipboard
fix: close posthog clients and only create clients if telemtry is ena…
Description
Every call to memory/telemetry.py:capture_event creates a new PostHog client, which internally creates a new thread to handle an internal message queue. This can lead to massive thread counts from idle PostHog clients.
The environment flag MEM0_TELEMETRY=False does not prevent this as it just pauses the PostHog client's internal queue processing.
This PR:
- adds an explicit call to
AnonymousTelemetry.closeshutdown the PostHog client - honors the
MEM0_TELEMETRYflag more conistently by not even creating a PostHog client.
See #3376
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
Maintainer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed