otel-utils 1.1.5__tar.gz → 1.1.6__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.5 → otel_utils-1.1.6}/PKG-INFO +8 -31
- {otel_utils-1.1.5 → otel_utils-1.1.6}/README.md +7 -30
- {otel_utils-1.1.5 → otel_utils-1.1.6}/pyproject.toml +1 -1
- {otel_utils-1.1.5 → otel_utils-1.1.6}/src/otel_utils/__init__.py +0 -0
- {otel_utils-1.1.5 → otel_utils-1.1.6}/src/otel_utils/configurator.py +0 -0
- {otel_utils-1.1.5 → otel_utils-1.1.6}/src/otel_utils/logging.py +0 -0
- {otel_utils-1.1.5 → otel_utils-1.1.6}/src/otel_utils/metrics.py +0 -0
- {otel_utils-1.1.5 → otel_utils-1.1.6}/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.6
|
|
4
4
|
Summary: Utilidades simplificadas para instrumentación con OpenTelemetry
|
|
5
5
|
License: Proprietary
|
|
6
6
|
Author: Harold Portocarrero
|
|
@@ -58,7 +58,6 @@ 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)
|
|
62
61
|
additional_resources={ # Optional additional resources
|
|
63
62
|
"deployment.region": "us-east-1",
|
|
64
63
|
"team.name": "backend"
|
|
@@ -74,21 +73,16 @@ from otel_utils import Tracer
|
|
|
74
73
|
|
|
75
74
|
tracer = Tracer("my-service")
|
|
76
75
|
|
|
77
|
-
# Using the decorator
|
|
76
|
+
# Using the decorator
|
|
78
77
|
@tracer.trace("my_operation")
|
|
79
78
|
async def my_function():
|
|
80
79
|
# Your code here
|
|
81
80
|
pass
|
|
82
81
|
|
|
83
|
-
# Using the context manager
|
|
82
|
+
# Using the context manager
|
|
84
83
|
with tracer.create_span("my_operation") as span:
|
|
85
84
|
span.set_attribute("key", "value")
|
|
86
85
|
# 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
|
|
92
86
|
```
|
|
93
87
|
|
|
94
88
|
### Metrics
|
|
@@ -101,38 +95,21 @@ metrics = Metrics("my-service")
|
|
|
101
95
|
counter = metrics.get_counter("requests_total")
|
|
102
96
|
counter.add(1, {"endpoint": "/api/v1/resource"})
|
|
103
97
|
|
|
104
|
-
# Histogram for latencies
|
|
105
|
-
with metrics.measure_duration("request_duration"
|
|
98
|
+
# Histogram for latencies
|
|
99
|
+
with metrics.measure_duration("request_duration"):
|
|
106
100
|
# Your code here
|
|
107
101
|
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
|
-
)
|
|
118
102
|
```
|
|
119
103
|
|
|
120
104
|
### 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
|
-
|
|
123
105
|
```python
|
|
124
106
|
from otel_utils import StructuredLogger
|
|
125
107
|
|
|
126
|
-
logger = StructuredLogger("my-service"
|
|
108
|
+
logger = StructuredLogger("my-service")
|
|
127
109
|
|
|
128
|
-
|
|
129
|
-
with logger.operation_context("process_order", order_id="123", customer_type="vip"):
|
|
110
|
+
with logger.operation_context("process_order", order_id="123"):
|
|
130
111
|
logger.info("Starting processing")
|
|
131
|
-
#
|
|
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")
|
|
112
|
+
# Your code here
|
|
136
113
|
```
|
|
137
114
|
|
|
138
115
|
## OpenTelemetry Collector Integration
|
|
@@ -32,7 +32,6 @@ 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)
|
|
36
35
|
additional_resources={ # Optional additional resources
|
|
37
36
|
"deployment.region": "us-east-1",
|
|
38
37
|
"team.name": "backend"
|
|
@@ -48,21 +47,16 @@ from otel_utils import Tracer
|
|
|
48
47
|
|
|
49
48
|
tracer = Tracer("my-service")
|
|
50
49
|
|
|
51
|
-
# Using the decorator
|
|
50
|
+
# Using the decorator
|
|
52
51
|
@tracer.trace("my_operation")
|
|
53
52
|
async def my_function():
|
|
54
53
|
# Your code here
|
|
55
54
|
pass
|
|
56
55
|
|
|
57
|
-
# Using the context manager
|
|
56
|
+
# Using the context manager
|
|
58
57
|
with tracer.create_span("my_operation") as span:
|
|
59
58
|
span.set_attribute("key", "value")
|
|
60
59
|
# 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
|
|
66
60
|
```
|
|
67
61
|
|
|
68
62
|
### Metrics
|
|
@@ -75,38 +69,21 @@ metrics = Metrics("my-service")
|
|
|
75
69
|
counter = metrics.get_counter("requests_total")
|
|
76
70
|
counter.add(1, {"endpoint": "/api/v1/resource"})
|
|
77
71
|
|
|
78
|
-
# Histogram for latencies
|
|
79
|
-
with metrics.measure_duration("request_duration"
|
|
72
|
+
# Histogram for latencies
|
|
73
|
+
with metrics.measure_duration("request_duration"):
|
|
80
74
|
# Your code here
|
|
81
75
|
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
|
-
)
|
|
92
76
|
```
|
|
93
77
|
|
|
94
78
|
### 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
|
-
|
|
97
79
|
```python
|
|
98
80
|
from otel_utils import StructuredLogger
|
|
99
81
|
|
|
100
|
-
logger = StructuredLogger("my-service"
|
|
82
|
+
logger = StructuredLogger("my-service")
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
with logger.operation_context("process_order", order_id="123", customer_type="vip"):
|
|
84
|
+
with logger.operation_context("process_order", order_id="123"):
|
|
104
85
|
logger.info("Starting processing")
|
|
105
|
-
#
|
|
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")
|
|
86
|
+
# Your code here
|
|
110
87
|
```
|
|
111
88
|
|
|
112
89
|
## OpenTelemetry Collector Integration
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|