From e81bbd22f8dc67f3417c5bdb69a73184473012e6 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Tue, 8 Sep 2020 10:08:02 +0000 Subject: [PATCH] Metrics: Assure announce pid with payload --- instana/agent/host.py | 4 ++-- instana/collector/helpers/runtime.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/instana/agent/host.py b/instana/agent/host.py index d666de6e..5263507e 100644 --- a/instana/agent/host.py +++ b/instana/agent/host.py @@ -6,9 +6,10 @@ import os import json +from datetime import datetime + import urllib3 import requests -from datetime import datetime from ..log import logger from .base import BaseAgent @@ -219,7 +220,6 @@ def report_data_payload(self, payload): # Report metrics metric_bundle = payload["metrics"]["plugins"][0]["data"] - # logger.debug(to_json(metric_bundle)) response = self.client.post(self.__data_url(), data=to_json(metric_bundle), headers={"Content-Type": "application/json"}, diff --git a/instana/collector/helpers/runtime.py b/instana/collector/helpers/runtime.py index e7789c99..79d80ae6 100644 --- a/instana/collector/helpers/runtime.py +++ b/instana/collector/helpers/runtime.py @@ -32,7 +32,14 @@ def collect_metrics(self, with_snapshot=False): plugin_data["name"] = "com.instana.plugin.python" plugin_data["entityId"] = str(os.getpid()) plugin_data["data"] = DictionaryOfStan() - plugin_data["data"]["pid"] = str(os.getpid()) + + if hasattr(self.collector.agent, "announce_data"): + try: + plugin_data["data"]["pid"] = self.collector.agent.announce_data.pid + except Exception: + plugin_data["data"]["pid"] = str(os.getpid()) + else: + plugin_data["data"]["pid"] = str(os.getpid()) self._collect_runtime_metrics(plugin_data, with_snapshot)