rebrandly-otel 0.1.30__tar.gz → 0.1.33__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.

Files changed (20) hide show
  1. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/PKG-INFO +1 -1
  2. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/rebrandly_otel.egg-info/PKG-INFO +1 -1
  3. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/setup.py +1 -1
  4. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/logs.py +33 -0
  5. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/pymysql_instrumentation.py +16 -3
  6. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/rebrandly_otel.py +12 -0
  7. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/LICENSE +0 -0
  8. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/README.md +0 -0
  9. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/rebrandly_otel.egg-info/SOURCES.txt +0 -0
  10. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/rebrandly_otel.egg-info/dependency_links.txt +0 -0
  11. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/rebrandly_otel.egg-info/requires.txt +0 -0
  12. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/rebrandly_otel.egg-info/top_level.txt +0 -0
  13. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/setup.cfg +0 -0
  14. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/__init__.py +0 -0
  15. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/fastapi_support.py +0 -0
  16. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/flask_support.py +0 -0
  17. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/metrics.py +0 -0
  18. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/otel_utils.py +0 -0
  19. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/src/traces.py +0 -0
  20. {rebrandly_otel-0.1.30 → rebrandly_otel-0.1.33}/tests/test_usage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rebrandly_otel
3
- Version: 0.1.30
3
+ Version: 0.1.33
4
4
  Summary: Python OTEL wrapper by Rebrandly
5
5
  Home-page: https://github.com/rebrandly/rebrandly-otel-python
6
6
  Author: Antonio Romano
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rebrandly_otel
3
- Version: 0.1.30
3
+ Version: 0.1.33
4
4
  Summary: Python OTEL wrapper by Rebrandly
5
5
  Home-page: https://github.com/rebrandly/rebrandly-otel-python
6
6
  Author: Antonio Romano
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="rebrandly_otel",
8
- version="0.1.30",
8
+ version="0.1.33",
9
9
  author="Antonio Romano",
10
10
  author_email="antonio@rebrandly.com",
11
11
  description="Python OTEL wrapper by Rebrandly",
@@ -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,31 @@ 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 using the original unbound method
104
+ # This avoids infinite recursion if the logger's setLevel has been monkey-patched
105
+ if self._logger:
106
+ logging.Logger.setLevel(self._logger, level)
107
+
108
+ # Set level on the OTEL handler
109
+ root_logger = logging.getLogger()
110
+ for handler in root_logger.handlers:
111
+ if isinstance(handler, LoggingHandler):
112
+ handler.setLevel(level)
113
+
81
114
  def force_flush(self, timeout_millis: int = 5000) -> bool:
82
115
  """
83
116
  Force flush all pending logs.
@@ -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