rebrandly-otel 0.2.3__py3-none-any.whl → 0.2.4__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.

Potentially problematic release.


This version of rebrandly-otel might be problematic. Click here for more details.

@@ -11,6 +11,9 @@ from opentelemetry.semconv.attributes import service_attributes, telemetry_attri
11
11
  from opentelemetry.semconv.resource import ResourceAttributes
12
12
  from opentelemetry.semconv._incubating.attributes import process_attributes, deployment_attributes
13
13
 
14
+ # Cache for endpoint validation results
15
+ _ENDPOINT_CACHE = {}
16
+
14
17
  def create_resource(name: str = None, version: str = None) -> Resource:
15
18
 
16
19
  if name is None:
@@ -85,36 +88,49 @@ def get_subsystem_name(subsystem_name: str = None) -> str:
85
88
  def get_otlp_endpoint(otlp_endpoint: str = None) -> str | None:
86
89
  endpoint = otlp_endpoint or os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', None)
87
90
 
88
- if endpoint is not None:
89
-
90
- if endpoint.strip() == "":
91
- return None
91
+ # Return cached result if available
92
+ cache_key = endpoint if endpoint else '__none__'
93
+ if cache_key in _ENDPOINT_CACHE:
94
+ return _ENDPOINT_CACHE[cache_key]
92
95
 
93
- try:
94
- from urllib.parse import urlparse
96
+ # Store the result to cache
97
+ result = None
95
98
 
96
- # Parse the endpoint
97
- parsed = urlparse(endpoint if '://' in endpoint else f'http://{endpoint}')
98
- host = parsed.hostname
99
- port = parsed.port
99
+ if endpoint is not None:
100
100
 
101
- # Test gRPC connection
102
- channel = grpc.insecure_channel(f'{host}:{port}')
101
+ if endpoint.strip() == "":
102
+ result = None
103
+ else:
103
104
  try:
104
- # Wait for the channel to be ready
105
- grpc.channel_ready_future(channel).result(timeout=3)
106
- return endpoint
107
- finally:
108
- channel.close()
109
-
110
- except grpc.FutureTimeoutError:
111
- print(f"[OTEL] Error: Connection timeout to OTLP endpoint {endpoint}. Check if the collector is running and accessible.")
112
- return None
113
- except Exception as e:
114
- print(f"[OTEL] Error: Failed to connect to OTLP endpoint {endpoint}: {type(e).__name__}: {e}")
115
- print(f"[OTEL] Telemetry data will not be exported. Verify endpoint configuration and network connectivity.")
116
- return None
117
- return endpoint
105
+ from urllib.parse import urlparse
106
+
107
+ # Parse the endpoint
108
+ parsed = urlparse(endpoint if '://' in endpoint else f'http://{endpoint}')
109
+ host = parsed.hostname
110
+ port = parsed.port
111
+
112
+ # Test gRPC connection
113
+ channel = grpc.insecure_channel(f'{host}:{port}')
114
+ try:
115
+ # Wait for the channel to be ready
116
+ grpc.channel_ready_future(channel).result(timeout=3)
117
+ result = endpoint
118
+ finally:
119
+ channel.close()
120
+
121
+ except grpc.FutureTimeoutError:
122
+ print(f"[OTEL] Error: Connection timeout to OTLP endpoint {endpoint}. Check if the collector is running and accessible.")
123
+ result = None
124
+ except Exception as e:
125
+ print(f"[OTEL] Error: Failed to connect to OTLP endpoint {endpoint}: {type(e).__name__}: {e}")
126
+ print(f"[OTEL] Telemetry data will not be exported. Verify endpoint configuration and network connectivity.")
127
+ result = None
128
+ else:
129
+ result = None
130
+
131
+ # Cache the result
132
+ _ENDPOINT_CACHE[cache_key] = result
133
+ return result
118
134
 
119
135
  def is_otel_debug() -> bool:
120
136
  return os.environ.get('OTEL_DEBUG', 'false').lower() == 'true'
@@ -41,8 +41,8 @@ def instrument_pymysql(otel_instance, connection, options=None):
41
41
  print('[Rebrandly OTEL PyMySQL] No valid OTEL instance provided for instrumentation')
42
42
  return connection
43
43
 
44
- # Get tracer from RebrandlyOTEL instance
45
- tracer = otel_instance.tracer
44
+ # Get the underlying OpenTelemetry tracer from RebrandlyOTEL instance
45
+ tracer = otel_instance.tracer.tracer
46
46
 
47
47
  # Extract database name from connection
48
48
  db_name = getattr(connection, 'db', None) or getattr(connection, 'database', None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rebrandly_otel
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Python OTEL wrapper by Rebrandly
5
5
  Home-page: https://github.com/rebrandly/rebrandly-otel-python
6
6
  Author: Antonio Romano
@@ -4,12 +4,12 @@ rebrandly_otel/flask_support.py,sha256=G0Q3apg4urtvHfXFb1uANomryAL7Mo2nPPULEe7j7
4
4
  rebrandly_otel/http_utils.py,sha256=Cwo1Ku1-BMqRp37ycvHtbiArxEjFPYU_zkF1H9_7CIE,719
5
5
  rebrandly_otel/logs.py,sha256=9uwWbQ9h9YcxF7-2vtsYucaMGCqMoPnO2vWf6qkyGgI,5328
6
6
  rebrandly_otel/metrics.py,sha256=jZPygTY7vie33sadXc7P1DwLTKe9tJvAWSZuGHW1xQg,7743
7
- rebrandly_otel/otel_utils.py,sha256=f7n1vEUXeMtTT4CafFZ0-yYhjmoVhBZqoCe9DpdhpDQ,5297
8
- rebrandly_otel/pymysql_instrumentation.py,sha256=rUCEbCOD5FiquH7MOcXJ3NCUeGCO0dvkzdylKm-BLZs,6441
7
+ rebrandly_otel/otel_utils.py,sha256=rZhrLUSlDGxlaCDQMPeL8JGMj3F2HUp5Knl2e1HD-Rk,5782
8
+ rebrandly_otel/pymysql_instrumentation.py,sha256=lS_V5DcsnpQ3f2PoNqeM7t3Jyiew2KNURM9iILfz8sM,6477
9
9
  rebrandly_otel/rebrandly_otel.py,sha256=8ty2rxcuaYV5WsNye7odxXXuh91kpdd5RVGOGSvsT98,22430
10
10
  rebrandly_otel/traces.py,sha256=JY_3RWbzpUxzEx3GqTVgggsyA2DB4oR-zDftIFFJha4,7174
11
- rebrandly_otel-0.2.3.dist-info/licenses/LICENSE,sha256=KMXHvTwP62S2q-SG7CFfMU_09rUwxiqlM0izaYGdcgY,1103
12
- rebrandly_otel-0.2.3.dist-info/METADATA,sha256=1BcpvnEcc8CMJ2uF7Gy8BkL-rkHBVFnlQEUn6vrGODg,14509
13
- rebrandly_otel-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- rebrandly_otel-0.2.3.dist-info/top_level.txt,sha256=26PSC1gjVUl8tTH5QfKbFevjVV4E2yojoukEfiTScvM,15
15
- rebrandly_otel-0.2.3.dist-info/RECORD,,
11
+ rebrandly_otel-0.2.4.dist-info/licenses/LICENSE,sha256=KMXHvTwP62S2q-SG7CFfMU_09rUwxiqlM0izaYGdcgY,1103
12
+ rebrandly_otel-0.2.4.dist-info/METADATA,sha256=EYalPNbuHeVBQNN8XIp-b-nnLgO3rICy2C494Unv8BA,14509
13
+ rebrandly_otel-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ rebrandly_otel-0.2.4.dist-info/top_level.txt,sha256=26PSC1gjVUl8tTH5QfKbFevjVV4E2yojoukEfiTScvM,15
15
+ rebrandly_otel-0.2.4.dist-info/RECORD,,