class_docstr: Haystack reports anonymous usage statistics to support continuous software improvements for all its users.
  
  You can opt-out of sharing usage statistics by manually setting the environment
  variable `HAYSTACK_TELEMETRY_ENABLED` as described for different operating systems on the
  [documentation page](https://docs.haystack.deepset.ai/docs/telemetry#how-can-i-opt-out).
  
  Check out the documentation for more details: [Telemetry](https://docs.haystack.deepset.ai/docs/telemetry).
class_docstr_tok: ["Haystack","reports","anonymous","usage","statistics","to","support","continuous","software","improvements","for","all","its","users",".","You","can","opt-out","of","sharing","usage","statistics","by","manually","setting","the","environment","variable","`","HAYSTACK_TELEMETRY_ENABLED","`","as","described","for","different","operating","systems","on","the","[","documentation","page","]","(","https",":","\/\/docs.haystack.deepset.ai\/docs\/telemetry","#","how-can-i-opt-out",")",".","Check","out","the","documentation","for","more","details",":","[","Telemetry","]","(","https",":","\/\/docs.haystack.deepset.ai\/docs\/telemetry",")","."]
docstr: Initializes the telemetry. Loads the user_id from the config file,
  or creates a new id and saves it if the file is not found.
  
  It also collects system information which cannot change across the lifecycle
  of the process (for example `is_containerized()`).
docstr_tok: ["Initializes","the","telemetry",".","Loads","the","user_id","from","the","config","file",",","or","creates","a","new","id","and","saves","it","if","the","file","is","not","found",".","It","also","collects","system","information","which","can","not","change","across","the","lifecycle","of","the","process","(","for","example","`","is_containerized","(",")","`",")","."]
code: def __init__(self):
      """
      Initializes the telemetry. Loads the user_id from the config file,
      or creates a new id and saves it if the file is not found.
  
      It also collects system information which cannot change across the lifecycle
      of the process (for example `is_containerized()`).
      """
      posthog.api_key = (
          "phc_C44vUK9R1J6HYVdfJarTEPqVAoRPJzMXzFcj8PIrJgP"
      )
      posthog.host = "https://eu.posthog.com"
  
      # disable posthog logging
      for module_name in ["posthog", "backoff"]:
          logging.getLogger(module_name).setLevel(logging.CRITICAL)
          # Prevent module from sending errors to stderr when an exception is encountered during an emit() call
          logging.getLogger(module_name).addHandler(
              logging.NullHandler()
          )
          logging.getLogger(module_name).propagate = False
  
      self.user_id = None
  
      if CONFIG_PATH.exists():
          # Load the config file
          try:
              with open(
                  CONFIG_PATH, "r", encoding="utf-8"
              ) as config_file:
                  config = yaml.safe_load(config_file)
                  if "user_id" in config:
                      self.user_id = config["user_id"]
          except Exception as e:
              logger.debug(
                  "Telemetry could not read the config file %s",
                  CONFIG_PATH,
                  exc_info=e,
              )
      else:
          # Create the config file
          logger.info(
              "Haystack sends anonymous usage data to understand the actual usage and steer dev efforts "
              "towards features that are most meaningful to users. You can opt-out at anytime by manually "
              "setting the environment variable HAYSTACK_TELEMETRY_ENABLED as described for different "
              "operating systems in the [documentation page](https://docs.haystack.deepset.ai/docs/telemetry#how-can-i-opt-out). "
              "More information at [Telemetry](https://docs.haystack.deepset.ai/docs/telemetry)."
          )
          CONFIG_PATH.parents[0].mkdir(parents=True, exist_ok=True)
          self.user_id = str(uuid.uuid4())
          try:
              with open(CONFIG_PATH, "w") as outfile:
                  yaml.dump(
                      {"user_id": self.user_id},
                      outfile,
                      default_flow_style=False,
                  )
          except Exception as e:
              logger.debug(
                  "Telemetry could not write config file to %s",
                  CONFIG_PATH,
                  exc_info=e,
              )
  
      self.event_properties = collect_system_specs()
  
file_path: haystack/haystack/telemetry/_telemetry.py
imports: from typing import Any, Dict, Optional, TYPE_CHECKING, List, Tuple
  import os
  from pathlib import Path
  from collections import defaultdict
  import datetime
  import logging
  import uuid
  import yaml
  import posthog
  from haystack.telemetry._environment import collect_system_specs
label_desc: Use image node_id 1 to create a new Telemetry object  with example: obj = Telemetry()