azpaddypy 0.3.7__py3-none-any.whl → 0.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azpaddypy/mgmt/logging.py +73 -42
- {azpaddypy-0.3.7.dist-info → azpaddypy-0.3.9.dist-info}/METADATA +1 -1
- {azpaddypy-0.3.7.dist-info → azpaddypy-0.3.9.dist-info}/RECORD +6 -6
- {azpaddypy-0.3.7.dist-info → azpaddypy-0.3.9.dist-info}/WHEEL +0 -0
- {azpaddypy-0.3.7.dist-info → azpaddypy-0.3.9.dist-info}/licenses/LICENSE +0 -0
- {azpaddypy-0.3.7.dist-info → azpaddypy-0.3.9.dist-info}/top_level.txt +0 -0
azpaddypy/mgmt/logging.py
CHANGED
@@ -517,70 +517,101 @@ class AzureLogger:
|
|
517
517
|
is_async: bool,
|
518
518
|
):
|
519
519
|
"""Handle failed function execution in tracing."""
|
520
|
-
span.set_status(Status(StatusCode.ERROR, str(e)))
|
520
|
+
span.set_status(Status(StatusCode.ERROR, description=str(e)))
|
521
521
|
span.record_exception(e)
|
522
|
-
span.set_attribute("function.duration_ms", duration_ms)
|
523
|
-
span.set_attribute("function.success", False)
|
524
|
-
span.set_attribute("error.type", type(e).__name__)
|
525
|
-
span.set_attribute("error.message", str(e))
|
526
|
-
|
527
522
|
if log_execution:
|
528
523
|
self.log_function_execution(
|
529
|
-
func.__name__,
|
530
|
-
|
531
|
-
|
532
|
-
{
|
533
|
-
|
534
|
-
"error_message": str(e),
|
535
|
-
"is_async": is_async,
|
536
|
-
},
|
524
|
+
function_name=func.__name__, duration_ms=duration_ms, success=False
|
525
|
+
)
|
526
|
+
self.error(
|
527
|
+
f"Exception in {'async ' if is_async else ''}"
|
528
|
+
f"function '{func.__name__}': {e}"
|
537
529
|
)
|
538
|
-
|
539
|
-
log_prefix = "Async function" if is_async else "Function"
|
540
|
-
self.error(f"{log_prefix} execution failed: {func.__name__} - {str(e)}")
|
541
530
|
|
542
531
|
def trace_function(
|
543
532
|
self,
|
544
533
|
function_name: Optional[str] = None,
|
545
534
|
log_execution: bool = True,
|
546
535
|
log_args: bool = True,
|
547
|
-
log_result: bool = False
|
536
|
+
log_result: bool = False,
|
548
537
|
) -> Callable:
|
549
|
-
"""
|
538
|
+
"""Trace function execution with OpenTelemetry.
|
550
539
|
|
551
|
-
|
552
|
-
|
553
|
-
|
540
|
+
This decorator provides a simple way to instrument a function by automatically
|
541
|
+
creating an OpenTelemetry span to trace its execution. It measures execution
|
542
|
+
time, captures arguments, and records the result as attributes on the span.
|
543
|
+
It supports both synchronous and asynchronous functions.
|
554
544
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
- Ensures consistent tracing across function calls
|
545
|
+
A correlation ID is automatically managed. If one is not already set on the
|
546
|
+
logger instance, a new UUID4 correlation ID will be generated and used for
|
547
|
+
the function's trace, ensuring that all related logs and traces can be
|
548
|
+
linked together.
|
560
549
|
|
561
550
|
Args:
|
562
|
-
function_name
|
563
|
-
|
564
|
-
|
565
|
-
|
551
|
+
function_name (Optional[str], optional):
|
552
|
+
Specifies a custom name for the span. If not provided, the name of the
|
553
|
+
decorated function is used. Defaults to None.
|
554
|
+
log_execution (bool, optional):
|
555
|
+
When True, a log message is emitted at the start and end of the function's
|
556
|
+
execution, including the execution duration. This provides a clear
|
557
|
+
record of the function's lifecycle. Defaults to True.
|
558
|
+
log_args (bool, optional):
|
559
|
+
When True, the arguments passed to the function are recorded as
|
560
|
+
attributes on the span. This is useful for understanding the context
|
561
|
+
of the function call. Sensitive arguments should be handled with care.
|
562
|
+
Defaults to True.
|
563
|
+
log_result (bool, optional):
|
564
|
+
When True, the return value of the function is recorded as an attribute
|
565
|
+
on the span. This should be used cautiously, as large or sensitive
|
566
|
+
return values may be captured. Defaults to False.
|
566
567
|
|
567
568
|
Returns:
|
568
|
-
|
569
|
+
Callable: A decorator that can be applied to a function.
|
569
570
|
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
def my_function():
|
574
|
-
return "result"
|
571
|
+
Examples:
|
572
|
+
Basic usage with default settings:
|
573
|
+
Logs execution, arguments, but not the result.
|
575
574
|
|
576
|
-
# Manual correlation_id (preserved)
|
577
|
-
logger.set_correlation_id("manual-id")
|
578
575
|
@logger.trace_function()
|
579
|
-
def
|
580
|
-
return "
|
576
|
+
def sample_function(param1, param2="default"):
|
577
|
+
return "done"
|
578
|
+
|
579
|
+
Customizing the span name:
|
580
|
+
The span will be named "MyCustomTask" instead of "process_data".
|
581
|
+
|
582
|
+
@logger.trace_function(function_name="MyCustomTask")
|
583
|
+
def process_data(data):
|
584
|
+
# processing logic
|
585
|
+
return {"status": "processed"}
|
586
|
+
|
587
|
+
Logging the result:
|
588
|
+
Enable `log_result=True` to capture the function's return value.
|
589
|
+
|
590
|
+
@logger.trace_function(log_result=True)
|
591
|
+
def get_user_id(username):
|
592
|
+
return 12345
|
593
|
+
|
594
|
+
Disabling argument logging for sensitive data:
|
595
|
+
If a function handles sensitive information, disable argument logging.
|
596
|
+
|
597
|
+
@logger.trace_function(log_args=False)
|
598
|
+
def process_payment(credit_card_details):
|
599
|
+
# payment processing logic
|
600
|
+
pass
|
601
|
+
|
602
|
+
Tracing an asynchronous function:
|
603
|
+
The decorator works with async functions without any extra configuration.
|
604
|
+
|
605
|
+
@logger.trace_function(log_result=True)
|
606
|
+
async def fetch_remote_data(url):
|
607
|
+
# async data fetching
|
608
|
+
return await http_get(url)
|
581
609
|
"""
|
582
610
|
|
583
611
|
def decorator(func):
|
612
|
+
# Determine if the function is async at decoration time
|
613
|
+
is_async = asyncio.iscoroutinefunction(func)
|
614
|
+
|
584
615
|
@functools.wraps(func)
|
585
616
|
async def async_wrapper(*args, **kwargs):
|
586
617
|
span_name = function_name or f"{func.__module__}.{func.__name__}"
|
@@ -656,7 +687,7 @@ class AzureLogger:
|
|
656
687
|
raise
|
657
688
|
|
658
689
|
# Return appropriate wrapper based on function type
|
659
|
-
if
|
690
|
+
if is_async:
|
660
691
|
return async_wrapper
|
661
692
|
return sync_wrapper
|
662
693
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: azpaddypy
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.9
|
4
4
|
Summary: Comprehensive Python logger for Azure, integrating OpenTelemetry for advanced, structured, and distributed tracing.
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
6
6
|
Classifier: Operating System :: OS Independent
|
@@ -1,11 +1,11 @@
|
|
1
1
|
azpaddypy/__init__.py,sha256=hrWNAh4OHZOvm3Pbhq5eUjO-pSRYn0h0W0J87tc-lNI,45
|
2
2
|
azpaddypy/mgmt/__init__.py,sha256=-jH8Ftx9C8qu4yF5dMVEapVZhNwG7m4QCUjyutesOoY,278
|
3
3
|
azpaddypy/mgmt/identity.py,sha256=mA_krQslMsK_sDob-z-QA0B9khK_JUO2way7xwPopR8,12001
|
4
|
-
azpaddypy/mgmt/logging.py,sha256=
|
4
|
+
azpaddypy/mgmt/logging.py,sha256=5RTxzQeSDWysVQZ3Wiu0serM42Ba3hMYWza7NoEOR08,36753
|
5
5
|
azpaddypy/resources/__init__.py,sha256=Bvt3VK4RqwoxYpoh6EbLXIR18RuFPKaLP6zLL-icyFk,314
|
6
6
|
azpaddypy/resources/keyvault.py,sha256=4J08vLqoLFd1_UUDBji2oG2fatZaPkgnRyT_Z6wHAOc,20312
|
7
|
-
azpaddypy-0.3.
|
8
|
-
azpaddypy-0.3.
|
9
|
-
azpaddypy-0.3.
|
10
|
-
azpaddypy-0.3.
|
11
|
-
azpaddypy-0.3.
|
7
|
+
azpaddypy-0.3.9.dist-info/licenses/LICENSE,sha256=hQ6t0g2QaewGCQICHqTckBFbMVakGmoyTAzDpmEYV4c,1089
|
8
|
+
azpaddypy-0.3.9.dist-info/METADATA,sha256=hzvsml5CIzufS4mJkK06RdYNXKmC1HiCMUt0ysepJRY,665
|
9
|
+
azpaddypy-0.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
10
|
+
azpaddypy-0.3.9.dist-info/top_level.txt,sha256=hsDuboDhT61320ML8X479ezSTwT3rrlDWz1_Z45B2cs,10
|
11
|
+
azpaddypy-0.3.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|