omnata-plugin-runtime 0.8.0a189__tar.gz → 0.8.0a190__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.8.0a189
3
+ Version: 0.8.0a190
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "omnata-plugin-runtime"
3
- version = "0.8.0-a189"
3
+ version = "0.8.0-a190"
4
4
  description = "Classes and common runtime components for building and running Omnata Plugins"
5
5
  authors = ["James Weakley <james.weakley@omnata.com>"]
6
6
  readme = "README.md"
@@ -19,6 +19,9 @@ from .logging import logger
19
19
  import pytz
20
20
  from requests.adapters import HTTPAdapter
21
21
  from urllib3.util.retry import Retry
22
+ from opentelemetry import trace
23
+
24
+ tracer = trace.get_tracer(__name__)
22
25
 
23
26
  TimeUnitType = Literal["second", "minute", "hour", "day"]
24
27
 
@@ -383,11 +386,12 @@ class RetryWithLogging(Retry):
383
386
  retry_after = self.get_retry_after(response)
384
387
  if retry_after:
385
388
  logger.info(f"Retrying after {retry_after} seconds due to Retry-After header")
386
- if self.thread_cancellation_token is None:
387
- time.sleep(retry_after)
388
- else:
389
- if self.thread_cancellation_token.wait(retry_after):
390
- raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
389
+ with tracer.start_as_current_span("http_retry_wait"):
390
+ if self.thread_cancellation_token is None:
391
+ time.sleep(retry_after)
392
+ else:
393
+ if self.thread_cancellation_token.wait(retry_after):
394
+ raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
391
395
  return True
392
396
  return False
393
397
 
@@ -504,8 +508,9 @@ class RateLimitedSession(requests.Session):
504
508
  raise InterruptedWhileWaitingException(message=f"The rate limiting wait time ({wait_time} seconds) would exceed the run deadline")
505
509
  logger.info(f"Waiting for {wait_time} seconds before retrying {method} request to {url}")
506
510
  # if wait() returns true, it means that the thread was cancelled
507
- if self.thread_cancellation_token.wait(wait_time):
508
- raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
511
+ with tracer.start_as_current_span("http_retry_wait"):
512
+ if self.thread_cancellation_token.wait(wait_time):
513
+ raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
509
514
  else:
510
515
  current_url_retries = self.increment_retries(url)
511
516
  if current_url_retries >= self.max_retries:
@@ -514,8 +519,9 @@ class RateLimitedSession(requests.Session):
514
519
  if datetime.datetime.now(pytz.UTC) + datetime.timedelta(seconds=backoff_time) > self.run_deadline:
515
520
  raise InterruptedWhileWaitingException(message=f"The rate limiting backoff time ({backoff_time} seconds) would exceed the run deadline")
516
521
  logger.info(f"Waiting for {backoff_time} seconds before retrying {method} request to {url}")
517
- if self.thread_cancellation_token.wait(backoff_time):
518
- raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting backoff")
522
+ with tracer.start_as_current_span("http_retry_wait"):
523
+ if self.thread_cancellation_token.wait(backoff_time):
524
+ raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting backoff")
519
525
  else:
520
526
  self.set_retries(url,0) # Reset retries if the request is successful
521
527
  return response