azpaddypy 0.1.4__py3-none-any.whl → 0.1.6__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/test_function/__init__.py +112 -0
- azpaddypy/test_function/function_app.py +116 -0
- {azpaddypy-0.1.4.dist-info → azpaddypy-0.1.6.dist-info}/METADATA +1 -1
- azpaddypy-0.1.6.dist-info/RECORD +9 -0
- azpaddypy-0.1.6.dist-info/top_level.txt +1 -0
- azpaddypy-0.1.4.dist-info/RECORD +0 -7
- azpaddypy-0.1.4.dist-info/top_level.txt +0 -1
- {mgmt → azpaddypy/mgmt}/__init__.py +0 -0
- {mgmt → azpaddypy/mgmt}/logging.py +0 -0
- {azpaddypy-0.1.4.dist-info → azpaddypy-0.1.6.dist-info}/WHEEL +0 -0
- {azpaddypy-0.1.4.dist-info → azpaddypy-0.1.6.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
import logging
|
2
|
+
import json
|
3
|
+
import time
|
4
|
+
import azure.functions as func
|
5
|
+
from azpaddypy.mgmt.logging import create_function_logger
|
6
|
+
|
7
|
+
# Initialize the logger
|
8
|
+
logger = create_function_logger(
|
9
|
+
function_app_name="test-function-app", function_name="test-function"
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
@logger.trace_function(log_args=True, log_result=True)
|
14
|
+
def process_request(req_body: dict) -> dict:
|
15
|
+
"""Process the request body and return a response"""
|
16
|
+
# Simulate some processing time
|
17
|
+
time.sleep(0.1)
|
18
|
+
|
19
|
+
# Log the request processing
|
20
|
+
logger.info(
|
21
|
+
"Processing request",
|
22
|
+
extra={
|
23
|
+
"request_id": req_body.get("request_id", "unknown"),
|
24
|
+
"action": req_body.get("action", "unknown"),
|
25
|
+
},
|
26
|
+
)
|
27
|
+
|
28
|
+
return {
|
29
|
+
"status": "success",
|
30
|
+
"message": "Request processed successfully",
|
31
|
+
"data": req_body,
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
def main(req: func.HttpRequest) -> func.HttpResponse:
|
36
|
+
"""Azure Function entry point"""
|
37
|
+
try:
|
38
|
+
# Start timing the request
|
39
|
+
start_time = time.time()
|
40
|
+
|
41
|
+
# Get request details
|
42
|
+
method = req.method
|
43
|
+
url = req.url
|
44
|
+
headers = dict(req.headers)
|
45
|
+
|
46
|
+
# Log the incoming request
|
47
|
+
logger.log_request(
|
48
|
+
method=method,
|
49
|
+
url=url,
|
50
|
+
status_code=200, # We'll update this if there's an error
|
51
|
+
duration_ms=0, # We'll update this at the end
|
52
|
+
extra={"headers": headers, "request_type": "http_trigger"},
|
53
|
+
)
|
54
|
+
|
55
|
+
# Create a span for the entire function execution
|
56
|
+
with logger.create_span("function_execution") as span:
|
57
|
+
# Add request metadata to the span
|
58
|
+
span.set_attribute("http.method", method)
|
59
|
+
span.set_attribute("http.url", url)
|
60
|
+
|
61
|
+
# Parse request body
|
62
|
+
try:
|
63
|
+
req_body = req.get_json()
|
64
|
+
except ValueError:
|
65
|
+
req_body = {}
|
66
|
+
|
67
|
+
# Log the request body
|
68
|
+
logger.info("Received request body", extra={"body": req_body})
|
69
|
+
|
70
|
+
# Process the request
|
71
|
+
result = process_request(req_body)
|
72
|
+
|
73
|
+
# Calculate request duration
|
74
|
+
duration_ms = (time.time() - start_time) * 1000
|
75
|
+
|
76
|
+
# Log successful completion
|
77
|
+
logger.log_function_execution(
|
78
|
+
function_name="main",
|
79
|
+
duration_ms=duration_ms,
|
80
|
+
success=True,
|
81
|
+
extra={"method": method, "url": url},
|
82
|
+
)
|
83
|
+
|
84
|
+
# Return the response
|
85
|
+
return func.HttpResponse(
|
86
|
+
json.dumps(result), mimetype="application/json", status_code=200
|
87
|
+
)
|
88
|
+
|
89
|
+
except Exception as e:
|
90
|
+
# Calculate request duration
|
91
|
+
duration_ms = (time.time() - start_time) * 1000
|
92
|
+
|
93
|
+
# Log the error
|
94
|
+
logger.error(
|
95
|
+
f"Error processing request: {str(e)}",
|
96
|
+
extra={"method": method, "url": url, "error_type": type(e).__name__},
|
97
|
+
)
|
98
|
+
|
99
|
+
# Log failed execution
|
100
|
+
logger.log_function_execution(
|
101
|
+
function_name="main",
|
102
|
+
duration_ms=duration_ms,
|
103
|
+
success=False,
|
104
|
+
extra={"error": str(e), "error_type": type(e).__name__},
|
105
|
+
)
|
106
|
+
|
107
|
+
# Return error response
|
108
|
+
return func.HttpResponse(
|
109
|
+
json.dumps({"status": "error", "message": str(e)}),
|
110
|
+
mimetype="application/json",
|
111
|
+
status_code=500,
|
112
|
+
)
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import logging
|
2
|
+
import json
|
3
|
+
import time
|
4
|
+
import azure.functions as func
|
5
|
+
from azpaddypy.mgmt.logging import create_function_logger
|
6
|
+
|
7
|
+
app = func.FunctionApp()
|
8
|
+
|
9
|
+
# Initialize the logger
|
10
|
+
logger = create_function_logger(
|
11
|
+
function_app_name="test-function-app", function_name="test-function"
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
@logger.trace_function(log_args=True, log_result=True)
|
16
|
+
def process_request(req_body: dict) -> dict:
|
17
|
+
"""Process the request body and return a response"""
|
18
|
+
# Simulate some processing time
|
19
|
+
time.sleep(0.1)
|
20
|
+
|
21
|
+
# Log the request processing
|
22
|
+
logger.info(
|
23
|
+
"Processing request",
|
24
|
+
extra={
|
25
|
+
"request_id": req_body.get("request_id", "unknown"),
|
26
|
+
"action": req_body.get("action", "unknown"),
|
27
|
+
},
|
28
|
+
)
|
29
|
+
|
30
|
+
return {
|
31
|
+
"status": "success",
|
32
|
+
"message": "Request processed successfully",
|
33
|
+
"data": req_body,
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
@app.function_name(name="test-function")
|
38
|
+
@app.route(route="test-function", auth_level=func.AuthLevel.ANONYMOUS)
|
39
|
+
def test_function(req: func.HttpRequest) -> func.HttpResponse:
|
40
|
+
"""Azure Function v2 HTTP trigger with comprehensive logging"""
|
41
|
+
try:
|
42
|
+
# Start timing the request
|
43
|
+
start_time = time.time()
|
44
|
+
|
45
|
+
# Get request details
|
46
|
+
method = req.method
|
47
|
+
url = req.url
|
48
|
+
headers = dict(req.headers)
|
49
|
+
|
50
|
+
# Log the incoming request
|
51
|
+
logger.log_request(
|
52
|
+
method=method,
|
53
|
+
url=url,
|
54
|
+
status_code=200, # We'll update this if there's an error
|
55
|
+
duration_ms=0, # We'll update this at the end
|
56
|
+
extra={"headers": headers, "request_type": "http_trigger"},
|
57
|
+
)
|
58
|
+
|
59
|
+
# Create a span for the entire function execution
|
60
|
+
with logger.create_span("function_execution") as span:
|
61
|
+
# Add request metadata to the span
|
62
|
+
span.set_attribute("http.method", method)
|
63
|
+
span.set_attribute("http.url", url)
|
64
|
+
|
65
|
+
# Parse request body
|
66
|
+
try:
|
67
|
+
req_body = req.get_json()
|
68
|
+
except ValueError:
|
69
|
+
req_body = {}
|
70
|
+
|
71
|
+
# Log the request body
|
72
|
+
logger.info("Received request body", extra={"body": req_body})
|
73
|
+
|
74
|
+
# Process the request
|
75
|
+
result = process_request(req_body)
|
76
|
+
|
77
|
+
# Calculate request duration
|
78
|
+
duration_ms = (time.time() - start_time) * 1000
|
79
|
+
|
80
|
+
# Log successful completion
|
81
|
+
logger.log_function_execution(
|
82
|
+
function_name="test_function",
|
83
|
+
duration_ms=duration_ms,
|
84
|
+
success=True,
|
85
|
+
extra={"method": method, "url": url},
|
86
|
+
)
|
87
|
+
|
88
|
+
# Return the response
|
89
|
+
return func.HttpResponse(
|
90
|
+
json.dumps(result), mimetype="application/json", status_code=200
|
91
|
+
)
|
92
|
+
|
93
|
+
except Exception as e:
|
94
|
+
# Calculate request duration
|
95
|
+
duration_ms = (time.time() - start_time) * 1000
|
96
|
+
|
97
|
+
# Log the error
|
98
|
+
logger.error(
|
99
|
+
f"Error processing request: {str(e)}",
|
100
|
+
extra={"method": method, "url": url, "error_type": type(e).__name__},
|
101
|
+
)
|
102
|
+
|
103
|
+
# Log failed execution
|
104
|
+
logger.log_function_execution(
|
105
|
+
function_name="test_function",
|
106
|
+
duration_ms=duration_ms,
|
107
|
+
success=False,
|
108
|
+
extra={"error": str(e), "error_type": type(e).__name__},
|
109
|
+
)
|
110
|
+
|
111
|
+
# Return error response
|
112
|
+
return func.HttpResponse(
|
113
|
+
json.dumps({"status": "error", "message": str(e)}),
|
114
|
+
mimetype="application/json",
|
115
|
+
status_code=500,
|
116
|
+
)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
azpaddypy/mgmt/__init__.py,sha256=5-0eZuJMZlCONZNJ5hEvWXfvLIM36mg7FsEVs32bY_A,183
|
2
|
+
azpaddypy/mgmt/logging.py,sha256=jQ1jIkdSf7p44_oBJZD3rPodtwkhY5Y9rwRNafwXgcI,21061
|
3
|
+
azpaddypy/test_function/__init__.py,sha256=0NjUl36wvUWV79GpRwBFkgkBaC6uDZsTdaSVOIHMFEU,3481
|
4
|
+
azpaddypy/test_function/function_app.py,sha256=-vksGicWKPqEmW8TjV2lQW0hOuGFmLxrk_VnP69dz4Q,3681
|
5
|
+
azpaddypy-0.1.6.dist-info/licenses/LICENSE,sha256=hQ6t0g2QaewGCQICHqTckBFbMVakGmoyTAzDpmEYV4c,1089
|
6
|
+
azpaddypy-0.1.6.dist-info/METADATA,sha256=q2nHswCgcUTXSohDCW4JnKHZnpxu5hyZxVR_qlxJ-YM,304
|
7
|
+
azpaddypy-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
azpaddypy-0.1.6.dist-info/top_level.txt,sha256=hsDuboDhT61320ML8X479ezSTwT3rrlDWz1_Z45B2cs,10
|
9
|
+
azpaddypy-0.1.6.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
azpaddypy
|
azpaddypy-0.1.4.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
azpaddypy-0.1.4.dist-info/licenses/LICENSE,sha256=hQ6t0g2QaewGCQICHqTckBFbMVakGmoyTAzDpmEYV4c,1089
|
2
|
-
mgmt/__init__.py,sha256=5-0eZuJMZlCONZNJ5hEvWXfvLIM36mg7FsEVs32bY_A,183
|
3
|
-
mgmt/logging.py,sha256=jQ1jIkdSf7p44_oBJZD3rPodtwkhY5Y9rwRNafwXgcI,21061
|
4
|
-
azpaddypy-0.1.4.dist-info/METADATA,sha256=ygsoFE5Lv2UiAx_QwP6VZFJjSMj2NfKXNyxZW2Rxbh8,304
|
5
|
-
azpaddypy-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
azpaddypy-0.1.4.dist-info/top_level.txt,sha256=Xqg3gg53XEnWtdRarYe2ubJO0NDuer-pkr8RN2y7G-c,5
|
7
|
-
azpaddypy-0.1.4.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
mgmt
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|