From 767e6df24ae872bfc1ca1df7c49870f69b03e5da Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Thu, 12 Sep 2024 14:31:12 +0300 Subject: [PATCH 1/2] chore: comment all logging as they for some reason leak into the application --- initializer/odigos_sampler.py | 25 +++++++++++++------------ opamp/http_client.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/initializer/odigos_sampler.py b/initializer/odigos_sampler.py index 9255ef5..df54a42 100644 --- a/initializer/odigos_sampler.py +++ b/initializer/odigos_sampler.py @@ -5,10 +5,10 @@ # Setup the Sampler logger sampler_logger = logging.getLogger(__name__) -sampler_logger.setLevel(logging.DEBUG) +# sampler_logger.setLevel(logging.DEBUG) # handler = logging.StreamHandler() # sampler_logger.addHandler(handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) or handler) -sampler_logger.disabled = True # Comment this line to enable the logger +# sampler_logger.disabled = True # Comment this line to enable the logger class OdigosSampler(Sampler): @@ -38,10 +38,10 @@ def _trace_id_based_sampling(self, trace_id, fraction): def should_sample(self, parent_context, trace_id, name, kind, attributes, links): with self._lock: - sampler_logger.debug(f'Running Should_sample a span with the following attributes: {attributes}') + # sampler_logger.debug(f'Running Should_sample a span with the following attributes: {attributes}') if self._config is None: - sampler_logger.debug('No configuration is set, returning RECORD_AND_SAMPLE') + # sampler_logger.debug('No configuration is set, returning RECORD_AND_SAMPLE') return SamplingResult(Decision.RECORD_AND_SAMPLE) rules = self._config.get('attributesAndSamplerRules', []) @@ -50,7 +50,7 @@ def should_sample(self, parent_context, trace_id, name, kind, attributes, links) for rule in rules: # The first attribute rule that evaluates to true is used to determine the sampling decision based on its fraction. and_attributes_sampler_rules = rule.get('attributeConditions', []) - sampler_logger.debug(f'"AND" rule operands are: {and_attributes_sampler_rules}') + # sampler_logger.debug(f'"AND" rule operands are: {and_attributes_sampler_rules}') and_rule_fraction = rule.get('fraction', 1) # default to 1 if not set which means always sample and_rule_met = True @@ -68,25 +68,26 @@ def should_sample(self, parent_context, trace_id, name, kind, attributes, links) # Perform the corresponding operation if operator in self._operations and self._operations[operator](attributes[key], value): - sampler_logger.debug(f'Operator {operator} is true for the attribute {key} with value {value}') + # sampler_logger.debug(f'Operator {operator} is true for the attribute {key} with value {value}') + pass else: - sampler_logger.debug(f'Operator {operator} is false, setting the "AND" rule flag to false') + # sampler_logger.debug(f'Operator {operator} is false, setting the "AND" rule flag to false') and_rule_met = False else: - sampler_logger.debug(f'Attribute {key} is not present in the span attributes, setting the "AND" rule flag to false') + # sampler_logger.debug(f'Attribute {key} is not present in the span attributes, setting the "AND" rule flag to false') and_rule_met = False if and_rule_met: # Perform the sampling decision if self._trace_id_based_sampling(trace_id, and_rule_fraction): - sampler_logger.debug(f'Trace [{trace_id}] is sampled "And rules" are met with fraction {and_rule_fraction}') + # sampler_logger.debug(f'Trace [{trace_id}] is sampled "And rules" are met with fraction {and_rule_fraction}') return SamplingResult(Decision.RECORD_AND_SAMPLE) else: - sampler_logger.debug(f'Trace [{trace_id}] is dropped "And rules" are met but fraction {and_rule_fraction} not met') + # sampler_logger.debug(f'Trace [{trace_id}] is dropped "And rules" are met but fraction {and_rule_fraction} not met') return SamplingResult(Decision.DROP) # Fallback to the global fraction if no rule matches - sampler_logger.debug(f'No rule matched, falling back to the global fraction {global_fraction}') + # sampler_logger.debug(f'No rule matched, falling back to the global fraction {global_fraction}') if self._trace_id_based_sampling(trace_id, global_fraction): return SamplingResult(Decision.RECORD_AND_SAMPLE) else: @@ -98,5 +99,5 @@ def get_description(self): def update_config(self, new_config): with self._lock: - sampler_logger.debug(f'Updating the configuration with the new configuration: {new_config}') + # sampler_logger.debug(f'Updating the configuration with the new configuration: {new_config}') self._config = new_config \ No newline at end of file diff --git a/opamp/http_client.py b/opamp/http_client.py index 843c1ad..d94007a 100644 --- a/opamp/http_client.py +++ b/opamp/http_client.py @@ -148,7 +148,7 @@ def worker(self): self.condition.wait(30) def send_heartbeat(self) -> opamp_pb2.ServerToAgent: # type: ignore - opamp_logger.debug("Sending heartbeat to OpAMP server...") + # opamp_logger.debug("Sending heartbeat to OpAMP server...") try: agent_to_server = opamp_pb2.AgentToServer(remote_config_status=self.remote_config_status) return self.send_agent_to_server_message(agent_to_server) From 9df3213b2d0bbe89abd410e3d7093e556793711b Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Thu, 12 Sep 2024 14:32:51 +0300 Subject: [PATCH 2/2] chore: keep disable logger --- initializer/odigos_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializer/odigos_sampler.py b/initializer/odigos_sampler.py index df54a42..6af8197 100644 --- a/initializer/odigos_sampler.py +++ b/initializer/odigos_sampler.py @@ -8,7 +8,7 @@ # sampler_logger.setLevel(logging.DEBUG) # handler = logging.StreamHandler() # sampler_logger.addHandler(handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) or handler) -# sampler_logger.disabled = True # Comment this line to enable the logger +sampler_logger.disabled = True # Comment this line to enable the logger class OdigosSampler(Sampler):