Instrument a single package using the provided loader. Returns the instrumentor instance if successful, None otherwise.
(loader: InstrumentorLoader)
| 494 | |
| 495 | |
| 496 | def instrument_one(loader: InstrumentorLoader) -> Optional[BaseInstrumentor]: |
| 497 | """ |
| 498 | Instrument a single package using the provided loader. |
| 499 | Returns the instrumentor instance if successful, None otherwise. |
| 500 | """ |
| 501 | if not loader.should_activate: |
| 502 | # This log is important for users to know why something wasn't instrumented. |
| 503 | logger.debug( |
| 504 | f"AgentOps: Package '{loader.package_name or loader.module_name}' not found or version is less than minimum required ('{loader.min_version}'). Skipping instrumentation." |
| 505 | ) |
| 506 | return None |
| 507 | |
| 508 | instrumentor = loader.get_instance() |
| 509 | try: |
| 510 | # Use the provider directly from the global tracer instance |
| 511 | instrumentor.instrument(tracer_provider=tracer.provider) |
| 512 | logger.debug( |
| 513 | f"AgentOps: Successfully instrumented '{loader.class_name}' for package '{loader.package_name or loader.module_name}'." |
| 514 | ) |
| 515 | except Exception as e: |
| 516 | logger.error( |
| 517 | f"Failed to instrument {loader.class_name} for {loader.package_name or loader.module_name}: {e}", |
| 518 | exc_info=True, |
| 519 | ) |
| 520 | return instrumentor |
| 521 | |
| 522 | |
| 523 | def instrument_all(): |
no test coverage detected
searching dependent graphs…