Skip to content

Commit e4b723a

Browse files
authored
Merge pull request #77209 from mrbullwinkle/mrb_05_20_2019_python
update script blocks
2 parents 3fbdb63 + 7d0849b commit e4b723a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

articles/azure-monitor/app/opencensus-python.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ First you have to create an Application Insights resource which will generate an
7373

7474
## OpenCensus Python package
7575

76-
1. Install the Open Census package for Python with pip or pipenv from the command line:
76+
1. Install the Open Census package for Python and exporter with pip or pipenv from the command line:
7777

78-
```python
78+
```console
7979
python -m pip install opencensus
80+
python -m pip install opencensus-ext-ocagent
81+
8082
# pip env install opencensus
8183
```
8284

@@ -87,20 +89,20 @@ First you have to create an Application Insights resource which will generate an
8789

8890
```python
8991
from opencensus.trace.tracer import Tracer
90-
92+
9193
def main():
9294
while True:
9395
valuePrompt()
94-
96+
9597
def valuePrompt():
9698
tracer = Tracer()
9799
with tracer.span(name="test") as span:
98100
line = input("Enter a value: ")
99101
print(line)
100-
102+
101103
if __name__ == "__main__":
102104
main()
103-
105+
104106
```
105107

106108
3. Running the code will repeatedly prompt you to enter a value. With each entry, the value will be printed to the shell, and a corresponding piece of **SpanData** will be generated by the OpenCensus Python Module. The OpenCensus project defines a [_trace as a tree of spans_](https://opencensus.io/core-concepts/tracing/).
@@ -122,32 +124,33 @@ First you have to create an Application Insights resource which will generate an
122124
```python
123125
from opencensus.trace.tracer import Tracer
124126
from opencensus.trace import config_integration
125-
from opencensus.trace.exporters.ocagent import trace_exporter
127+
from opencensus.ext.ocagent.trace_exporter import TraceExporter
126128
from opencensus.trace import tracer as tracer_module
127-
129+
128130
import os
129-
130-
def main():
131+
132+
def main():
131133
while True:
132134
valuePrompt()
133-
135+
134136
def valuePrompt():
135-
export_LocalForwarder = trace_exporter.TraceExporter(
137+
export_LocalForwarder = TraceExporter(
136138
service_name=os.getenv('SERVICE_NAME', 'python-service'),
137139
endpoint=os.getenv('OCAGENT_TRACE_EXPORTER_ENDPOINT'))
138-
140+
139141
tracer = Tracer(exporter=export_LocalForwarder)
140142
with tracer.span(name="test") as span:
141143
line = input("Enter a value: ")
142144
print(line)
143-
145+
144146
if __name__ == "__main__":
145147
main()
148+
146149
```
147150

148151
5. If you save and try running the above module, you may receive a `ModuleNotFoundError` for `grpc`. If this occurs run the following to install the [grpcio package](https://pypi.org/project/grpcio/) with:
149152

150-
```
153+
```console
151154
python -m pip install grpcio
152155
```
153156

0 commit comments

Comments
 (0)