Skip to content

Commit

Permalink
Add Azure support
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
  • Loading branch information
Lawouach committed Aug 1, 2023
1 parent 93b5486 commit 1c2ea81
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions chaostracing/oltp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1c2ea81

Please sign in to comment.