provide-foundation 0.0.0.dev1__py3-none-any.whl → 0.0.0.dev2__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.
Files changed (93) hide show
  1. provide/foundation/__init__.py +29 -3
  2. provide/foundation/archive/operations.py +4 -6
  3. provide/foundation/cli/__init__.py +2 -2
  4. provide/foundation/cli/commands/deps.py +13 -7
  5. provide/foundation/cli/commands/logs/__init__.py +1 -1
  6. provide/foundation/cli/commands/logs/query.py +1 -1
  7. provide/foundation/cli/commands/logs/send.py +1 -1
  8. provide/foundation/cli/commands/logs/tail.py +1 -1
  9. provide/foundation/cli/decorators.py +11 -10
  10. provide/foundation/cli/main.py +1 -1
  11. provide/foundation/cli/testing.py +2 -35
  12. provide/foundation/cli/utils.py +21 -17
  13. provide/foundation/config/__init__.py +35 -2
  14. provide/foundation/config/converters.py +479 -0
  15. provide/foundation/config/defaults.py +67 -0
  16. provide/foundation/config/env.py +4 -19
  17. provide/foundation/config/loader.py +9 -3
  18. provide/foundation/console/input.py +5 -5
  19. provide/foundation/console/output.py +35 -13
  20. provide/foundation/context/__init__.py +8 -4
  21. provide/foundation/context/core.py +85 -109
  22. provide/foundation/crypto/certificates/operations.py +1 -1
  23. provide/foundation/errors/__init__.py +2 -3
  24. provide/foundation/errors/decorators.py +0 -231
  25. provide/foundation/errors/types.py +0 -97
  26. provide/foundation/file/directory.py +13 -22
  27. provide/foundation/file/lock.py +3 -1
  28. provide/foundation/hub/components.py +72 -384
  29. provide/foundation/hub/config.py +151 -0
  30. provide/foundation/hub/discovery.py +62 -0
  31. provide/foundation/hub/handlers.py +81 -0
  32. provide/foundation/hub/lifecycle.py +194 -0
  33. provide/foundation/hub/manager.py +4 -4
  34. provide/foundation/hub/processors.py +44 -0
  35. provide/foundation/integrations/__init__.py +11 -0
  36. provide/foundation/{observability → integrations}/openobserve/__init__.py +10 -7
  37. provide/foundation/{observability → integrations}/openobserve/auth.py +1 -1
  38. provide/foundation/{observability → integrations}/openobserve/client.py +12 -12
  39. provide/foundation/{observability → integrations}/openobserve/commands.py +3 -3
  40. provide/foundation/integrations/openobserve/config.py +37 -0
  41. provide/foundation/{observability → integrations}/openobserve/formatters.py +1 -1
  42. provide/foundation/{observability → integrations}/openobserve/otlp.py +1 -1
  43. provide/foundation/{observability → integrations}/openobserve/search.py +2 -2
  44. provide/foundation/{observability → integrations}/openobserve/streaming.py +4 -4
  45. provide/foundation/logger/config/logging.py +68 -298
  46. provide/foundation/logger/config/telemetry.py +41 -121
  47. provide/foundation/logger/setup/coordinator.py +1 -1
  48. provide/foundation/observability/__init__.py +2 -2
  49. provide/foundation/process/__init__.py +9 -0
  50. provide/foundation/process/exit.py +47 -0
  51. provide/foundation/process/lifecycle.py +33 -33
  52. provide/foundation/resilience/__init__.py +35 -0
  53. provide/foundation/resilience/circuit.py +164 -0
  54. provide/foundation/resilience/decorators.py +220 -0
  55. provide/foundation/resilience/fallback.py +193 -0
  56. provide/foundation/resilience/retry.py +325 -0
  57. provide/foundation/streams/config.py +79 -0
  58. provide/foundation/streams/console.py +7 -8
  59. provide/foundation/streams/core.py +6 -3
  60. provide/foundation/streams/file.py +12 -2
  61. provide/foundation/testing/__init__.py +7 -2
  62. provide/foundation/testing/cli.py +30 -17
  63. provide/foundation/testing/common/__init__.py +0 -2
  64. provide/foundation/testing/common/fixtures.py +0 -27
  65. provide/foundation/testing/file/content_fixtures.py +316 -0
  66. provide/foundation/testing/file/directory_fixtures.py +107 -0
  67. provide/foundation/testing/file/fixtures.py +45 -516
  68. provide/foundation/testing/file/special_fixtures.py +153 -0
  69. provide/foundation/testing/logger.py +76 -0
  70. provide/foundation/testing/process/async_fixtures.py +405 -0
  71. provide/foundation/testing/process/fixtures.py +50 -571
  72. provide/foundation/testing/process/subprocess_fixtures.py +209 -0
  73. provide/foundation/testing/threading/basic_fixtures.py +101 -0
  74. provide/foundation/testing/threading/data_fixtures.py +99 -0
  75. provide/foundation/testing/threading/execution_fixtures.py +263 -0
  76. provide/foundation/testing/threading/fixtures.py +34 -500
  77. provide/foundation/testing/threading/sync_fixtures.py +97 -0
  78. provide/foundation/testing/time/fixtures.py +4 -4
  79. provide/foundation/tools/cache.py +8 -6
  80. provide/foundation/tools/downloader.py +23 -12
  81. provide/foundation/tracer/spans.py +2 -2
  82. provide/foundation/transport/config.py +26 -95
  83. provide/foundation/transport/middleware.py +30 -36
  84. provide/foundation/utils/deps.py +14 -12
  85. provide/foundation/utils/parsing.py +49 -4
  86. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/METADATA +1 -1
  87. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/RECORD +93 -68
  88. /provide/foundation/{observability → integrations}/openobserve/exceptions.py +0 -0
  89. /provide/foundation/{observability → integrations}/openobserve/models.py +0 -0
  90. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/WHEEL +0 -0
  91. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/entry_points.txt +0 -0
  92. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/licenses/LICENSE +0 -0
  93. {provide_foundation-0.0.0.dev1.dist-info → provide_foundation-0.0.0.dev2.dist-info}/top_level.txt +0 -0
@@ -5,390 +5,160 @@
5
5
  LoggingConfig class for Foundation logger configuration.
6
6
  """
7
7
 
8
- import json
9
- import os
10
8
  from pathlib import Path
11
9
 
12
10
  from attrs import define
13
11
 
14
- from provide.foundation.config import BaseConfig, field
15
- from provide.foundation.config.types import ConfigSource
16
- from provide.foundation.logger.config.base import get_config_logger
17
- from provide.foundation.eventsets.types import EventMapping, EventSet
12
+ from provide.foundation.config.env import RuntimeConfig
13
+ from provide.foundation.config.base import field
14
+ from provide.foundation.config.defaults import (
15
+ DEFAULT_LOG_LEVEL,
16
+ DEFAULT_CONSOLE_FORMATTER,
17
+ DEFAULT_LOGGER_NAME_EMOJI_ENABLED,
18
+ DEFAULT_DAS_EMOJI_ENABLED,
19
+ DEFAULT_OMIT_TIMESTAMP,
20
+ DEFAULT_FOUNDATION_SETUP_LOG_LEVEL,
21
+ DEFAULT_FOUNDATION_LOG_OUTPUT,
22
+ DEFAULT_RATE_LIMIT_ENABLED,
23
+ DEFAULT_RATE_LIMIT_EMIT_WARNINGS,
24
+ DEFAULT_RATE_LIMIT_GLOBAL,
25
+ DEFAULT_RATE_LIMIT_GLOBAL_CAPACITY,
26
+ DEFAULT_RATE_LIMIT_OVERFLOW_POLICY,
27
+ )
28
+ from provide.foundation.config.converters import (
29
+ parse_bool_extended,
30
+ parse_console_formatter,
31
+ parse_float_with_validation,
32
+ parse_foundation_log_output,
33
+ parse_log_level,
34
+ parse_module_levels,
35
+ parse_rate_limits,
36
+ validate_log_level,
37
+ validate_non_negative,
38
+ validate_overflow_policy,
39
+ validate_positive,
40
+ )
18
41
  from provide.foundation.types import (
19
- _VALID_FORMATTER_TUPLE,
20
- _VALID_LOG_LEVEL_TUPLE,
21
42
  ConsoleFormatterStr,
22
43
  LogLevelStr,
23
44
  )
24
45
 
25
46
 
26
47
  @define(slots=True, repr=False)
27
- class LoggingConfig(BaseConfig):
48
+ class LoggingConfig(RuntimeConfig):
28
49
  """Configuration specific to logging behavior within Foundation Telemetry."""
29
50
 
30
51
  default_level: LogLevelStr = field(
31
- default="WARNING",
52
+ default=DEFAULT_LOG_LEVEL,
32
53
  env_var="PROVIDE_LOG_LEVEL",
54
+ converter=parse_log_level,
55
+ validator=validate_log_level,
33
56
  description="Default logging level",
34
57
  )
35
58
  module_levels: dict[str, LogLevelStr] = field(
36
59
  factory=lambda: {},
37
60
  env_var="PROVIDE_LOG_MODULE_LEVELS",
61
+ converter=parse_module_levels,
38
62
  description="Per-module log levels (format: module1:LEVEL,module2:LEVEL)",
39
63
  )
40
64
  console_formatter: ConsoleFormatterStr = field(
41
- default="key_value",
65
+ default=DEFAULT_CONSOLE_FORMATTER,
42
66
  env_var="PROVIDE_LOG_CONSOLE_FORMATTER",
67
+ converter=parse_console_formatter,
43
68
  description="Console output formatter (key_value or json)",
44
69
  )
45
70
  logger_name_emoji_prefix_enabled: bool = field(
46
- default=True,
71
+ default=DEFAULT_LOGGER_NAME_EMOJI_ENABLED,
47
72
  env_var="PROVIDE_LOG_LOGGER_NAME_EMOJI_ENABLED",
73
+ converter=parse_bool_extended,
48
74
  description="Enable emoji prefixes based on logger names",
49
75
  )
50
76
  das_emoji_prefix_enabled: bool = field(
51
- default=True,
77
+ default=DEFAULT_DAS_EMOJI_ENABLED,
52
78
  env_var="PROVIDE_LOG_DAS_EMOJI_ENABLED",
79
+ converter=parse_bool_extended,
53
80
  description="Enable Domain-Action-Status emoji prefixes",
54
81
  )
55
82
  omit_timestamp: bool = field(
56
- default=False,
83
+ default=DEFAULT_OMIT_TIMESTAMP,
57
84
  env_var="PROVIDE_LOG_OMIT_TIMESTAMP",
85
+ converter=parse_bool_extended,
58
86
  description="Omit timestamps from console output",
59
87
  )
60
- enabled_emoji_sets: list[str] = field(
61
- factory=lambda: [],
62
- env_var="PROVIDE_LOG_ENABLED_EMOJI_SETS",
63
- description="Comma-separated list of emoji sets to enable",
64
- )
65
- custom_emoji_sets: list[EventSet] = field(
66
- factory=lambda: [],
67
- env_var="PROVIDE_LOG_CUSTOM_EMOJI_SETS",
68
- description="JSON array of custom emoji set configurations",
69
- )
70
- user_defined_emoji_sets: list[EventMapping] = field(
71
- factory=lambda: [],
72
- env_var="PROVIDE_LOG_USER_DEFINED_EMOJI_SETS",
73
- description="JSON array of user-defined emoji sets",
74
- )
88
+ # Event sets have replaced emoji sets - these fields are deprecated
75
89
  log_file: Path | None = field(
76
- default=None, env_var="PROVIDE_LOG_FILE", description="Path to log file"
90
+ default=None,
91
+ env_var="PROVIDE_LOG_FILE",
92
+ converter=lambda x: Path(x) if x else None,
93
+ description="Path to log file"
77
94
  )
78
95
  foundation_setup_log_level: LogLevelStr = field(
79
- default="INFO",
96
+ default=DEFAULT_FOUNDATION_SETUP_LOG_LEVEL,
80
97
  env_var="FOUNDATION_LOG_LEVEL",
98
+ converter=parse_log_level,
99
+ validator=validate_log_level,
81
100
  description="Log level for Foundation internal setup messages",
82
101
  )
83
102
  foundation_log_output: str = field(
84
- default="stderr",
103
+ default=DEFAULT_FOUNDATION_LOG_OUTPUT,
85
104
  env_var="FOUNDATION_LOG_OUTPUT",
105
+ converter=parse_foundation_log_output,
86
106
  description="Output destination for Foundation internal messages (stderr, stdout, main)",
87
107
  )
88
- show_emoji_matrix: bool = field(
89
- default=False,
90
- env_var="PROVIDE_SHOW_EMOJI_MATRIX",
91
- description="Whether to display emoji matrix on startup",
92
- )
93
108
  rate_limit_enabled: bool = field(
94
- default=False,
109
+ default=DEFAULT_RATE_LIMIT_ENABLED,
95
110
  env_var="PROVIDE_LOG_RATE_LIMIT_ENABLED",
111
+ converter=parse_bool_extended,
96
112
  description="Enable rate limiting for log output",
97
113
  )
98
114
  rate_limit_global: float | None = field(
99
115
  default=None,
100
116
  env_var="PROVIDE_LOG_RATE_LIMIT_GLOBAL",
117
+ converter=lambda x: parse_float_with_validation(x, min_val=0.0) if x else None,
101
118
  description="Global rate limit (logs per second)",
102
119
  )
103
120
  rate_limit_global_capacity: float | None = field(
104
121
  default=None,
105
122
  env_var="PROVIDE_LOG_RATE_LIMIT_GLOBAL_CAPACITY",
123
+ converter=lambda x: parse_float_with_validation(x, min_val=0.0) if x else None,
106
124
  description="Global rate limit burst capacity",
107
125
  )
108
126
  rate_limit_per_logger: dict[str, tuple[float, float]] = field(
109
127
  factory=lambda: {},
110
128
  env_var="PROVIDE_LOG_RATE_LIMIT_PER_LOGGER",
129
+ converter=parse_rate_limits,
111
130
  description="Per-logger rate limits (format: logger1:rate:capacity,logger2:rate:capacity)",
112
131
  )
113
132
  rate_limit_emit_warnings: bool = field(
114
- default=True,
133
+ default=DEFAULT_RATE_LIMIT_EMIT_WARNINGS,
115
134
  env_var="PROVIDE_LOG_RATE_LIMIT_EMIT_WARNINGS",
135
+ converter=parse_bool_extended,
116
136
  description="Emit warnings when logs are rate limited",
117
137
  )
118
138
  rate_limit_summary_interval: float = field(
119
- default=5.0,
139
+ default=DEFAULT_RATE_LIMIT_GLOBAL,
120
140
  env_var="PROVIDE_LOG_RATE_LIMIT_SUMMARY_INTERVAL",
141
+ converter=lambda x: parse_float_with_validation(x, min_val=0.0) if x else DEFAULT_RATE_LIMIT_GLOBAL,
142
+ validator=validate_positive,
121
143
  description="Seconds between rate limit summary reports",
122
144
  )
123
145
  rate_limit_max_queue_size: int = field(
124
- default=1000,
146
+ default=DEFAULT_RATE_LIMIT_GLOBAL_CAPACITY,
125
147
  env_var="PROVIDE_LOG_RATE_LIMIT_MAX_QUEUE_SIZE",
148
+ converter=int,
149
+ validator=validate_positive,
126
150
  description="Maximum number of logs to queue when rate limited",
127
151
  )
128
152
  rate_limit_max_memory_mb: float | None = field(
129
153
  default=None,
130
154
  env_var="PROVIDE_LOG_RATE_LIMIT_MAX_MEMORY_MB",
155
+ converter=lambda x: parse_float_with_validation(x, min_val=0.0) if x else None,
131
156
  description="Maximum memory (MB) for queued logs",
132
157
  )
133
158
  rate_limit_overflow_policy: str = field(
134
- default="drop_oldest",
159
+ default=DEFAULT_RATE_LIMIT_OVERFLOW_POLICY,
135
160
  env_var="PROVIDE_LOG_RATE_LIMIT_OVERFLOW_POLICY",
161
+ validator=validate_overflow_policy,
136
162
  description="Policy when queue is full: drop_oldest, drop_newest, or block",
137
163
  )
138
164
 
139
- @classmethod
140
- def from_env(cls, strict: bool = True) -> "LoggingConfig":
141
- """Load LoggingConfig from environment variables."""
142
- config_dict = {}
143
-
144
- # Parse standard fields
145
- if level := os.getenv("PROVIDE_LOG_LEVEL"):
146
- level = level.upper()
147
- if level in _VALID_LOG_LEVEL_TUPLE:
148
- config_dict["default_level"] = level
149
- elif strict:
150
- get_config_logger().warning(
151
- "[Foundation Config Warning] Invalid configuration value, using default",
152
- config_key="PROVIDE_LOG_LEVEL",
153
- invalid_value=level,
154
- valid_options=list(_VALID_LOG_LEVEL_TUPLE),
155
- default_value="DEBUG",
156
- )
157
-
158
- if formatter := os.getenv("PROVIDE_LOG_CONSOLE_FORMATTER"):
159
- formatter = formatter.lower()
160
- if formatter in _VALID_FORMATTER_TUPLE:
161
- config_dict["console_formatter"] = formatter
162
- elif strict:
163
- get_config_logger().warning(
164
- "[Foundation Config Warning] Invalid configuration value, using default",
165
- config_key="PROVIDE_LOG_CONSOLE_FORMATTER",
166
- invalid_value=formatter,
167
- valid_options=list(_VALID_FORMATTER_TUPLE),
168
- default_value="key_value",
169
- )
170
-
171
- if omit_ts := os.getenv("PROVIDE_LOG_OMIT_TIMESTAMP"):
172
- config_dict["omit_timestamp"] = omit_ts.lower() == "true"
173
-
174
- if logger_emoji := os.getenv("PROVIDE_LOG_LOGGER_NAME_EMOJI_ENABLED"):
175
- config_dict["logger_name_emoji_prefix_enabled"] = (
176
- logger_emoji.lower() == "true"
177
- )
178
-
179
- if das_emoji := os.getenv("PROVIDE_LOG_DAS_EMOJI_ENABLED"):
180
- config_dict["das_emoji_prefix_enabled"] = das_emoji.lower() == "true"
181
-
182
- if log_file := os.getenv("PROVIDE_LOG_FILE"):
183
- config_dict["log_file"] = Path(log_file)
184
-
185
- if foundation_level := os.getenv("FOUNDATION_LOG_LEVEL"):
186
- foundation_level = foundation_level.upper()
187
- if foundation_level in _VALID_LOG_LEVEL_TUPLE:
188
- config_dict["foundation_setup_log_level"] = foundation_level
189
- elif strict:
190
- get_config_logger().warning(
191
- "[Foundation Config Warning] Invalid configuration value, using default",
192
- config_key="FOUNDATION_LOG_LEVEL",
193
- invalid_value=foundation_level,
194
- valid_options=list(_VALID_LOG_LEVEL_TUPLE),
195
- default_value="INFO",
196
- )
197
-
198
- if foundation_output := os.getenv("FOUNDATION_LOG_OUTPUT"):
199
- foundation_output = foundation_output.lower()
200
- valid_outputs = ("stderr", "stdout", "main")
201
- if foundation_output in valid_outputs:
202
- config_dict["foundation_log_output"] = foundation_output
203
- elif strict:
204
- get_config_logger().warning(
205
- "[Foundation Config Warning] Invalid configuration value, using default",
206
- config_key="FOUNDATION_LOG_OUTPUT",
207
- invalid_value=foundation_output,
208
- valid_options=list(valid_outputs),
209
- default_value="stderr",
210
- )
211
-
212
- if show_matrix := os.getenv("PROVIDE_SHOW_EMOJI_MATRIX"):
213
- config_dict["show_emoji_matrix"] = show_matrix.strip().lower() in (
214
- "true",
215
- "1",
216
- "yes",
217
- )
218
-
219
- # Parse rate limiting configuration
220
- if rate_limit_enabled := os.getenv("PROVIDE_LOG_RATE_LIMIT_ENABLED"):
221
- config_dict["rate_limit_enabled"] = rate_limit_enabled.lower() == "true"
222
-
223
- if rate_limit_global := os.getenv("PROVIDE_LOG_RATE_LIMIT_GLOBAL"):
224
- try:
225
- config_dict["rate_limit_global"] = float(rate_limit_global)
226
- except ValueError:
227
- if strict:
228
- get_config_logger().warning(
229
- "[Foundation Config Warning] Invalid rate limit value",
230
- config_key="PROVIDE_LOG_RATE_LIMIT_GLOBAL",
231
- invalid_value=rate_limit_global,
232
- )
233
-
234
- if rate_limit_capacity := os.getenv("PROVIDE_LOG_RATE_LIMIT_GLOBAL_CAPACITY"):
235
- try:
236
- config_dict["rate_limit_global_capacity"] = float(rate_limit_capacity)
237
- except ValueError:
238
- if strict:
239
- get_config_logger().warning(
240
- "[Foundation Config Warning] Invalid rate limit capacity",
241
- config_key="PROVIDE_LOG_RATE_LIMIT_GLOBAL_CAPACITY",
242
- invalid_value=rate_limit_capacity,
243
- )
244
-
245
- if per_logger_limits := os.getenv("PROVIDE_LOG_RATE_LIMIT_PER_LOGGER"):
246
- limits_dict = {}
247
- for item in per_logger_limits.split(","):
248
- parts = item.split(":")
249
- if len(parts) == 3:
250
- logger_name, rate, capacity = parts
251
- try:
252
- limits_dict[logger_name.strip()] = (
253
- float(rate.strip()),
254
- float(capacity.strip()),
255
- )
256
- except ValueError:
257
- if strict:
258
- get_config_logger().warning(
259
- "[Foundation Config Warning] Invalid per-logger rate limit",
260
- config_key="PROVIDE_LOG_RATE_LIMIT_PER_LOGGER",
261
- invalid_item=item,
262
- )
263
- if limits_dict:
264
- config_dict["rate_limit_per_logger"] = limits_dict
265
-
266
- if emit_warnings := os.getenv("PROVIDE_LOG_RATE_LIMIT_EMIT_WARNINGS"):
267
- config_dict["rate_limit_emit_warnings"] = emit_warnings.lower() == "true"
268
-
269
- if summary_interval := os.getenv("PROVIDE_LOG_RATE_LIMIT_SUMMARY_INTERVAL"):
270
- try:
271
- config_dict["rate_limit_summary_interval"] = float(summary_interval)
272
- except ValueError:
273
- if strict:
274
- get_config_logger().warning(
275
- "[Foundation Config Warning] Invalid summary interval",
276
- config_key="PROVIDE_LOG_RATE_LIMIT_SUMMARY_INTERVAL",
277
- invalid_value=summary_interval,
278
- )
279
-
280
- if max_queue := os.getenv("PROVIDE_LOG_RATE_LIMIT_MAX_QUEUE_SIZE"):
281
- try:
282
- config_dict["rate_limit_max_queue_size"] = int(max_queue)
283
- except ValueError:
284
- if strict:
285
- get_config_logger().warning(
286
- "[Foundation Config Warning] Invalid max queue size",
287
- config_key="PROVIDE_LOG_RATE_LIMIT_MAX_QUEUE_SIZE",
288
- invalid_value=max_queue,
289
- )
290
-
291
- if max_memory := os.getenv("PROVIDE_LOG_RATE_LIMIT_MAX_MEMORY_MB"):
292
- try:
293
- config_dict["rate_limit_max_memory_mb"] = float(max_memory)
294
- except ValueError:
295
- if strict:
296
- get_config_logger().warning(
297
- "[Foundation Config Warning] Invalid max memory",
298
- config_key="PROVIDE_LOG_RATE_LIMIT_MAX_MEMORY_MB",
299
- invalid_value=max_memory,
300
- )
301
-
302
- if overflow_policy := os.getenv("PROVIDE_LOG_RATE_LIMIT_OVERFLOW_POLICY"):
303
- valid_policies = ("drop_oldest", "drop_newest", "block")
304
- if overflow_policy in valid_policies:
305
- config_dict["rate_limit_overflow_policy"] = overflow_policy
306
- elif strict:
307
- get_config_logger().warning(
308
- "[Foundation Config Warning] Invalid overflow policy",
309
- config_key="PROVIDE_LOG_RATE_LIMIT_OVERFLOW_POLICY",
310
- invalid_value=overflow_policy,
311
- valid_options=list(valid_policies),
312
- )
313
-
314
- # Parse complex fields
315
- if module_levels := os.getenv("PROVIDE_LOG_MODULE_LEVELS"):
316
- levels_dict = {}
317
- for item in module_levels.split(","):
318
- if ":" in item:
319
- module, level = item.split(":", 1)
320
- module = module.strip()
321
- level = level.strip().upper()
322
- if module and level in _VALID_LOG_LEVEL_TUPLE:
323
- levels_dict[module] = level
324
- elif strict and module and level not in _VALID_LOG_LEVEL_TUPLE:
325
- get_config_logger().warning(
326
- "[Foundation Config Warning] Invalid module log level, skipping",
327
- config_key="PROVIDE_LOG_MODULE_LEVELS",
328
- module_name=module,
329
- invalid_level=level,
330
- valid_options=list(_VALID_LOG_LEVEL_TUPLE),
331
- )
332
- if levels_dict:
333
- config_dict["module_levels"] = levels_dict
334
-
335
- if emoji_sets := os.getenv("PROVIDE_LOG_ENABLED_EMOJI_SETS"):
336
- config_dict["enabled_emoji_sets"] = [
337
- s.strip() for s in emoji_sets.split(",") if s.strip()
338
- ]
339
-
340
- if custom_sets := os.getenv("PROVIDE_LOG_CUSTOM_EMOJI_SETS"):
341
- try:
342
- parsed = json.loads(custom_sets)
343
- if isinstance(parsed, list):
344
- config_dict["custom_emoji_sets"] = [
345
- EventSet(**item) if isinstance(item, dict) else item
346
- for item in parsed
347
- ]
348
- except json.JSONDecodeError as e:
349
- if strict:
350
- get_config_logger().warning(
351
- "[Foundation Config Warning] Invalid JSON in configuration",
352
- config_key="PROVIDE_LOG_CUSTOM_EMOJI_SETS",
353
- error=str(e),
354
- config_value=custom_sets[:100] + "..."
355
- if len(custom_sets) > 100
356
- else custom_sets,
357
- )
358
- except (TypeError, ValueError) as e:
359
- if strict:
360
- get_config_logger().warning(
361
- "[Foundation Config Warning] Error parsing custom emoji set configuration",
362
- config_key="PROVIDE_LOG_CUSTOM_EMOJI_SETS",
363
- error=str(e),
364
- error_type=type(e).__name__,
365
- )
366
-
367
- if user_sets := os.getenv("PROVIDE_LOG_USER_DEFINED_EMOJI_SETS"):
368
- try:
369
- parsed = json.loads(user_sets)
370
- if isinstance(parsed, list):
371
- config_dict["user_defined_emoji_sets"] = [
372
- EventMapping(**item) if isinstance(item, dict) else item
373
- for item in parsed
374
- ]
375
- except json.JSONDecodeError as e:
376
- if strict:
377
- get_config_logger().warning(
378
- "[Foundation Config Warning] Invalid JSON in configuration",
379
- config_key="PROVIDE_LOG_USER_DEFINED_EMOJI_SETS",
380
- error=str(e),
381
- config_value=user_sets[:100] + "..."
382
- if len(user_sets) > 100
383
- else user_sets,
384
- )
385
- except (TypeError, ValueError) as e:
386
- if strict:
387
- get_config_logger().warning(
388
- "[Foundation Config Warning] Error parsing user emoji set configuration",
389
- config_key="PROVIDE_LOG_USER_DEFINED_EMOJI_SETS",
390
- error=str(e),
391
- error_type=type(e).__name__,
392
- )
393
-
394
- return cls.from_dict(config_dict, source=ConfigSource.ENV)
@@ -5,22 +5,39 @@
5
5
  TelemetryConfig class for Foundation telemetry configuration.
6
6
  """
7
7
 
8
- import os
9
-
10
8
  from attrs import define
11
9
 
12
- from provide.foundation.config import BaseConfig, field
10
+ from provide.foundation.config.env import RuntimeConfig
11
+ from provide.foundation.config.base import field
12
+ from provide.foundation.config.defaults import (
13
+ DEFAULT_TELEMETRY_GLOBALLY_DISABLED,
14
+ DEFAULT_TRACING_ENABLED,
15
+ DEFAULT_METRICS_ENABLED,
16
+ DEFAULT_OTLP_PROTOCOL,
17
+ DEFAULT_TRACE_SAMPLE_RATE,
18
+ )
19
+ import os
20
+ from provide.foundation.config.converters import (
21
+ parse_bool_extended,
22
+ parse_headers,
23
+ parse_sample_rate,
24
+ validate_sample_rate,
25
+ )
13
26
  from provide.foundation.logger.config.logging import LoggingConfig
14
27
 
15
28
 
29
+ def _get_service_name() -> str | None:
30
+ """Get service name from OTEL_SERVICE_NAME or PROVIDE_SERVICE_NAME (OTEL takes precedence)."""
31
+ return os.getenv("OTEL_SERVICE_NAME") or os.getenv("PROVIDE_SERVICE_NAME")
32
+
33
+
16
34
  @define(slots=True, repr=False)
17
- class TelemetryConfig(BaseConfig):
35
+ class TelemetryConfig(RuntimeConfig):
18
36
  """Main configuration object for the Foundation Telemetry system."""
19
37
 
20
38
  service_name: str | None = field(
21
- default=None,
22
- env_var="PROVIDE_SERVICE_NAME",
23
- description="Service name for telemetry",
39
+ factory=_get_service_name,
40
+ description="Service name for telemetry (from OTEL_SERVICE_NAME or PROVIDE_SERVICE_NAME)",
24
41
  )
25
42
  service_version: str | None = field(
26
43
  default=None,
@@ -28,23 +45,27 @@ class TelemetryConfig(BaseConfig):
28
45
  description="Service version for telemetry",
29
46
  )
30
47
  logging: LoggingConfig = field(
31
- factory=LoggingConfig, description="Logging configuration"
48
+ factory=lambda: LoggingConfig.from_env(),
49
+ description="Logging configuration"
32
50
  )
33
51
  globally_disabled: bool = field(
34
- default=False,
52
+ default=DEFAULT_TELEMETRY_GLOBALLY_DISABLED,
35
53
  env_var="PROVIDE_TELEMETRY_DISABLED",
54
+ converter=parse_bool_extended,
36
55
  description="Globally disable telemetry",
37
56
  )
38
57
 
39
58
  # OpenTelemetry configuration
40
59
  tracing_enabled: bool = field(
41
- default=True,
60
+ default=DEFAULT_TRACING_ENABLED,
42
61
  env_var="OTEL_TRACING_ENABLED",
62
+ converter=parse_bool_extended,
43
63
  description="Enable OpenTelemetry tracing",
44
64
  )
45
65
  metrics_enabled: bool = field(
46
- default=True,
66
+ default=DEFAULT_METRICS_ENABLED,
47
67
  env_var="OTEL_METRICS_ENABLED",
68
+ converter=parse_bool_extended,
48
69
  description="Enable OpenTelemetry metrics",
49
70
  )
50
71
  otlp_endpoint: str | None = field(
@@ -57,132 +78,31 @@ class TelemetryConfig(BaseConfig):
57
78
  env_var="OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
58
79
  description="OTLP endpoint specifically for traces",
59
80
  )
60
- otlp_headers: str | None = field(
61
- default=None,
81
+ otlp_headers: dict[str, str] = field(
82
+ factory=lambda: {},
62
83
  env_var="OTEL_EXPORTER_OTLP_HEADERS",
84
+ converter=parse_headers,
63
85
  description="Headers to send with OTLP requests (key1=value1,key2=value2)",
64
86
  )
65
87
  otlp_protocol: str = field(
66
- default="http/protobuf",
88
+ default=DEFAULT_OTLP_PROTOCOL,
67
89
  env_var="OTEL_EXPORTER_OTLP_PROTOCOL",
68
90
  description="OTLP protocol (grpc, http/protobuf)",
69
91
  )
70
92
  trace_sample_rate: float = field(
71
- default=1.0,
93
+ default=DEFAULT_TRACE_SAMPLE_RATE,
72
94
  env_var="OTEL_TRACE_SAMPLE_RATE",
95
+ converter=parse_sample_rate,
96
+ validator=validate_sample_rate,
73
97
  description="Sampling rate for traces (0.0 to 1.0)",
74
98
  )
75
99
 
76
- # OpenObserve configuration
77
- openobserve_url: str | None = field(
78
- default=None,
79
- env_var="OPENOBSERVE_URL",
80
- description="OpenObserve API endpoint URL",
81
- )
82
- openobserve_org: str = field(
83
- default="default",
84
- env_var="OPENOBSERVE_ORG",
85
- description="OpenObserve organization name",
86
- )
87
- openobserve_user: str | None = field(
88
- default=None,
89
- env_var="OPENOBSERVE_USER",
90
- description="OpenObserve username for authentication",
91
- )
92
- openobserve_password: str | None = field(
93
- default=None,
94
- env_var="OPENOBSERVE_PASSWORD",
95
- description="OpenObserve password for authentication",
96
- )
97
- openobserve_stream: str = field(
98
- default="default",
99
- env_var="OPENOBSERVE_STREAM",
100
- description="Default OpenObserve stream name",
101
- )
102
-
103
- @classmethod
104
- def from_env(cls, strict: bool = True) -> "TelemetryConfig":
105
- """Creates a TelemetryConfig instance from environment variables."""
106
- config_dict = {}
107
-
108
- # Check OTEL_SERVICE_NAME first, then PROVIDE_SERVICE_NAME
109
- service_name = os.getenv("OTEL_SERVICE_NAME") or os.getenv(
110
- "PROVIDE_SERVICE_NAME"
111
- )
112
- if service_name:
113
- config_dict["service_name"] = service_name
114
100
 
115
- # Service version
116
- service_version = os.getenv("OTEL_SERVICE_VERSION") or os.getenv(
117
- "PROVIDE_SERVICE_VERSION"
118
- )
119
- if service_version:
120
- config_dict["service_version"] = service_version
121
-
122
- # Telemetry disable flag
123
- if disabled := os.getenv("PROVIDE_TELEMETRY_DISABLED"):
124
- config_dict["globally_disabled"] = disabled.lower() == "true"
125
-
126
- # OpenTelemetry specific configuration
127
- if tracing_enabled := os.getenv("OTEL_TRACING_ENABLED"):
128
- config_dict["tracing_enabled"] = tracing_enabled.lower() == "true"
129
-
130
- if metrics_enabled := os.getenv("OTEL_METRICS_ENABLED"):
131
- config_dict["metrics_enabled"] = metrics_enabled.lower() == "true"
132
-
133
- if otlp_endpoint := os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):
134
- config_dict["otlp_endpoint"] = otlp_endpoint
135
-
136
- if otlp_traces_endpoint := os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"):
137
- config_dict["otlp_traces_endpoint"] = otlp_traces_endpoint
138
-
139
- if otlp_headers := os.getenv("OTEL_EXPORTER_OTLP_HEADERS"):
140
- config_dict["otlp_headers"] = otlp_headers
141
-
142
- if otlp_protocol := os.getenv("OTEL_EXPORTER_OTLP_PROTOCOL"):
143
- config_dict["otlp_protocol"] = otlp_protocol
144
-
145
- if trace_sample_rate := os.getenv("OTEL_TRACE_SAMPLE_RATE"):
146
- try:
147
- config_dict["trace_sample_rate"] = float(trace_sample_rate)
148
- except ValueError:
149
- if strict:
150
- raise
151
- # Use default value in non-strict mode
152
-
153
- # OpenObserve configuration
154
- if openobserve_url := os.getenv("OPENOBSERVE_URL"):
155
- config_dict["openobserve_url"] = openobserve_url
156
-
157
- if openobserve_org := os.getenv("OPENOBSERVE_ORG"):
158
- config_dict["openobserve_org"] = openobserve_org
159
-
160
- if openobserve_user := os.getenv("OPENOBSERVE_USER"):
161
- config_dict["openobserve_user"] = openobserve_user
162
-
163
- if openobserve_password := os.getenv("OPENOBSERVE_PASSWORD"):
164
- config_dict["openobserve_password"] = openobserve_password
165
-
166
- if openobserve_stream := os.getenv("OPENOBSERVE_STREAM"):
167
- config_dict["openobserve_stream"] = openobserve_stream
168
-
169
- # Load logging config from env
170
- config_dict["logging"] = LoggingConfig.from_env(strict=strict)
171
-
172
- return cls(**config_dict)
173
101
 
174
102
  def get_otlp_headers_dict(self) -> dict[str, str]:
175
- """Parse OTLP headers string into dictionary.
103
+ """Get OTLP headers dictionary.
176
104
 
177
105
  Returns:
178
106
  Dictionary of header key-value pairs
179
107
  """
180
- if not self.otlp_headers:
181
- return {}
182
-
183
- headers = {}
184
- for pair in self.otlp_headers.split(","):
185
- if "=" in pair:
186
- key, value = pair.split("=", 1)
187
- headers[key.strip()] = value.strip()
188
- return headers
108
+ return self.otlp_headers
@@ -72,7 +72,7 @@ def create_foundation_internal_logger(globally_disabled: bool = False) -> Any:
72
72
  else:
73
73
  # Get the foundation log output stream
74
74
  try:
75
- logging_config = LoggingConfig.from_env(strict=False)
75
+ logging_config = LoggingConfig.from_env()
76
76
  foundation_stream = get_foundation_log_stream(
77
77
  logging_config.foundation_log_output
78
78
  )