From 1c2ea81693626454657718b15deda85b29f85e55 Mon Sep 17 00:00:00 2001 From: Sylvain Hellegouarch Date: Tue, 1 Aug 2023 08:35:12 +0200 Subject: [PATCH] Add Azure support Signed-off-by: Sylvain Hellegouarch --- CHANGELOG.md | 4 ++++ README.md | 18 ++++++++++++++++++ chaostracing/oltp.py | 19 +++++++++++++++++++ setup.py | 7 ++++++- 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd90b3d..1069af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ [Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-opentracing/compare/0.10.0...HEAD +### Added + +- Added specific support for Azure. Install the dependencies with `pip install chaostoolkit-opentracing[azure]` + ### Changed - Switched from flake8/pycodestyle to ruff diff --git a/README.md b/README.md index 2264a40..f60dc05 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,24 @@ To authenticate the client, you can either: In all cases, point to a service account which has the `roles/cloudtrace.agent` role as nthe name of the target project. +#### Azure Traces + +To use this package to send traces to Azure monitors, please install the +dependencies as follows: + +``` +$ pip install chaostoolkit-opentracing[azure] +``` + +Then set the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable +appropriately. + +See Azure documentation for more details: + +* https://learn.microsoft.com/en-us/python/api/overview/azure/core-tracing-opentelemetry-readme +* https://learn.microsoft.com/en-us/python/api/overview/azure/monitor-opentelemetry-exporter-readme + + ### Legacy Open Tracing This extensions supports the [Open Tracing](https://opentracing.io/) export diff --git a/chaostracing/oltp.py b/chaostracing/oltp.py index 3dbd734..a25edcd 100644 --- a/chaostracing/oltp.py +++ b/chaostracing/oltp.py @@ -68,6 +68,16 @@ HAS_AWS_EXPORTER = False +try: + from azure.core.settings import settings + from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan + from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter + + HAS_AZURE_EXPORTER = True +except ImportError: + HAS_AZURE_EXPORTER = False + + __all__ = [ "configure_control", "before_activity_control", @@ -408,6 +418,15 @@ def configure_traces(configuration: Configuration) -> None: resources=resources, id_generator=AwsXRayIdGenerator() ) set_global_textmap(AwsXRayPropagator()) + elif vendor == "azure": + if not HAS_AZURE_EXPORTER: + raise RuntimeError( + "missing Azure Open Telemetry dependencies. " + "See: https://learn.microsoft.com/en-us/python/api/overview/azure/core-tracing-opentelemetry-readme" # noqa + ) + + settings.tracing_implementation = OpenTelemetrySpan + exporter = AzureMonitorTraceExporter() processor = BatchSpanProcessor(exporter) provider.add_span_processor(processor) diff --git a/setup.py b/setup.py index cf52270..a485de0 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,12 @@ with io.open('requirements.txt') as f: install_require = [l.strip() for l in f if not l.startswith('#')] -extra_requires = {} +extra_requires = { + "azure": [ + "azure-core-tracing-opentelemetry", + "azure-monitor-opentelemetry-exporter", + ] +} setup_params = dict( name=name,