Repository: deepset-ai/haystack

Issue:
`since_last_run` not sent
**Describe the bug**
The field `since_last_run` seems to be always empty for Pipeline telemetry events.

**Details**
It was introduced here (see last change at the end of the diff) https://github.com/deepset-ai/haystack/pull/4275/files#diff-a250e689bd860af91399950f344040321e6d76c000016ffafadb297e2a92ea0cR215-R222 but then disappeared from main.

It apparently has been removed here https://github.com/deepset-ai/haystack/commit/6d578ebf3dbb0be6126756a03d7115b8e407106d#diff-31b925f6ad8af5214cd1aeae3ff4f7afecf5e8a5e44a95cf458fd463fcae576f after being mistaken as part of the machinery of telemetry v2


Discussion:

Resolving patch:
diff --git a/haystack/pipelines/base.py b/haystack/pipelines/base.py
--- a/haystack/pipelines/base.py
+++ b/haystack/pipelines/base.py
@@ -73,6 +73,7 @@ def __init__(self):
         self.graph = DiGraph()
         self.config_hash = None
         self.last_config_hash = None
+        self.runs = 0
 
     @property
     def root_node(self) -> Optional[str]:
@@ -492,6 +493,8 @@ def run(  # type: ignore
                       about their execution. By default, this information includes the input parameters
                       the Nodes received and the output they generated. You can then find all debug information in the dictionary returned by this method under the key `_debug`.
         """
+        self.runs += 1
+
         send_pipeline_event(
             pipeline=self,
             query=query,
@@ -640,6 +643,8 @@ def run_batch(  # type: ignore
                       about their execution. By default, this information includes the input parameters
                       the Nodes received and the output they generated. You can then find all debug information in the dictionary returned by this method under the key `_debug`.
         """
+        self.runs += 1
+
         send_pipeline_event(
             pipeline=self,
             queries=queries,
diff --git a/haystack/telemetry.py b/haystack/telemetry.py
--- a/haystack/telemetry.py
+++ b/haystack/telemetry.py
@@ -14,6 +14,7 @@
 HAYSTACK_EXECUTION_CONTEXT = "HAYSTACK_EXECUTION_CONTEXT"
 HAYSTACK_DOCKER_CONTAINER = "HAYSTACK_DOCKER_CONTAINER"
 CONFIG_PATH = Path("~/.haystack/config.yaml").expanduser()
+SEND_EVENT_EVERY_N_RUNS = 100
 
 
 logger = logging.getLogger(__name__)
@@ -146,14 +147,18 @@ def send_pipeline_event(  # type: ignore
                 telemetry.send_event(event_name="Public Demo", event_properties=event_properties)
                 return
 
-            # Send this event only if the pipeline config has changed
-            if pipeline.last_config_hash == pipeline.config_hash:
+            # If pipeline config has not changed, send an event every SEND_EVENT_EVERY_N_RUNS runs
+            if pipeline.last_config_hash == pipeline.config_hash and pipeline.runs % SEND_EVENT_EVERY_N_RUNS == 0:
+                event_properties = {"pipeline.config_hash": pipeline.config_hash, "pipeline.runs": pipeline.runs}
+                telemetry.send_event(event_name="Pipeline", event_properties=event_properties)
                 return
             pipeline.last_config_hash = pipeline.config_hash
+            pipeline.runs = 1
 
             event_properties = {
                 "pipeline.classname": pipeline.__class__.__name__,
                 "pipeline.config_hash": pipeline.config_hash,
+                "pipeline.runs": pipeline.runs,
             }
 
             # Add document store


Test patch: