rebrandly-otel 0.2.3__tar.gz → 0.2.5__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 (21) hide show
  1. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/PKG-INFO +1 -1
  2. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/rebrandly_otel.egg-info/PKG-INFO +1 -1
  3. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/setup.py +1 -1
  4. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/otel_utils.py +54 -28
  5. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/pymysql_instrumentation.py +2 -2
  6. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/LICENSE +0 -0
  7. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/README.md +0 -0
  8. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/rebrandly_otel.egg-info/SOURCES.txt +0 -0
  9. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/rebrandly_otel.egg-info/dependency_links.txt +0 -0
  10. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/rebrandly_otel.egg-info/requires.txt +0 -0
  11. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/rebrandly_otel.egg-info/top_level.txt +0 -0
  12. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/setup.cfg +0 -0
  13. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/__init__.py +0 -0
  14. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/fastapi_support.py +0 -0
  15. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/flask_support.py +0 -0
  16. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/http_utils.py +0 -0
  17. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/logs.py +0 -0
  18. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/metrics.py +0 -0
  19. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/rebrandly_otel.py +0 -0
  20. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/src/traces.py +0 -0
  21. {rebrandly_otel-0.2.3 → rebrandly_otel-0.2.5}/tests/test_usage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rebrandly_otel
3
- Version: 0.2.3
3
+ Version: 0.2.5
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.2.3
3
+ Version: 0.2.5
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.2.3",
8
+ version="0.2.5",
9
9
  author="Antonio Romano",
10
10
  author_email="antonio@rebrandly.com",
11
11
  description="Python OTEL wrapper by Rebrandly",
@@ -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: os.environ.get('ENV', os.environ.get('ENVIRONMENT', os.environ.get('NODE_ENV', 'local'))),
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
- if endpoint is not None:
89
-
90
- if endpoint.strip() == "":
91
- return None
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
- try:
94
- from urllib.parse import urlparse
106
+ # Store the result to cache
107
+ result = None
95
108
 
96
- # Parse the endpoint
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
- # Test gRPC connection
102
- channel = grpc.insecure_channel(f'{host}:{port}')
111
+ if endpoint.strip() == "":
112
+ result = None
113
+ else:
103
114
  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
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)
File without changes
File without changes
File without changes