rebrandly-otel 0.2.3__py3-none-any.whl → 0.2.5__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 +54 -28
- rebrandly_otel/pymysql_instrumentation.py +2 -2
- {rebrandly_otel-0.2.3.dist-info → rebrandly_otel-0.2.5.dist-info}/METADATA +1 -1
- {rebrandly_otel-0.2.3.dist-info → rebrandly_otel-0.2.5.dist-info}/RECORD +7 -7
- {rebrandly_otel-0.2.3.dist-info → rebrandly_otel-0.2.5.dist-info}/WHEEL +0 -0
- {rebrandly_otel-0.2.3.dist-info → rebrandly_otel-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {rebrandly_otel-0.2.3.dist-info → rebrandly_otel-0.2.5.dist-info}/top_level.txt +0 -0
rebrandly_otel/otel_utils.py
CHANGED
|
@@ -6,11 +6,14 @@ import sys
|
|
|
6
6
|
import grpc
|
|
7
7
|
import json
|
|
8
8
|
|
|
9
|
-
from opentelemetry.sdk.resources import Resource, SERVICE_NAMESPACE
|
|
9
|
+
from opentelemetry.sdk.resources import Resource, SERVICE_NAMESPACE, DEPLOYMENT_ENVIRONMENT
|
|
10
10
|
from opentelemetry.semconv.attributes import service_attributes, telemetry_attributes
|
|
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:
|
|
@@ -18,11 +21,14 @@ def create_resource(name: str = None, version: str = None) -> Resource:
|
|
|
18
21
|
if version is None:
|
|
19
22
|
version = get_service_version()
|
|
20
23
|
|
|
24
|
+
env = os.environ.get('ENV', os.environ.get('ENVIRONMENT', os.environ.get('NODE_ENV', 'local')))
|
|
25
|
+
|
|
21
26
|
resources_attributes = {
|
|
22
27
|
service_attributes.SERVICE_NAME: name,
|
|
23
28
|
service_attributes.SERVICE_VERSION: version,
|
|
24
29
|
process_attributes.PROCESS_RUNTIME_VERSION: f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
|
|
25
|
-
SERVICE_NAMESPACE:
|
|
30
|
+
SERVICE_NAMESPACE: env,
|
|
31
|
+
DEPLOYMENT_ENVIRONMENT: env,
|
|
26
32
|
telemetry_attributes.TELEMETRY_SDK_LANGUAGE: "python"
|
|
27
33
|
}
|
|
28
34
|
|
|
@@ -38,6 +44,13 @@ def create_resource(name: str = None, version: str = None) -> Resource:
|
|
|
38
44
|
resources_attributes[k.strip()] = v.strip()
|
|
39
45
|
except Exception as e:
|
|
40
46
|
print(f"[OTEL Utils] Warning: Invalid OTEL_RESOURCE_ATTRIBUTES value: {e}")
|
|
47
|
+
|
|
48
|
+
if os.environ.get('OTEL_REPO_NAME', None) is not None:
|
|
49
|
+
resources_attributes['repository.name'] = os.environ.get('OTEL_REPO_NAME')
|
|
50
|
+
|
|
51
|
+
if os.environ.get('OTEL_COMMIT_ID', None) is not None:
|
|
52
|
+
resources_attributes[service_attributes.SERVICE_VERSION] = os.environ.get('OTEL_COMMIT_ID')
|
|
53
|
+
|
|
41
54
|
resource = Resource.create(
|
|
42
55
|
resources_attributes
|
|
43
56
|
)
|
|
@@ -85,36 +98,49 @@ def get_subsystem_name(subsystem_name: str = None) -> str:
|
|
|
85
98
|
def get_otlp_endpoint(otlp_endpoint: str = None) -> str | None:
|
|
86
99
|
endpoint = otlp_endpoint or os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', None)
|
|
87
100
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
# Return cached result if available
|
|
102
|
+
cache_key = endpoint if endpoint else '__none__'
|
|
103
|
+
if cache_key in _ENDPOINT_CACHE:
|
|
104
|
+
return _ENDPOINT_CACHE[cache_key]
|
|
92
105
|
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
# Store the result to cache
|
|
107
|
+
result = None
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
parsed = urlparse(endpoint if '://' in endpoint else f'http://{endpoint}')
|
|
98
|
-
host = parsed.hostname
|
|
99
|
-
port = parsed.port
|
|
109
|
+
if endpoint is not None:
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
if endpoint.strip() == "":
|
|
112
|
+
result = None
|
|
113
|
+
else:
|
|
103
114
|
try:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
from urllib.parse import urlparse
|
|
116
|
+
|
|
117
|
+
# Parse the endpoint
|
|
118
|
+
parsed = urlparse(endpoint if '://' in endpoint else f'http://{endpoint}')
|
|
119
|
+
host = parsed.hostname
|
|
120
|
+
port = parsed.port
|
|
121
|
+
|
|
122
|
+
# Test gRPC connection
|
|
123
|
+
channel = grpc.insecure_channel(f'{host}:{port}')
|
|
124
|
+
try:
|
|
125
|
+
# Wait for the channel to be ready
|
|
126
|
+
grpc.channel_ready_future(channel).result(timeout=3)
|
|
127
|
+
result = endpoint
|
|
128
|
+
finally:
|
|
129
|
+
channel.close()
|
|
130
|
+
|
|
131
|
+
except grpc.FutureTimeoutError:
|
|
132
|
+
print(f"[OTEL] Error: Connection timeout to OTLP endpoint {endpoint}. Check if the collector is running and accessible.")
|
|
133
|
+
result = None
|
|
134
|
+
except Exception as e:
|
|
135
|
+
print(f"[OTEL] Error: Failed to connect to OTLP endpoint {endpoint}: {type(e).__name__}: {e}")
|
|
136
|
+
print(f"[OTEL] Telemetry data will not be exported. Verify endpoint configuration and network connectivity.")
|
|
137
|
+
result = None
|
|
138
|
+
else:
|
|
139
|
+
result = None
|
|
140
|
+
|
|
141
|
+
# Cache the result
|
|
142
|
+
_ENDPOINT_CACHE[cache_key] = result
|
|
143
|
+
return result
|
|
118
144
|
|
|
119
145
|
def is_otel_debug() -> bool:
|
|
120
146
|
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)
|
|
@@ -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=vr5ygRXY2If-c2Vq2ectupTm1AHgSPkflEw25O5T7NE,6162
|
|
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.5.dist-info/licenses/LICENSE,sha256=KMXHvTwP62S2q-SG7CFfMU_09rUwxiqlM0izaYGdcgY,1103
|
|
12
|
+
rebrandly_otel-0.2.5.dist-info/METADATA,sha256=-kU1ruj2BNZA2yJ8vYouX1wiuxfzyFJWri69bThqJeI,14509
|
|
13
|
+
rebrandly_otel-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
rebrandly_otel-0.2.5.dist-info/top_level.txt,sha256=26PSC1gjVUl8tTH5QfKbFevjVV4E2yojoukEfiTScvM,15
|
|
15
|
+
rebrandly_otel-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|