Skip to content

Commit

Permalink
Merge pull request #22 from odigos-io/disable-logging
Browse files Browse the repository at this point in the history
chore: comment all logging as they for some reason leak into the application
  • Loading branch information
blumamir authored Sep 12, 2024
2 parents 62ab2c6 + 9df3213 commit 413be00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions initializer/odigos_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# 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
Expand Down Expand Up @@ -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', [])
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion opamp/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 413be00

Please sign in to comment.