rebrandly-otel 0.2.2__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.
- rebrandly_otel/otel_utils.py +46 -28
- rebrandly_otel/pymysql_instrumentation.py +3 -3
- {rebrandly_otel-0.2.2.dist-info → rebrandly_otel-0.2.4.dist-info}/METADATA +1 -1
- {rebrandly_otel-0.2.2.dist-info → rebrandly_otel-0.2.4.dist-info}/RECORD +7 -7
- {rebrandly_otel-0.2.2.dist-info → rebrandly_otel-0.2.4.dist-info}/WHEEL +0 -0
- {rebrandly_otel-0.2.2.dist-info → rebrandly_otel-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {rebrandly_otel-0.2.2.dist-info → rebrandly_otel-0.2.4.dist-info}/top_level.txt +0 -0
rebrandly_otel/otel_utils.py
CHANGED
|
@@ -7,9 +7,13 @@ import grpc
|
|
|
7
7
|
import json
|
|
8
8
|
|
|
9
9
|
from opentelemetry.sdk.resources import Resource, SERVICE_NAMESPACE
|
|
10
|
-
from opentelemetry.semconv.attributes import service_attributes
|
|
10
|
+
from opentelemetry.semconv.attributes import service_attributes, telemetry_attributes
|
|
11
|
+
from opentelemetry.semconv.resource import ResourceAttributes
|
|
11
12
|
from opentelemetry.semconv._incubating.attributes import process_attributes, deployment_attributes
|
|
12
13
|
|
|
14
|
+
# Cache for endpoint validation results
|
|
15
|
+
_ENDPOINT_CACHE = {}
|
|
16
|
+
|
|
13
17
|
def create_resource(name: str = None, version: str = None) -> Resource:
|
|
14
18
|
|
|
15
19
|
if name is None:
|
|
@@ -21,7 +25,8 @@ def create_resource(name: str = None, version: str = None) -> Resource:
|
|
|
21
25
|
service_attributes.SERVICE_NAME: name,
|
|
22
26
|
service_attributes.SERVICE_VERSION: version,
|
|
23
27
|
process_attributes.PROCESS_RUNTIME_VERSION: f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
|
|
24
|
-
SERVICE_NAMESPACE: os.environ.get('ENV', os.environ.get('ENVIRONMENT', os.environ.get('NODE_ENV', 'local')))
|
|
28
|
+
SERVICE_NAMESPACE: os.environ.get('ENV', os.environ.get('ENVIRONMENT', os.environ.get('NODE_ENV', 'local'))),
|
|
29
|
+
telemetry_attributes.TELEMETRY_SDK_LANGUAGE: "python"
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
if os.environ.get('OTEL_RESOURCE_ATTRIBUTES', None) is not None and os.environ.get('OTEL_RESOURCE_ATTRIBUTES', None).strip() != "":
|
|
@@ -83,36 +88,49 @@ def get_subsystem_name(subsystem_name: str = None) -> str:
|
|
|
83
88
|
def get_otlp_endpoint(otlp_endpoint: str = None) -> str | None:
|
|
84
89
|
endpoint = otlp_endpoint or os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', None)
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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]
|
|
90
95
|
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
# Store the result to cache
|
|
97
|
+
result = None
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
parsed = urlparse(endpoint if '://' in endpoint else f'http://{endpoint}')
|
|
96
|
-
host = parsed.hostname
|
|
97
|
-
port = parsed.port
|
|
99
|
+
if endpoint is not None:
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
if endpoint.strip() == "":
|
|
102
|
+
result = None
|
|
103
|
+
else:
|
|
101
104
|
try:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
116
134
|
|
|
117
135
|
def is_otel_debug() -> bool:
|
|
118
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)
|
|
@@ -110,7 +110,7 @@ def _trace_query(func, tracer, slow_query_threshold_ms, capture_bindings, db_nam
|
|
|
110
110
|
# Start span
|
|
111
111
|
span_name = f"pymysql.{'executemany' if many else 'execute'}"
|
|
112
112
|
|
|
113
|
-
with tracer.
|
|
113
|
+
with tracer.start_as_current_span(
|
|
114
114
|
name=span_name,
|
|
115
115
|
kind=SpanKind.CLIENT
|
|
116
116
|
) as span:
|
|
@@ -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=
|
|
8
|
-
rebrandly_otel/pymysql_instrumentation.py,sha256=
|
|
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.
|
|
12
|
-
rebrandly_otel-0.2.
|
|
13
|
-
rebrandly_otel-0.2.
|
|
14
|
-
rebrandly_otel-0.2.
|
|
15
|
-
rebrandly_otel-0.2.
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|