netra-zen 1.2.0__py3-none-any.whl → 1.2.1__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.
@@ -1,221 +1,221 @@
1
- #!/usr/bin/env python3
2
- """
3
- Debug script to test apex telemetry and identify why spans aren't appearing in Cloud Trace.
4
- Run this after setting COMMUNITY_CREDENTIALS to diagnose the issue.
5
- """
6
-
7
- import sys
8
- import logging
9
- from pathlib import Path
10
-
11
- # Add project to path
12
- sys.path.insert(0, str(Path(__file__).parent.parent))
13
-
14
- # Enable debug logging
15
- logging.basicConfig(
16
- level=logging.DEBUG,
17
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
18
- )
19
-
20
- def test_telemetry_manager():
21
- """Test that telemetry manager is properly initialized."""
22
- print("=" * 80)
23
- print("TEST 1: Telemetry Manager Initialization")
24
- print("=" * 80)
25
-
26
- from zen.telemetry import telemetry_manager
27
-
28
- print(f"Telemetry manager type: {type(telemetry_manager)}")
29
- print(f"Is enabled: {telemetry_manager.is_enabled()}")
30
-
31
- if hasattr(telemetry_manager, '_tracer'):
32
- print(f"Has _tracer: {telemetry_manager._tracer is not None}")
33
- else:
34
- print("❌ No _tracer attribute")
35
-
36
- if hasattr(telemetry_manager, '_provider'):
37
- print(f"Has _provider: {telemetry_manager._provider is not None}")
38
- else:
39
- print("❌ No _provider attribute")
40
-
41
- print()
42
- return telemetry_manager.is_enabled()
43
-
44
-
45
- def test_apex_wrapper_import():
46
- """Test that apex wrapper can be imported."""
47
- print("=" * 80)
48
- print("TEST 2: Apex Telemetry Wrapper Import")
49
- print("=" * 80)
50
-
51
- try:
52
- from zen.telemetry.apex_telemetry import ApexTelemetryWrapper
53
- print("✅ ApexTelemetryWrapper imported successfully")
54
-
55
- wrapper = ApexTelemetryWrapper()
56
- print(f"✅ Wrapper instance created: {type(wrapper)}")
57
- print()
58
- return True
59
- except Exception as e:
60
- print(f"❌ Failed to import ApexTelemetryWrapper: {e}")
61
- import traceback
62
- traceback.print_exc()
63
- print()
64
- return False
65
-
66
-
67
- def test_manual_span_emission():
68
- """Test manual span emission using telemetry manager."""
69
- print("=" * 80)
70
- print("TEST 3: Manual Span Emission")
71
- print("=" * 80)
72
-
73
- from zen.telemetry import telemetry_manager
74
-
75
- if not telemetry_manager.is_enabled():
76
- print("⚠️ Telemetry is not enabled - skipping test")
77
- print()
78
- return False
79
-
80
- try:
81
- from opentelemetry.trace import SpanKind
82
-
83
- print("Creating test span...")
84
- with telemetry_manager._tracer.start_as_current_span(
85
- "test.apex.span", kind=SpanKind.INTERNAL
86
- ) as span:
87
- span.set_attribute("test.type", "manual")
88
- span.set_attribute("test.value", 123)
89
- print("✅ Span created and attributes set")
90
-
91
- print("Flushing provider...")
92
- if hasattr(telemetry_manager, '_provider') and telemetry_manager._provider:
93
- telemetry_manager._provider.force_flush(timeout_millis=5000)
94
- print("✅ Provider flushed")
95
-
96
- print("✅ Manual span test completed")
97
- print(" Check Cloud Trace for span: 'test.apex.span'")
98
- print()
99
- return True
100
-
101
- except Exception as e:
102
- print(f"❌ Manual span emission failed: {e}")
103
- import traceback
104
- traceback.print_exc()
105
- print()
106
- return False
107
-
108
-
109
- def test_apex_wrapper_emission():
110
- """Test apex wrapper span emission."""
111
- print("=" * 80)
112
- print("TEST 4: Apex Wrapper Span Emission")
113
- print("=" * 80)
114
-
115
- from zen.telemetry.apex_telemetry import ApexTelemetryWrapper
116
-
117
- wrapper = ApexTelemetryWrapper()
118
- wrapper.start_time = 1000.0
119
- wrapper.end_time = 1010.0
120
- wrapper.exit_code = 0
121
- wrapper.message = "test apex telemetry debug"
122
- wrapper.env = "staging"
123
- wrapper.stdout = ""
124
- wrapper.stderr = ""
125
-
126
- print("Emitting telemetry with wrapper...")
127
- try:
128
- wrapper._emit_telemetry()
129
- print("✅ Wrapper._emit_telemetry() completed")
130
- print(" Check Cloud Trace for span: 'apex.instance'")
131
- print()
132
- return True
133
- except Exception as e:
134
- print(f"❌ Wrapper emission failed: {e}")
135
- import traceback
136
- traceback.print_exc()
137
- print()
138
- return False
139
-
140
-
141
- def test_credentials():
142
- """Test credential loading."""
143
- print("=" * 80)
144
- print("TEST 5: Credential Loading")
145
- print("=" * 80)
146
-
147
- from zen.telemetry import get_embedded_credentials, get_project_id
148
-
149
- creds = get_embedded_credentials()
150
- if creds:
151
- print(f"✅ Credentials loaded")
152
- project_id = get_project_id()
153
- print(f"✅ Project ID: {project_id}")
154
- print()
155
- return True
156
- else:
157
- print("❌ No credentials found")
158
- print(" Set COMMUNITY_CREDENTIALS environment variable")
159
- print()
160
- return False
161
-
162
-
163
- def main():
164
- """Run all diagnostic tests."""
165
- print("\n🔍 APEX TELEMETRY DEBUG TESTS")
166
- print("=" * 80)
167
-
168
- results = {}
169
-
170
- results['credentials'] = test_credentials()
171
- results['telemetry_manager'] = test_telemetry_manager()
172
- results['apex_wrapper_import'] = test_apex_wrapper_import()
173
-
174
- if results['telemetry_manager']:
175
- results['manual_span'] = test_manual_span_emission()
176
- results['apex_wrapper'] = test_apex_wrapper_emission()
177
- else:
178
- print("⚠️ Skipping span tests - telemetry not enabled")
179
- results['manual_span'] = False
180
- results['apex_wrapper'] = False
181
-
182
- # Summary
183
- print("=" * 80)
184
- print("SUMMARY")
185
- print("=" * 80)
186
-
187
- for test_name, passed in results.items():
188
- status = "✅ PASS" if passed else "❌ FAIL"
189
- print(f"{status:10} {test_name}")
190
-
191
- print()
192
-
193
- if all(results.values()):
194
- print("✅ ALL TESTS PASSED!")
195
- print("\nIf spans still don't appear in Cloud Trace:")
196
- print(" 1. Wait 60 seconds (BatchSpanProcessor batches spans)")
197
- print(" 2. Check Cloud Trace console")
198
- print(" 3. Verify project ID matches your GCP setup")
199
- print(" 4. Check service account has cloudtrace.traces.patch permission")
200
- return 0
201
- else:
202
- print("❌ SOME TESTS FAILED")
203
- print("\nTroubleshooting:")
204
-
205
- if not results['credentials']:
206
- print(" • Set COMMUNITY_CREDENTIALS: export COMMUNITY_CREDENTIALS='<base64-json>'")
207
-
208
- if not results['telemetry_manager']:
209
- print(" • Telemetry manager not initialized - check credentials")
210
-
211
- if results['telemetry_manager'] and not results['manual_span']:
212
- print(" • Manual span failed - check OpenTelemetry setup")
213
-
214
- if results['telemetry_manager'] and not results['apex_wrapper']:
215
- print(" • Apex wrapper failed - check implementation")
216
-
217
- return 1
218
-
219
-
220
- if __name__ == "__main__":
221
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """
3
+ Debug script to test apex telemetry and identify why spans aren't appearing in Cloud Trace.
4
+ Run this after setting COMMUNITY_CREDENTIALS to diagnose the issue.
5
+ """
6
+
7
+ import sys
8
+ import logging
9
+ from pathlib import Path
10
+
11
+ # Add project to path
12
+ sys.path.insert(0, str(Path(__file__).parent.parent))
13
+
14
+ # Enable debug logging
15
+ logging.basicConfig(
16
+ level=logging.DEBUG,
17
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
18
+ )
19
+
20
+ def test_telemetry_manager():
21
+ """Test that telemetry manager is properly initialized."""
22
+ print("=" * 80)
23
+ print("TEST 1: Telemetry Manager Initialization")
24
+ print("=" * 80)
25
+
26
+ from zen.telemetry import telemetry_manager
27
+
28
+ print(f"Telemetry manager type: {type(telemetry_manager)}")
29
+ print(f"Is enabled: {telemetry_manager.is_enabled()}")
30
+
31
+ if hasattr(telemetry_manager, '_tracer'):
32
+ print(f"Has _tracer: {telemetry_manager._tracer is not None}")
33
+ else:
34
+ print("❌ No _tracer attribute")
35
+
36
+ if hasattr(telemetry_manager, '_provider'):
37
+ print(f"Has _provider: {telemetry_manager._provider is not None}")
38
+ else:
39
+ print("❌ No _provider attribute")
40
+
41
+ print()
42
+ return telemetry_manager.is_enabled()
43
+
44
+
45
+ def test_apex_wrapper_import():
46
+ """Test that apex wrapper can be imported."""
47
+ print("=" * 80)
48
+ print("TEST 2: Apex Telemetry Wrapper Import")
49
+ print("=" * 80)
50
+
51
+ try:
52
+ from zen.telemetry.apex_telemetry import ApexTelemetryWrapper
53
+ print("✅ ApexTelemetryWrapper imported successfully")
54
+
55
+ wrapper = ApexTelemetryWrapper()
56
+ print(f"✅ Wrapper instance created: {type(wrapper)}")
57
+ print()
58
+ return True
59
+ except Exception as e:
60
+ print(f"❌ Failed to import ApexTelemetryWrapper: {e}")
61
+ import traceback
62
+ traceback.print_exc()
63
+ print()
64
+ return False
65
+
66
+
67
+ def test_manual_span_emission():
68
+ """Test manual span emission using telemetry manager."""
69
+ print("=" * 80)
70
+ print("TEST 3: Manual Span Emission")
71
+ print("=" * 80)
72
+
73
+ from zen.telemetry import telemetry_manager
74
+
75
+ if not telemetry_manager.is_enabled():
76
+ print("⚠️ Telemetry is not enabled - skipping test")
77
+ print()
78
+ return False
79
+
80
+ try:
81
+ from opentelemetry.trace import SpanKind
82
+
83
+ print("Creating test span...")
84
+ with telemetry_manager._tracer.start_as_current_span(
85
+ "test.apex.span", kind=SpanKind.INTERNAL
86
+ ) as span:
87
+ span.set_attribute("test.type", "manual")
88
+ span.set_attribute("test.value", 123)
89
+ print("✅ Span created and attributes set")
90
+
91
+ print("Flushing provider...")
92
+ if hasattr(telemetry_manager, '_provider') and telemetry_manager._provider:
93
+ telemetry_manager._provider.force_flush(timeout_millis=5000)
94
+ print("✅ Provider flushed")
95
+
96
+ print("✅ Manual span test completed")
97
+ print(" Check Cloud Trace for span: 'test.apex.span'")
98
+ print()
99
+ return True
100
+
101
+ except Exception as e:
102
+ print(f"❌ Manual span emission failed: {e}")
103
+ import traceback
104
+ traceback.print_exc()
105
+ print()
106
+ return False
107
+
108
+
109
+ def test_apex_wrapper_emission():
110
+ """Test apex wrapper span emission."""
111
+ print("=" * 80)
112
+ print("TEST 4: Apex Wrapper Span Emission")
113
+ print("=" * 80)
114
+
115
+ from zen.telemetry.apex_telemetry import ApexTelemetryWrapper
116
+
117
+ wrapper = ApexTelemetryWrapper()
118
+ wrapper.start_time = 1000.0
119
+ wrapper.end_time = 1010.0
120
+ wrapper.exit_code = 0
121
+ wrapper.message = "test apex telemetry debug"
122
+ wrapper.env = "staging"
123
+ wrapper.stdout = ""
124
+ wrapper.stderr = ""
125
+
126
+ print("Emitting telemetry with wrapper...")
127
+ try:
128
+ wrapper._emit_telemetry()
129
+ print("✅ Wrapper._emit_telemetry() completed")
130
+ print(" Check Cloud Trace for span: 'apex.instance'")
131
+ print()
132
+ return True
133
+ except Exception as e:
134
+ print(f"❌ Wrapper emission failed: {e}")
135
+ import traceback
136
+ traceback.print_exc()
137
+ print()
138
+ return False
139
+
140
+
141
+ def test_credentials():
142
+ """Test credential loading."""
143
+ print("=" * 80)
144
+ print("TEST 5: Credential Loading")
145
+ print("=" * 80)
146
+
147
+ from zen.telemetry import get_embedded_credentials, get_project_id
148
+
149
+ creds = get_embedded_credentials()
150
+ if creds:
151
+ print(f"✅ Credentials loaded")
152
+ project_id = get_project_id()
153
+ print(f"✅ Project ID: {project_id}")
154
+ print()
155
+ return True
156
+ else:
157
+ print("❌ No credentials found")
158
+ print(" Set COMMUNITY_CREDENTIALS environment variable")
159
+ print()
160
+ return False
161
+
162
+
163
+ def main():
164
+ """Run all diagnostic tests."""
165
+ print("\n🔍 APEX TELEMETRY DEBUG TESTS")
166
+ print("=" * 80)
167
+
168
+ results = {}
169
+
170
+ results['credentials'] = test_credentials()
171
+ results['telemetry_manager'] = test_telemetry_manager()
172
+ results['apex_wrapper_import'] = test_apex_wrapper_import()
173
+
174
+ if results['telemetry_manager']:
175
+ results['manual_span'] = test_manual_span_emission()
176
+ results['apex_wrapper'] = test_apex_wrapper_emission()
177
+ else:
178
+ print("⚠️ Skipping span tests - telemetry not enabled")
179
+ results['manual_span'] = False
180
+ results['apex_wrapper'] = False
181
+
182
+ # Summary
183
+ print("=" * 80)
184
+ print("SUMMARY")
185
+ print("=" * 80)
186
+
187
+ for test_name, passed in results.items():
188
+ status = "✅ PASS" if passed else "❌ FAIL"
189
+ print(f"{status:10} {test_name}")
190
+
191
+ print()
192
+
193
+ if all(results.values()):
194
+ print("✅ ALL TESTS PASSED!")
195
+ print("\nIf spans still don't appear in Cloud Trace:")
196
+ print(" 1. Wait 60 seconds (BatchSpanProcessor batches spans)")
197
+ print(" 2. Check Cloud Trace console")
198
+ print(" 3. Verify project ID matches your GCP setup")
199
+ print(" 4. Check service account has cloudtrace.traces.patch permission")
200
+ return 0
201
+ else:
202
+ print("❌ SOME TESTS FAILED")
203
+ print("\nTroubleshooting:")
204
+
205
+ if not results['credentials']:
206
+ print(" • Set COMMUNITY_CREDENTIALS: export COMMUNITY_CREDENTIALS='<base64-json>'")
207
+
208
+ if not results['telemetry_manager']:
209
+ print(" • Telemetry manager not initialized - check credentials")
210
+
211
+ if results['telemetry_manager'] and not results['manual_span']:
212
+ print(" • Manual span failed - check OpenTelemetry setup")
213
+
214
+ if results['telemetry_manager'] and not results['apex_wrapper']:
215
+ print(" • Apex wrapper failed - check implementation")
216
+
217
+ return 1
218
+
219
+
220
+ if __name__ == "__main__":
221
+ sys.exit(main())