Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e523140

Browse files
authored
Implement Azure Monitor Exporter (open-telemetry#175)
1 parent 764d317 commit e523140

File tree

7 files changed

+491
-5
lines changed

7 files changed

+491
-5
lines changed

ext/opentelemetry-ext-azure-monitor/README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ OpenTelemetry Azure Monitor Exporters
33

44
This library provides integration with Microsoft Azure Monitor.
55

6+
Installation
7+
------------
8+
9+
::
10+
11+
pip install opentelemetry-ext-azure-monitor
12+
613
References
714
----------
815

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 opentelemetry import trace
18+
from opentelemetry.ext import http_requests
19+
from opentelemetry.ext.azure_monitor import AzureMonitorSpanExporter
20+
from opentelemetry.sdk.trace import Tracer
21+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
22+
23+
trace.set_preferred_tracer_implementation(lambda T: Tracer())
24+
tracer = trace.tracer()
25+
http_requests.enable(tracer)
26+
span_processor = BatchExportSpanProcessor(AzureMonitorSpanExporter())
27+
tracer.add_span_processor(span_processor)
28+
29+
response = requests.get(url="http://127.0.0.1:5000/")
30+
span_processor.shutdown()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 flask
16+
import requests
17+
18+
from opentelemetry import trace
19+
from opentelemetry.ext import http_requests
20+
from opentelemetry.ext.azure_monitor import AzureMonitorSpanExporter
21+
from opentelemetry.ext.wsgi import OpenTelemetryMiddleware
22+
from opentelemetry.sdk.trace import Tracer
23+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
24+
25+
trace.set_preferred_tracer_implementation(lambda T: Tracer())
26+
27+
http_requests.enable(trace.tracer())
28+
span_processor = BatchExportSpanProcessor(AzureMonitorSpanExporter())
29+
trace.tracer().add_span_processor(span_processor)
30+
31+
app = flask.Flask(__name__)
32+
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)
33+
34+
35+
@app.route("/")
36+
def hello():
37+
with trace.tracer().start_span("parent"):
38+
requests.get("https://www.wikipedia.org/wiki/Rabbit")
39+
return "hello"
40+
41+
42+
if __name__ == "__main__":
43+
app.run(debug=True)
44+
span_processor.shutdown()

ext/opentelemetry-ext-azure-monitor/examples/trace.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
from opentelemetry import trace
216
from opentelemetry.ext.azure_monitor import AzureMonitorSpanExporter
317
from opentelemetry.sdk.trace import Tracer
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Copyright 2019, OpenTelemetry 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+
16+
class BaseObject(dict):
17+
def __init__(self, *args, **kwargs):
18+
super().__init__(*args, **kwargs)
19+
for key in kwargs:
20+
self[key] = kwargs[key]
21+
22+
def __repr__(self):
23+
tmp = {}
24+
current = self
25+
while True:
26+
for item in current.items():
27+
if item[0] not in tmp:
28+
tmp[item[0]] = item[1]
29+
if (
30+
current._default # noqa pylint: disable=protected-access
31+
== current
32+
):
33+
break
34+
current = current._default # noqa pylint: disable=protected-access
35+
return repr(tmp)
36+
37+
def __setattr__(self, name, value):
38+
self[name] = value
39+
40+
def __getattr__(self, name):
41+
try:
42+
return self[name]
43+
except KeyError:
44+
raise AttributeError(
45+
"'{}' object has no attribute {}".format(
46+
type(self).__name__, name
47+
)
48+
)
49+
50+
def __getitem__(self, key):
51+
if self._default is self:
52+
return super().__getitem__(key)
53+
if key in self:
54+
return super().__getitem__(key)
55+
return self._default[key]
56+
57+
58+
BaseObject._default = BaseObject() # noqa pylint: disable=protected-access
59+
60+
61+
class Data(BaseObject):
62+
_default = BaseObject(baseData=None, baseType=None)
63+
64+
def __init__(self, *args, **kwargs):
65+
super().__init__(*args, **kwargs)
66+
self.baseData = self.baseData # noqa pylint: disable=invalid-name
67+
self.baseType = self.baseType # noqa pylint: disable=invalid-name
68+
69+
70+
class DataPoint(BaseObject):
71+
_default = BaseObject(
72+
ns="",
73+
name="",
74+
kind=None,
75+
value=0.0,
76+
count=None,
77+
min=None,
78+
max=None,
79+
stdDev=None,
80+
)
81+
82+
def __init__(self, *args, **kwargs):
83+
super().__init__(*args, **kwargs)
84+
self.name = self.name
85+
self.value = self.value
86+
87+
88+
class Envelope(BaseObject):
89+
_default = BaseObject(
90+
ver=1,
91+
name="",
92+
time="",
93+
sampleRate=None,
94+
seq=None,
95+
iKey=None,
96+
flags=None,
97+
tags=None,
98+
data=None,
99+
)
100+
101+
def __init__(self, *args, **kwargs):
102+
super().__init__(*args, **kwargs)
103+
self.name = self.name
104+
self.time = self.time
105+
106+
107+
class Event(BaseObject):
108+
_default = BaseObject(ver=2, name="", properties=None, measurements=None)
109+
110+
def __init__(self, *args, **kwargs):
111+
super().__init__(*args, **kwargs)
112+
self.ver = self.ver
113+
self.name = self.name
114+
115+
116+
class ExceptionData(BaseObject):
117+
_default = BaseObject(
118+
ver=2,
119+
exceptions=[],
120+
severityLevel=None,
121+
problemId=None,
122+
properties=None,
123+
measurements=None,
124+
)
125+
126+
def __init__(self, *args, **kwargs):
127+
super().__init__(*args, **kwargs)
128+
self.ver = self.ver
129+
self.exceptions = self.exceptions
130+
131+
132+
class Message(BaseObject):
133+
_default = BaseObject(
134+
ver=2,
135+
message="",
136+
severityLevel=None,
137+
properties=None,
138+
measurements=None,
139+
)
140+
141+
def __init__(self, *args, **kwargs):
142+
super().__init__(*args, **kwargs)
143+
self.ver = self.ver
144+
self.message = self.message
145+
146+
147+
class MetricData(BaseObject):
148+
_default = BaseObject(ver=2, metrics=[], properties=None)
149+
150+
def __init__(self, *args, **kwargs):
151+
super().__init__(*args, **kwargs)
152+
self.ver = self.ver
153+
self.metrics = self.metrics
154+
155+
156+
class RemoteDependency(BaseObject):
157+
_default = BaseObject(
158+
ver=2,
159+
name="",
160+
id="",
161+
resultCode="",
162+
duration="",
163+
success=True,
164+
data=None,
165+
type=None,
166+
target=None,
167+
properties=None,
168+
measurements=None,
169+
)
170+
171+
def __init__(self, *args, **kwargs):
172+
super().__init__(*args, **kwargs)
173+
self.ver = self.ver
174+
self.name = self.name
175+
self.resultCode = self.resultCode # noqa pylint: disable=invalid-name
176+
self.duration = self.duration
177+
178+
179+
class Request(BaseObject):
180+
_default = BaseObject(
181+
ver=2,
182+
id="",
183+
duration="",
184+
responseCode="",
185+
success=True,
186+
source=None,
187+
name=None,
188+
url=None,
189+
properties=None,
190+
measurements=None,
191+
)
192+
193+
def __init__(self, *args, **kwargs):
194+
super().__init__(*args, **kwargs)
195+
self.ver = self.ver
196+
self.id = self.id # noqa pylint: disable=invalid-name
197+
self.duration = self.duration
198+
self.responseCode = ( # noqa pylint: disable=invalid-name
199+
self.responseCode
200+
)
201+
self.success = self.success

0 commit comments

Comments
 (0)