otel-utils 1.1.6__tar.gz → 1.1.8__tar.gz
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.
Potentially problematic release.
This version of otel-utils might be problematic. Click here for more details.
- {otel_utils-1.1.6 → otel_utils-1.1.8}/PKG-INFO +31 -8
- {otel_utils-1.1.6 → otel_utils-1.1.8}/README.md +30 -7
- {otel_utils-1.1.6 → otel_utils-1.1.8}/pyproject.toml +1 -1
- {otel_utils-1.1.6 → otel_utils-1.1.8}/src/otel_utils/__init__.py +0 -0
- {otel_utils-1.1.6 → otel_utils-1.1.8}/src/otel_utils/configurator.py +0 -0
- {otel_utils-1.1.6 → otel_utils-1.1.8}/src/otel_utils/logging.py +0 -0
- {otel_utils-1.1.6 → otel_utils-1.1.8}/src/otel_utils/metrics.py +0 -0
- {otel_utils-1.1.6 → otel_utils-1.1.8}/src/otel_utils/tracing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: otel-utils
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.8
|
|
4
4
|
Summary: Utilidades simplificadas para instrumentación con OpenTelemetry
|
|
5
5
|
License: Proprietary
|
|
6
6
|
Author: Harold Portocarrero
|
|
@@ -58,6 +58,7 @@ config = OtelConfig(
|
|
|
58
58
|
metric_export_interval_ms=30000, # Metrics export interval
|
|
59
59
|
log_level=logging.INFO, # Logging level
|
|
60
60
|
enable_console_logging=True, # Enable console logging
|
|
61
|
+
json_logging=True, # Use JSON format for logs (default: True)
|
|
61
62
|
additional_resources={ # Optional additional resources
|
|
62
63
|
"deployment.region": "us-east-1",
|
|
63
64
|
"team.name": "backend"
|
|
@@ -73,16 +74,21 @@ from otel_utils import Tracer
|
|
|
73
74
|
|
|
74
75
|
tracer = Tracer("my-service")
|
|
75
76
|
|
|
76
|
-
# Using the decorator
|
|
77
|
+
# Using the decorator (auto-handles errors and status)
|
|
77
78
|
@tracer.trace("my_operation")
|
|
78
79
|
async def my_function():
|
|
79
80
|
# Your code here
|
|
80
81
|
pass
|
|
81
82
|
|
|
82
|
-
# Using the context manager
|
|
83
|
+
# Using the context manager for custom spans
|
|
83
84
|
with tracer.create_span("my_operation") as span:
|
|
84
85
|
span.set_attribute("key", "value")
|
|
85
86
|
# Your code here
|
|
87
|
+
|
|
88
|
+
# Using start_as_current_span for context propagation
|
|
89
|
+
with tracer.start_as_current_span("parent_span") as span:
|
|
90
|
+
# Operations here will be associated with parent_span
|
|
91
|
+
pass
|
|
86
92
|
```
|
|
87
93
|
|
|
88
94
|
### Metrics
|
|
@@ -95,21 +101,38 @@ metrics = Metrics("my-service")
|
|
|
95
101
|
counter = metrics.get_counter("requests_total")
|
|
96
102
|
counter.add(1, {"endpoint": "/api/v1/resource"})
|
|
97
103
|
|
|
98
|
-
# Histogram for latencies
|
|
99
|
-
with metrics.measure_duration("request_duration"):
|
|
104
|
+
# Histogram for latencies using a context manager
|
|
105
|
+
with metrics.measure_duration("request_duration", attributes={"method": "GET"}):
|
|
100
106
|
# Your code here
|
|
101
107
|
pass
|
|
108
|
+
|
|
109
|
+
# Asynchronous metrics (Observable Gauge)
|
|
110
|
+
def get_system_load():
|
|
111
|
+
return 0.5 # Calculated value
|
|
112
|
+
|
|
113
|
+
metrics.observe_async(
|
|
114
|
+
name="system_load",
|
|
115
|
+
description="Current system load",
|
|
116
|
+
callback=get_system_load
|
|
117
|
+
)
|
|
102
118
|
```
|
|
103
119
|
|
|
104
120
|
### Structured Logging
|
|
121
|
+
The library provides a `StructuredLogger` that outputs logs in JSON format (when `json_logging` is enabled) and automatically includes tracing context.
|
|
122
|
+
|
|
105
123
|
```python
|
|
106
124
|
from otel_utils import StructuredLogger
|
|
107
125
|
|
|
108
|
-
logger = StructuredLogger("my-service")
|
|
126
|
+
logger = StructuredLogger("my-service", environment="production")
|
|
109
127
|
|
|
110
|
-
|
|
128
|
+
# Using operation_context to auto-log start/end/errors
|
|
129
|
+
with logger.operation_context("process_order", order_id="123", customer_type="vip"):
|
|
111
130
|
logger.info("Starting processing")
|
|
112
|
-
#
|
|
131
|
+
# If an exception is raised here, it will be logged with status="failed"
|
|
132
|
+
# and the error message will be included in the JSON log.
|
|
133
|
+
|
|
134
|
+
# Manual logging with extra context
|
|
135
|
+
logger.info("Event occurred", action="login", user="user123")
|
|
113
136
|
```
|
|
114
137
|
|
|
115
138
|
## OpenTelemetry Collector Integration
|
|
@@ -32,6 +32,7 @@ config = OtelConfig(
|
|
|
32
32
|
metric_export_interval_ms=30000, # Metrics export interval
|
|
33
33
|
log_level=logging.INFO, # Logging level
|
|
34
34
|
enable_console_logging=True, # Enable console logging
|
|
35
|
+
json_logging=True, # Use JSON format for logs (default: True)
|
|
35
36
|
additional_resources={ # Optional additional resources
|
|
36
37
|
"deployment.region": "us-east-1",
|
|
37
38
|
"team.name": "backend"
|
|
@@ -47,16 +48,21 @@ from otel_utils import Tracer
|
|
|
47
48
|
|
|
48
49
|
tracer = Tracer("my-service")
|
|
49
50
|
|
|
50
|
-
# Using the decorator
|
|
51
|
+
# Using the decorator (auto-handles errors and status)
|
|
51
52
|
@tracer.trace("my_operation")
|
|
52
53
|
async def my_function():
|
|
53
54
|
# Your code here
|
|
54
55
|
pass
|
|
55
56
|
|
|
56
|
-
# Using the context manager
|
|
57
|
+
# Using the context manager for custom spans
|
|
57
58
|
with tracer.create_span("my_operation") as span:
|
|
58
59
|
span.set_attribute("key", "value")
|
|
59
60
|
# Your code here
|
|
61
|
+
|
|
62
|
+
# Using start_as_current_span for context propagation
|
|
63
|
+
with tracer.start_as_current_span("parent_span") as span:
|
|
64
|
+
# Operations here will be associated with parent_span
|
|
65
|
+
pass
|
|
60
66
|
```
|
|
61
67
|
|
|
62
68
|
### Metrics
|
|
@@ -69,21 +75,38 @@ metrics = Metrics("my-service")
|
|
|
69
75
|
counter = metrics.get_counter("requests_total")
|
|
70
76
|
counter.add(1, {"endpoint": "/api/v1/resource"})
|
|
71
77
|
|
|
72
|
-
# Histogram for latencies
|
|
73
|
-
with metrics.measure_duration("request_duration"):
|
|
78
|
+
# Histogram for latencies using a context manager
|
|
79
|
+
with metrics.measure_duration("request_duration", attributes={"method": "GET"}):
|
|
74
80
|
# Your code here
|
|
75
81
|
pass
|
|
82
|
+
|
|
83
|
+
# Asynchronous metrics (Observable Gauge)
|
|
84
|
+
def get_system_load():
|
|
85
|
+
return 0.5 # Calculated value
|
|
86
|
+
|
|
87
|
+
metrics.observe_async(
|
|
88
|
+
name="system_load",
|
|
89
|
+
description="Current system load",
|
|
90
|
+
callback=get_system_load
|
|
91
|
+
)
|
|
76
92
|
```
|
|
77
93
|
|
|
78
94
|
### Structured Logging
|
|
95
|
+
The library provides a `StructuredLogger` that outputs logs in JSON format (when `json_logging` is enabled) and automatically includes tracing context.
|
|
96
|
+
|
|
79
97
|
```python
|
|
80
98
|
from otel_utils import StructuredLogger
|
|
81
99
|
|
|
82
|
-
logger = StructuredLogger("my-service")
|
|
100
|
+
logger = StructuredLogger("my-service", environment="production")
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
# Using operation_context to auto-log start/end/errors
|
|
103
|
+
with logger.operation_context("process_order", order_id="123", customer_type="vip"):
|
|
85
104
|
logger.info("Starting processing")
|
|
86
|
-
#
|
|
105
|
+
# If an exception is raised here, it will be logged with status="failed"
|
|
106
|
+
# and the error message will be included in the JSON log.
|
|
107
|
+
|
|
108
|
+
# Manual logging with extra context
|
|
109
|
+
logger.info("Event occurred", action="login", user="user123")
|
|
87
110
|
```
|
|
88
111
|
|
|
89
112
|
## OpenTelemetry Collector Integration
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|