honeyhive.tracer.lifecycle.shutdown
Shutdown and cleanup operations for tracer lifecycle management.
This module handles tracer shutdown, provider cleanup, and resource management with comprehensive error handling, timeout protection, and graceful degradation.
shutdown_tracer
shutdown_tracer(tracer_instance: Any) -> None
Shutdown a tracer instance and clean up its resources.
This function performs a graceful shutdown of a tracer instance, including flushing pending data, shutting down providers, and cleaning up resources. It handles both main and secondary providers appropriately.
:param tracer_instance: The tracer instance to shutdown :type tracer_instance: HoneyHiveTracer
Example:
.. code-block:: python
# Graceful shutdown
shutdown_tracer(tracer)
# In a try/finally block
try:
# Use tracer
with tracer.start_span("operation") as span:
pass
finally:
shutdown_tracer(tracer)
Note:
This function only shuts down the OpenTelemetry provider if the tracer instance is the main provider. Secondary providers are left running to avoid disrupting other tracer instances.
Source code in src/honeyhive/tracer/lifecycle/shutdown.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
graceful_shutdown_all
graceful_shutdown_all() -> None
Gracefully shutdown all registered tracer instances.
This function attempts to find and shutdown all active HoneyHive tracer instances. It's useful for application shutdown or cleanup scenarios where multiple tracers might be active.
Example:
.. code-block:: python
# Application shutdown
import atexit
atexit.register(graceful_shutdown_all)
# Or explicit cleanup
graceful_shutdown_all()
Note:
This function uses the tracer registry to find active instances. It attempts graceful shutdown but continues even if some instances fail to shutdown properly.
Source code in src/honeyhive/tracer/lifecycle/shutdown.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
wait_for_pending_spans
Wait for pending spans to complete processing.
This function waits for any pending spans in the tracer's processors to complete processing. It's useful before shutdown to ensure all data is properly sent.
:param tracer_instance: The tracer instance to wait for :type tracer_instance: HoneyHiveTracer :param max_wait_seconds: Maximum time to wait in seconds :type max_wait_seconds: float :return: True if all spans completed within timeout, False otherwise :rtype: bool
Example:
.. code-block:: python
# Wait for spans before shutdown
if wait_for_pending_spans(tracer, max_wait_seconds=5.0):
print("All spans completed")
else:
print("Timeout waiting for spans")
Note:
This function polls the span processors to check for pending work. It's a best-effort operation and may not catch all edge cases.
Source code in src/honeyhive/tracer/lifecycle/shutdown.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |