Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 3b60af7

Browse files
authored
Initial version of Azure extension (#613)
Introduced a new package opencensus-ext-azure. Implemented the skeleton of Azure trace exporter. Fixed the example in opencensus-ext-flask (now it is in-sync with the doc). Increased the test_transport.py interval to 0.1 second (it keeps failing on Windows machine with anti-virus software).
1 parent b5b0332 commit 3b60af7

File tree

22 files changed

+1032
-10
lines changed

22 files changed

+1032
-10
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ OpenCensus supports integration with popular web frameworks, client libraries an
234234
Trace Exporter
235235
--------------
236236

237+
- `Azure`_
237238
- `Jaeger`_
238239
- `OCAgent`_
239240
- `Stackdriver`_
@@ -245,6 +246,7 @@ Stats Exporter
245246
- `Prometheus`_
246247
- `Stackdriver`_
247248

249+
.. _Azure: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-azure
248250
.. _Django: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-django
249251
.. _Flask: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-flask
250252
.. _Google Cloud Client Libraries: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-google-cloud-clientlibs
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## Unreleased
4+
- Initial project skeleton
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
OpenCensus Azure Monitor Trace Exporter
2+
============================================================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opencensus-ext-azure.svg
7+
:target: https://pypi.org/project/opencensus-ext-azure/
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install opencensus-ext-azure
15+
16+
Usage
17+
-----
18+
19+
.. code:: python
20+
21+
# TBD
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import requests
16+
17+
from opencensus.ext.azure.trace_exporter import AzureExporter
18+
from opencensus.trace import config_integration
19+
from opencensus.trace.propagation.trace_context_http_header_format \
20+
import TraceContextPropagator
21+
from opencensus.trace.tracer import Tracer
22+
23+
if __name__ == '__main__':
24+
config_integration.trace_integrations(['requests'])
25+
tracer = Tracer(
26+
propagator=TraceContextPropagator(),
27+
exporter=AzureExporter(),
28+
)
29+
with tracer.span(name='parent'):
30+
with tracer.span(name='child'):
31+
response = requests.get(url='http://localhost:8080/')
32+
print(response.status_code)
33+
print(response.text)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from flask import Flask
16+
import requests
17+
18+
from opencensus.trace import config_integration
19+
from opencensus.ext.azure.trace_exporter import AzureExporter
20+
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
21+
from opencensus.trace.propagation.trace_context_http_header_format \
22+
import TraceContextPropagator
23+
24+
app = Flask(__name__)
25+
middleware = FlaskMiddleware(
26+
app,
27+
exporter=AzureExporter(),
28+
propagator=TraceContextPropagator(),
29+
)
30+
31+
32+
@app.route('/')
33+
def hello():
34+
requests.get('https://www.wikipedia.org/wiki/Rabbit')
35+
return 'Hello, World!'
36+
37+
38+
if __name__ == '__main__':
39+
import logging
40+
logger = logging.getLogger('werkzeug')
41+
logger.setLevel(logging.ERROR)
42+
config_integration.trace_integrations(['requests'])
43+
app.run(host='localhost', port=8080, threaded=True)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from opencensus.ext.azure.trace_exporter import AzureExporter
16+
from opencensus.trace import tracer as tracer_module
17+
18+
tracer = tracer_module.Tracer(exporter=AzureExporter())
19+
20+
if __name__ == '__main__':
21+
with tracer.span(name='foo') as foo:
22+
with foo.span(name='bar'):
23+
print('Hello, World!')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from opencensus.ext.azure.common.protocol import Object
18+
19+
20+
class Options(Object):
21+
prototype = Object(
22+
endpoint='https://dc.services.visualstudio.com/v2/track',
23+
instrumentation_key=os.getenv('APPINSIGHTS_INSTRUMENTATIONKEY', None),
24+
proxy=None,
25+
timeout=5.0, # timeout in seconds
26+
)

0 commit comments

Comments
 (0)