Skip to content

Commit

Permalink
Move opamp to different repo (#1455)
Browse files Browse the repository at this point in the history
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local>
  • Loading branch information
tamirdavid1 and Tamir David authored Aug 21, 2024
1 parent 55a81ad commit 39a43f4
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 1,000 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
go.work.sum
cli/odigos
.venv
23 changes: 23 additions & 0 deletions agents/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,26 @@
Odigos distribution of OpenTelemetry for Python

This package is used in the odigos project to provide auto OpenTelemetry instrumentation for applications written in Python.


## Local development of `odigos-opentelemetry-python`
1. Navigate to the Project Directory:
Open a new terminal and move to the directory containing odigos-opentelemetry-python:
```sh
cd <ODIGOS-OPENTELEMETRY-PYTHON-PATH>
```
2. Start the Local PyPI Server:
Build and run a local PyPI server with the following command:
```sh
docker build -t local-pypi-server -f debug.Dockerfile . && docker run --rm --name pypi-server -p 8080:8080 local-pypi-server
```
- Note: You need to run the Docker build command each time you make changes to odigos-opentelemetry-python.

3. Update the Development Configuration:
In the `odigos/agents/python/setup.py` file, uncomment the DEV index-url to point to the local PyPI server.

4. Deploy the Odiglet:
Finally, deploy the Odiglet by running:
```sh
make deploy-odiglet <VERSION>
```
101 changes: 7 additions & 94 deletions agents/python/configurator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,15 @@
import threading
import atexit
import sys
import os
import opentelemetry.sdk._configuration as sdk_config

from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.resources import ProcessResourceDetector, OTELResourceDetector
from .lib_handling import reorder_python_path, reload_distro_modules
from .version import VERSION
from opamp.http_client import OpAMPHTTPClient
from initializer.components import initialize_components


MINIMUM_PYTHON_SUPPORTED_VERSION = (3, 8)

class OdigosPythonConfigurator(sdk_config._BaseConfigurator):

def _configure(self, **kwargs):
_initialize_components()


def _initialize_components():
resource_attributes_event = threading.Event()
client = None

try:

client = start_opamp_client(resource_attributes_event)
resource_attributes_event.wait(timeout=30) # Wait for the resource attributes to be received for 30 seconds

received_value = client.resource_attributes

if received_value:
trace_exporters, metric_exporters, log_exporters = sdk_config._import_exporters(
sdk_config._get_exporter_names("traces"),
sdk_config._get_exporter_names("metrics"),
sdk_config._get_exporter_names("logs"),
)

auto_resource = {
"telemetry.distro.name": "odigos",
"telemetry.distro.version": VERSION,
}

auto_resource.update(received_value)

resource = Resource.create(auto_resource) \
.merge(OTELResourceDetector().detect()) \
.merge(ProcessResourceDetector().detect())

initialize_traces_if_enabled(trace_exporters, resource)
initialize_metrics_if_enabled(metric_exporters, resource)
initialize_logging_if_enabled(log_exporters, resource)

# Reorder the python sys.path to ensure that the user application's dependencies take precedence over the agent's dependencies.
# This is necessary because the user application's dependencies may be incompatible with those used by the agent.
reorder_python_path()
# Reload distro modules to ensure the new path is used.
reload_distro_modules()

except Exception as e:
if client is not None:
client.shutdown(custom_failure_message=str(e))


def initialize_traces_if_enabled(trace_exporters, resource):
traces_enabled = os.getenv(sdk_config.OTEL_TRACES_EXPORTER, "none").strip().lower()
if traces_enabled != "none":
id_generator_name = sdk_config._get_id_generator()
id_generator = sdk_config._import_id_generator(id_generator_name)
sdk_config._init_tracing(exporters=trace_exporters, id_generator=id_generator, resource=resource)

def initialize_metrics_if_enabled(metric_exporters, resource):
metrics_enabled = os.getenv(sdk_config.OTEL_METRICS_EXPORTER, "none").strip().lower()
if metrics_enabled != "none":
sdk_config._init_metrics(metric_exporters, resource)

def initialize_logging_if_enabled(log_exporters, resource):
logging_enabled = os.getenv(sdk_config.OTEL_LOGS_EXPORTER, "none").strip().lower()
if logging_enabled != "none":
sdk_config._init_logging(log_exporters, resource)


def start_opamp_client(event):
condition = threading.Condition(threading.Lock())
client = OpAMPHTTPClient(event, condition)

python_version_supported = is_supported_python_version()

client.start(python_version_supported)

def shutdown():
client.shutdown()

# Ensure that the shutdown function is called on program exit
atexit.register(shutdown)

return client


def is_supported_python_version():
return sys.version_info >= MINIMUM_PYTHON_SUPPORTED_VERSION
trace_exporters, metric_exporters, log_exporters = sdk_config._import_exporters(
sdk_config._get_exporter_names("traces"),
sdk_config._get_exporter_names("metrics"),
sdk_config._get_exporter_names("logs"),
)
initialize_components(trace_exporters, metric_exporters, log_exporters)
34 changes: 0 additions & 34 deletions agents/python/configurator/lib_handling.py

This file was deleted.

2 changes: 0 additions & 2 deletions agents/python/configurator/version.py

This file was deleted.

Empty file removed agents/python/opamp/__init__.py
Empty file.
33 changes: 0 additions & 33 deletions agents/python/opamp/anyvalue_pb2.py

This file was deleted.

8 changes: 0 additions & 8 deletions agents/python/opamp/health_status.py

This file was deleted.

Loading

0 comments on commit 39a43f4

Please sign in to comment.