rebrandly-otel 0.1.29__tar.gz → 0.1.32__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 rebrandly-otel might be problematic. Click here for more details.
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/PKG-INFO +1 -1
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/PKG-INFO +1 -1
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/setup.py +1 -1
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/logs.py +32 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/otel_utils.py +4 -3
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/pymysql_instrumentation.py +16 -3
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/rebrandly_otel.py +12 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/LICENSE +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/README.md +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/SOURCES.txt +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/dependency_links.txt +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/requires.txt +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/top_level.txt +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/setup.cfg +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/__init__.py +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/fastapi_support.py +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/flask_support.py +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/metrics.py +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/src/traces.py +0 -0
- {rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/tests/test_usage.py +0 -0
|
@@ -18,6 +18,14 @@ from .otel_utils import *
|
|
|
18
18
|
class RebrandlyLogger:
|
|
19
19
|
"""Wrapper for OpenTelemetry logging with Rebrandly-specific features."""
|
|
20
20
|
|
|
21
|
+
# Expose logging levels for convenience (compatible with standard logging)
|
|
22
|
+
DEBUG = logging.DEBUG
|
|
23
|
+
INFO = logging.INFO
|
|
24
|
+
WARNING = logging.WARNING
|
|
25
|
+
ERROR = logging.ERROR
|
|
26
|
+
CRITICAL = logging.CRITICAL
|
|
27
|
+
NOTSET = logging.NOTSET
|
|
28
|
+
|
|
21
29
|
def __init__(self):
|
|
22
30
|
self._logger: Optional[logging.Logger] = None
|
|
23
31
|
self._provider: Optional[LoggerProvider] = None
|
|
@@ -78,6 +86,30 @@ class RebrandlyLogger:
|
|
|
78
86
|
self._logger = logging.getLogger(get_service_name())
|
|
79
87
|
return self._logger
|
|
80
88
|
|
|
89
|
+
def getLogger(self) -> logging.Logger:
|
|
90
|
+
"""
|
|
91
|
+
Get the internal logger instance.
|
|
92
|
+
Alias for the logger property for consistency with standard logging API.
|
|
93
|
+
"""
|
|
94
|
+
return self.logger
|
|
95
|
+
|
|
96
|
+
def setLevel(self, level: int):
|
|
97
|
+
"""
|
|
98
|
+
Set the logging level for both the internal logger and OTEL handler.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
level: Logging level (e.g., logging.INFO, logging.DEBUG, logging.WARNING)
|
|
102
|
+
"""
|
|
103
|
+
# Set level on the service-specific logger
|
|
104
|
+
if self._logger:
|
|
105
|
+
self._logger.setLevel(level)
|
|
106
|
+
|
|
107
|
+
# Set level on the OTEL handler
|
|
108
|
+
root_logger = logging.getLogger()
|
|
109
|
+
for handler in root_logger.handlers:
|
|
110
|
+
if isinstance(handler, LoggingHandler):
|
|
111
|
+
handler.setLevel(level)
|
|
112
|
+
|
|
81
113
|
def force_flush(self, timeout_millis: int = 5000) -> bool:
|
|
82
114
|
"""
|
|
83
115
|
Force flush all pending logs.
|
|
@@ -58,10 +58,11 @@ def get_service_version(service_version: str = None) -> str:
|
|
|
58
58
|
def get_otlp_endpoint(otlp_endpoint: str = None) -> str | None:
|
|
59
59
|
endpoint = otlp_endpoint or os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', None)
|
|
60
60
|
|
|
61
|
-
if endpoint.strip() == "":
|
|
62
|
-
return None
|
|
63
|
-
|
|
64
61
|
if endpoint is not None:
|
|
62
|
+
|
|
63
|
+
if endpoint.strip() == "":
|
|
64
|
+
return None
|
|
65
|
+
|
|
65
66
|
try:
|
|
66
67
|
from urllib.parse import urlparse
|
|
67
68
|
|
|
@@ -44,19 +44,24 @@ def instrument_pymysql(otel_instance, connection, options=None):
|
|
|
44
44
|
# Get tracer from RebrandlyOTEL instance
|
|
45
45
|
tracer = otel_instance.tracer
|
|
46
46
|
|
|
47
|
+
# Extract database name from connection
|
|
48
|
+
db_name = getattr(connection, 'db', None) or getattr(connection, 'database', None)
|
|
49
|
+
if db_name and isinstance(db_name, bytes):
|
|
50
|
+
db_name = db_name.decode('utf-8')
|
|
51
|
+
|
|
47
52
|
# Wrap the cursor method to return instrumented cursors
|
|
48
53
|
original_cursor = connection.cursor
|
|
49
54
|
|
|
50
55
|
def instrumented_cursor(*args, **kwargs):
|
|
51
56
|
cursor = original_cursor(*args, **kwargs)
|
|
52
|
-
return _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings)
|
|
57
|
+
return _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings, db_name)
|
|
53
58
|
|
|
54
59
|
connection.cursor = instrumented_cursor
|
|
55
60
|
|
|
56
61
|
return connection
|
|
57
62
|
|
|
58
63
|
|
|
59
|
-
def _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings):
|
|
64
|
+
def _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings, db_name=None):
|
|
60
65
|
"""
|
|
61
66
|
Instrument a cursor's execute methods
|
|
62
67
|
"""
|
|
@@ -70,6 +75,7 @@ def _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings
|
|
|
70
75
|
tracer,
|
|
71
76
|
slow_query_threshold_ms,
|
|
72
77
|
capture_bindings,
|
|
78
|
+
db_name,
|
|
73
79
|
query,
|
|
74
80
|
args,
|
|
75
81
|
many=False
|
|
@@ -82,6 +88,7 @@ def _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings
|
|
|
82
88
|
tracer,
|
|
83
89
|
slow_query_threshold_ms,
|
|
84
90
|
capture_bindings,
|
|
91
|
+
db_name,
|
|
85
92
|
query,
|
|
86
93
|
args,
|
|
87
94
|
many=True
|
|
@@ -93,7 +100,7 @@ def _instrument_cursor(cursor, tracer, slow_query_threshold_ms, capture_bindings
|
|
|
93
100
|
return cursor
|
|
94
101
|
|
|
95
102
|
|
|
96
|
-
def _trace_query(func, tracer, slow_query_threshold_ms, capture_bindings, query, args, many=False):
|
|
103
|
+
def _trace_query(func, tracer, slow_query_threshold_ms, capture_bindings, db_name, query, args, many=False):
|
|
97
104
|
"""
|
|
98
105
|
Trace a query execution with OpenTelemetry
|
|
99
106
|
"""
|
|
@@ -112,6 +119,12 @@ def _trace_query(func, tracer, slow_query_threshold_ms, capture_bindings, query,
|
|
|
112
119
|
span.set_attribute('db.operation.name', operation)
|
|
113
120
|
span.set_attribute('db.statement', truncated_query)
|
|
114
121
|
|
|
122
|
+
# Set database name if available
|
|
123
|
+
if db_name:
|
|
124
|
+
span.set_attribute('db.name', db_name)
|
|
125
|
+
else:
|
|
126
|
+
span.set_attribute('db.name', 'unknown')
|
|
127
|
+
|
|
115
128
|
# Add bindings if enabled (be cautious with sensitive data)
|
|
116
129
|
if capture_bindings and args:
|
|
117
130
|
if many:
|
|
@@ -525,3 +525,15 @@ attach_context = otel.attach_context
|
|
|
525
525
|
detach_context = otel.detach_context
|
|
526
526
|
force_flush = otel.force_flush
|
|
527
527
|
shutdown = otel.shutdown
|
|
528
|
+
|
|
529
|
+
# Attach logging levels to logger for convenience
|
|
530
|
+
# This allows: from rebrandly_otel import logger; logger.setLevel(logger.INFO)
|
|
531
|
+
import logging as _logging
|
|
532
|
+
logger.DEBUG = _logging.DEBUG
|
|
533
|
+
logger.INFO = _logging.INFO
|
|
534
|
+
logger.WARNING = _logging.WARNING
|
|
535
|
+
logger.ERROR = _logging.ERROR
|
|
536
|
+
logger.CRITICAL = _logging.CRITICAL
|
|
537
|
+
logger.NOTSET = _logging.NOTSET
|
|
538
|
+
logger.setLevel = otel.logger.setLevel
|
|
539
|
+
logger.getLogger = otel.logger.getLogger
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rebrandly_otel-0.1.29 → rebrandly_otel-0.1.32}/rebrandly_otel.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|