Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from lzchen/release
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored May 20, 2020
2 parents ecb13f0 + 3bded54 commit 66321f4
Show file tree
Hide file tree
Showing 44 changed files with 1,330 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ omit =
azure_monitor/tests/*

[report]
fail_under = 98
fail_under = 90
show_missing = True
omit =
azure_monitor/setup.py
Expand Down
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

27 changes: 7 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# OpenTelemetry Azure Monitor SDKs and Exporters
# OpenTelemetry Azure Monitor

[![Gitter chat](https://img.shields.io/gitter/room/Microsoft/azure-monitor-python)](https://gitter.im/Microsoft/azure-monitor-python)
[![Build status](https://travis-ci.org/microsoft/opentelemetry-azure-monitor-python.svg?branch=master)](https://travis-ci.org/microsoft/opentelemetry-azure-monitor-python)
[![PyPI version](https://badge.fury.io/py/opentelemetry-azure-monitor.svg)](https://badge.fury.io/py/opentelemetry-azure-monitor)

## Installation

Expand All @@ -14,9 +13,9 @@ pip install opentelemetry-azure-monitor

The online documentation is available at https://opentelemetry-azure-monitor-python.readthedocs.io/.


## Usage


### Trace

The **Azure Monitor Trace Exporter** allows you to export [OpenTelemetry](https://opentelemetry.io/) traces to [Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/).
Expand Down Expand Up @@ -68,7 +67,7 @@ import requests

from azure_monitor import AzureMonitorSpanExporter
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

Expand All @@ -81,7 +80,7 @@ exporter = AzureMonitorSpanExporter(
span_processor = BatchExportSpanProcessor(exporter)
tracer_provider.add_span_processor(span_processor)

http_requests.enable(tracer_provider)
RequestsInstrumentor().instrument()
response = requests.get(url="https://azure.microsoft.com/")
```

Expand Down Expand Up @@ -129,8 +128,6 @@ This example shows how to track a counter metric and send it as telemetry every
* Alternatively, you can specify your `connection string` in an environment variable ``APPLICATIONINSIGHTS_CONNECTION_STRING``.

```python
import time

from azure_monitor import AzureMonitorMetricsExporter
from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, MeterProvider
Expand All @@ -152,18 +149,8 @@ requests_counter = meter.create_metric(
label_keys=("environment",),
)

testing_label_set = meter.get_label_set({"environment": "testing"})
testing_labels = {"environment": "testing"}

requests_counter.add(25, testing_label_set)
time.sleep(100)
requests_counter.add(25, testing_labels)
input("...")
```

# References

[Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/)

[OpenTelemetry Project](https://opentelemetry.io/)

[OpenTelemetry Python Client](https://github.com/open-telemetry/opentelemetry-python)

[Azure Monitor Python Gitter](https://gitter.im/Microsoft/azure-monitor-python)
27 changes: 27 additions & 0 deletions azure_monitor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Changelog

## Unreleased

## 0.3b.0
Released 2020-05-19

- Implement max size logic for local storage
([#74](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/74))
- Remove label sets + add is_remote to spancontext
([#75](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/75))
- Adding live metrics manager
([#78](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/78))
- Handle status 439 - Too Many Requests over extended time
([#80](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/80))
- Fix breaking changes from OT release 0.7b.0
([#86](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/86))

## 0.2b.0
Released 2020-03-31

- Initial beta release

## 0.1a.0
Released 2019-11-06

- Initial alpha release
19 changes: 19 additions & 0 deletions azure_monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# OpenTelemetry Azure Monitor SDKs and Exporters

[![PyPI version](https://badge.fury.io/py/opentelemetry-azure-monitor.svg)](https://badge.fury.io/py/opentelemetry-azure-monitor)

## Installation

```sh
pip install opentelemetry-azure-monitor
```

# References

[Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/)

[OpenTelemetry Project](https://opentelemetry.io/)

[OpenTelemetry Python Client](https://github.com/open-telemetry/opentelemetry-python)

[Azure Monitor Python Gitter](https://gitter.im/Microsoft/azure-monitor-python)
4 changes: 2 additions & 2 deletions azure_monitor/examples/metrics/auto_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
)
controller = PushController(meter, exporter, 5)

testing_label_set = meter.get_label_set({"environment": "testing"})
testing_label_set = {"environment": "testing"}

# Automatically collect standard metrics
auto_collection = AutoCollection(meter=meter, label_set=testing_label_set)
auto_collection = AutoCollection(meter=meter, labels=testing_label_set)

# To configure a separate export interval specific for standard metrics
# meter_standard = metrics.get_meter(__name__ + "_standard")
Expand Down
26 changes: 0 additions & 26 deletions azure_monitor/examples/metrics/client.py

This file was deleted.

50 changes: 50 additions & 0 deletions azure_monitor/examples/metrics/observer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import psutil
from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export.controller import PushController

from azure_monitor import AzureMonitorMetricsExporter

metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
exporter = AzureMonitorMetricsExporter(
connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>"
)
controller = PushController(meter=meter, exporter=exporter, interval=2)


# Callback to gather cpu usage
def get_cpu_usage_callback(observer):
for (number, percent) in enumerate(psutil.cpu_percent(percpu=True)):
labels = {"cpu_number": str(number)}
observer.observe(percent, labels)


meter.register_observer(
callback=get_cpu_usage_callback,
name="cpu_percent",
description="per-cpu usage",
unit="1",
value_type=float,
label_keys=("cpu_number",),
)


# Callback to gather RAM memory usage
def get_ram_usage_callback(observer):
ram_percent = psutil.virtual_memory().percent
observer.observe(ram_percent, {})


meter.register_observer(
callback=get_ram_usage_callback,
name="ram_percent",
description="RAM memory usage",
unit="1",
value_type=float,
label_keys=(),
)

input("Metrics will be printed soon. Press a key to finish...\n")
4 changes: 2 additions & 2 deletions azure_monitor/examples/metrics/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
label_keys=("environment",),
)

testing_label_set = meter.get_label_set({"environment": "testing"})
testing_labels = {"environment": "testing"}

requests_counter.add(25, testing_label_set)
requests_counter.add(25, testing_labels)

input("Press any key to exit...")
2 changes: 1 addition & 1 deletion azure_monitor/examples/traces/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Installation

```sh
$ pip install opentelemetry-azure-monitor-exporter
$ pip install opentelemetry-azure-monitor
```

## Run the Applications
Expand Down
6 changes: 3 additions & 3 deletions azure_monitor/examples/traces/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# pylint: disable=no-name-in-module
import requests
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

from azure_monitor import AzureMonitorSpanExporter

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
http_requests.enable(trace.get_tracer_provider())
RequestsInstrumentor().instrument()
span_processor = BatchExportSpanProcessor(
AzureMonitorSpanExporter(
# connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>"
connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>"
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
4 changes: 2 additions & 2 deletions azure_monitor/examples/traces/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# pylint: disable=no-name-in-module
import requests
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

from azure_monitor import AzureMonitorSpanExporter

trace.set_tracer_provider(TracerProvider())

http_requests.enable(trace.get_tracer_provider())
RequestsInstrumentor().instrument()
span_processor = SimpleExportSpanProcessor(
AzureMonitorSpanExporter(
connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>"
Expand Down
12 changes: 8 additions & 4 deletions azure_monitor/examples/traces/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# pylint: disable=no-name-in-module
import requests
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.wsgi import OpenTelemetryMiddleware
from opentelemetry.ext.flask import FlaskInstrumentor
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

Expand All @@ -29,9 +29,13 @@
# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(trace.get_tracer_provider())

# Enable instrumentation in the requests library.
RequestsInstrumentor().instrument()

app = flask.Flask(__name__)
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)
# Enable instrumentation in the flask library.
FlaskInstrumentor().instrument_app(app)


@app.route("/")
Expand Down
10 changes: 5 additions & 5 deletions azure_monitor/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Licensed under the MIT License.
[metadata]
name = opentelemetry-azure-monitor
description = Azure Monitor integration for OpenTelemetry
long_description = file: README.rst
long_description_content_type = text/x-rst
description = Azure Monitor SDKs and Exporters for OpenTelemetry
long_description = file: README.md
long_description_content_type = text/markdown
author = Microsoft
author_email = appinsightssdk@microsoft.com
url = https://github.com/microsoft/opentelemetry-azure-monitor-python
Expand All @@ -27,8 +27,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api >= 0.5b0
opentelemetry-sdk >= 0.5b0
opentelemetry-api ~= 0.7b1
opentelemetry-sdk ~= 0.7b1
psutil >= 5.6.3
requests ~= 2.0

Expand Down
20 changes: 12 additions & 8 deletions azure_monitor/src/azure_monitor/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _transmit(self, envelopes: typing.List[Envelope]) -> ExportResult:
for error in data["errors"]:
if error["statusCode"] in (
429, # Too Many Requests
439, # Too Many Requests over extended time
500, # Internal Server Error
503, # Service Unavailable
):
Expand Down Expand Up @@ -172,6 +173,7 @@ def _transmit(self, envelopes: typing.List[Envelope]) -> ExportResult:
if response.status_code in (
206, # Partial Content
429, # Too Many Requests
439, # Too Many Requests over extended time
500, # Internal Server Error
503, # Service Unavailable
):
Expand All @@ -185,18 +187,20 @@ def _transmit(self, envelopes: typing.List[Envelope]) -> ExportResult:
def get_trace_export_result(result: ExportResult) -> SpanExportResult:
if result == ExportResult.SUCCESS:
return SpanExportResult.SUCCESS
if result == ExportResult.FAILED_RETRYABLE:
return SpanExportResult.FAILED_RETRYABLE
if result == ExportResult.FAILED_NOT_RETRYABLE:
return SpanExportResult.FAILED_NOT_RETRYABLE
if result in (
ExportResult.FAILED_RETRYABLE,
ExportResult.FAILED_NOT_RETRYABLE,
):
return SpanExportResult.FAILURE
return None


def get_metrics_export_result(result: ExportResult) -> MetricsExportResult:
if result == ExportResult.SUCCESS:
return MetricsExportResult.SUCCESS
if result == ExportResult.FAILED_RETRYABLE:
return MetricsExportResult.FAILED_RETRYABLE
if result == ExportResult.FAILED_NOT_RETRYABLE:
return MetricsExportResult.FAILED_NOT_RETRYABLE
if result in (
ExportResult.FAILED_RETRYABLE,
ExportResult.FAILED_NOT_RETRYABLE,
):
return MetricsExportResult.FAILURE
return None
Loading

0 comments on commit 66321f4

Please sign in to comment.