This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
erlang.html
318 lines (269 loc) · 19.5 KB
/
erlang.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en">
<head>
<!-- GOOGLE ANALYTICS SNIPPET -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-115468315-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-115468315-1');
</script>
<!-- END GOOGLE ANALYTICS -->
<meta charset="utf-8">
<!-- Always force latest IE rendering engine -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Mobile Specific Meta -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="DESCRIPTION">
<meta name="keywords" content="KEYWORDS">
<meta name="author" content="AUTHOR NAME">
<!-- TITLE -->
<title>Erlang</title>
<!-- FAVICON -->
<link href=favicon.ico rel="icon">
<link rel="apple-touch-icon" sizes="72x72" href="favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicon/apple-icon-114x114.png">
<link rel="manifest" href="favicon/site.webmanifest">
<link rel="apple-touch-icon" href="favicon/apple-touch-icon.png">
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="theme-color" content="#ffffff">
<!-- BOOTSTRAP CSS -->
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
<!-- FONT-AWESOME & ET-LINE-FONT CSS -->
<link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/et-line-font/et-line-font.css">
<!-- MAGNIFIC POPUP CORE CSS -->
<link href="css/magnific-popup/magnific-popup.css" rel="stylesheet">
<!-- OWL CAROUSEL -->
<link href="css/owl-carousel/owl.carousel.min.css" rel="stylesheet">
<link href="css/owl-carousel/owl.theme.default.min.css" rel="stylesheet">
<!-- MAIN STYLE CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- RESPONSIVE STYLE CSS -->
<link rel="stylesheet" href="css/responsive.css">
<!-- COLORS CSS -->
<link rel="stylesheet" href="css/colors/red.css">
</head>
<body>
<!-- ====== Preloader ====== -->
<div class="loading">
<div class="load-circle">
</div>
</div>
<!-- ======End Preloader ====== -->
<!-- ====== HEADER START ====== -->
<section class="t-header" id="home" data-scroll-index="0">
<div class="header-overlay">
<!-- ====== NAVGITION ====== -->
<nav class="navbar land-nav navbar-fixed-top">
<div class="container">
<div class="row">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- logo -->
<a class="logo navbar-brand" href="index.html"><ul><li><img src="img/logo-sm.png"/> Open<span>Census</span></li></ul>
</a>
</div>
<!-- Collect the nav links, and other content for toggling -->
<div class="collapse navbar-collapse" id="collapse">
<!-- links -->
<ul class="nav navbar-nav navbar-right" id="navbar">
<li><a href="overview.html">Overview</a></li>
<!-- LANGUAGES NAV DROPDOWN -->
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="margin-left:10px"> Languages <b class="caret"></b></a>
<ul class="dropdown-menu">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li style="droplist"><a href="cpp.html">C++</a></li>
<li style="droplist"><a href="go.html">Go</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li style="droplist"><a href="erlang.html">Erlang</a></li>
<li style="droplist"><a href="java.html">Java</a></li>
<li style="droplist"><a href="ruby.html">Ruby</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li style="droplist"><a href="php.html">PHP</a></li>
<li style="droplist"><a href="python.html">Python</a></li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
<!-- END LANGUAGES NAV DROPDOWN -->
<li><a href="docs.html">Docs</a></li>
<li><a href="glossary.html">Glossary</a></li>
<li><a href="roadmap.html">Roadmap</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="faq.html">FAQ</a></li>
<li><a href="about.html">About</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</div><!-- /.container -->
</nav>
<!-- ====== END NAVGITION ====== -->
</div>
</section>
<!-- ====== HEADER END ====== -->
<!-- ====== ERLANG START ====== -->
<section class="sections lang" id="lang">
<div class="container">
<!-- ====== MIDDLE NAVGITION ====== -->
<div class="row">
<div class="title">
<div class="lang-con1 col-sm-12">
<p><a href="https://github.com/census-instrumentation/opencensus-website/blob/master/README.md">Contribution Guidelines</a></p>
<p> | </p>
<p><a href="https://github.com/census-instrumentation/opencensus-website/edit/master/static/v2/erlang.html"><span class="fa fa-github"></span> Edit <b>erlang.html</b></a></p>
</div>
</div>
</div>
<!-- ====== END MIDDLE NAVGITION ====== -->
</div>
<div class="container">
<div class="row">
<!-- ERLANG CONTENT START -->
<div class="title">
<!-- LEFT COULMN -->
<div class="col-md-3 box" style="margin-left:5px">
<h4>Quickstart</h4>
<hr>
<ul>
<li><p><a href="cpp.html">C++</a></p></li>
<li><p><a href="erlang.html"class="active"> Erlang</a></p></li>
<li><p><a href="go.html">Go</a></p></li>
<li><p><a href="java.html">Java</a></p></li>
<!-- <li><p><a href="dotnet.html">.NET</a></p></li>
<li><p><a href="nodejs.html">Node.js</a></p></li> -->
<li><p><a href="php.html">PHP</a></p></li>
<li><p><a href="python.html">Python</a></p></li>
<li><p><a href="ruby.html">Ruby</a></p></li>
<!-- <li><p><a href="webjs.html">Web JS</a></p></li> -->
</ul><hr><br>
</div>
<!-- END LEFT COULMN -->
<!-- CENTER COULMN -->
<div class="col-md-8 box" style="margin-left:5px">
<h1>Erlang Quickstart</h1><br>
<p>The example demonstrates how to record stats and traces for a video processing system. It records data with the "frontend" tag so that collected data can be broken by the frontend user who initiated the video processing. Code for this example can be found under the <span class="code1">examples/helloworld</span> directory of the <a href="https://github.com/census-instrumentation/opencensus-erlang"><span class="gloss1">OpenCensus Erlang repo</span></a>.</p><br><hr><br>
<h4>API Documentation</h4>
<p>The OpenCensus Erlang API artifact is available <a href="https://hexdocs.pm/opencensus/0.3.0/index.html"><span class="gloss1">here</span></a>.</p><br><hr><br>
<h4>Example</h4>
<p><b>Prerequisite</b><br><a href="http://www.erlang.org/"><span class="gloss1">Erlang/OTP 20</span></a> and <a href="http://www.rebar3.org/"><span class="gloss1">rebar3</span></a> are required.</p><br><br>
<p><b>Using</b><br>Create a new Erlang application with <span class="code1">rebar3 new</span> named <span class="code1">helloworld</span>:</p>
<p><pre><code>$ rebar3 new app helloworld<br>===> Writing helloworld/src/helloworld_app.erl<br>===> Writing helloworld/src/helloworld_sup.erl<br>===> Writing helloworld/src/helloworld.app.src<br>===> Writing helloworld/rebar.config<br>===> Writing helloworld/.gitignore<br>===> Writing helloworld/LICENSE<br>===> Writing helloworld/README.md<br>$ cd helloworld</code></pre></p><br><br>
<p>Add <span class="code1">opencensus</span> as a dependency in <span class="code1">rebar.config</span>. For development purposes it is also useful to include the <span class="code1">shell</span> section of the config which tells rebar3 to boot the application and load configuration when running <span class="code1">rebar3 shell</span>:</p>
<p><pre><code>{erl_opts, [debug_info]}.<br>{deps, [opencensus]}.<br><br>{shell, [{apps, [helloworld]},<br> {config, "config/sys.config"}]}.</code></pre></p><br>
<p><pre><code>[<br>{opencensus, [{sampler, {oc_sampler_always, []}},<br> {reporter, {oc_reporter_stdout, []}},<br> {stat, [{exporters, [{oc_stat_exporter_stdout, []}]}]}<br>].</code></pre></p><br><br>
<p><span class="code1">opencensus</span> is a runtime dependency so it is added to the applications list in <span class="code1">src/helloworld.app.src</span>, ensuring it is included and started in a release of <span class="code1">helloworld</span>:</p>
<p><pre><code>{application, helloworld,<br> [{description, "Example OpenCensus application"},<br> {vsn, "0.1.0"},<br> {registered, []},<br> {mod, { helloworld_app, []}},<br> {applications,<br> [kernel,<br> stdlib,<br> opencensus<br> ]},<br> {env,[]},<br> {modules, []},<br><br> {maintainers, []},<br> {licenses, ["Apache 2.0"]},<br> {links, []}<br>]}.</code></pre></p><br><br>
<p>Building the application with <span class="code1">rebar3 compile</span> will fetch the OpenCensus Erlang library and its dependencies.</p><br>
<p>When our application starts it needs to create and subscribe to the statistics that we'll record. So a call to <span class="code1">subscribe_views/0</span> is added to the application start function, <span class="code1">helloworld_app:start/2</span>:</p>
<p><pre><code>subscribe_views() -><br> oc_stat_view:subscribe(#{name => "video_size",<br> description => "size of processed videos",<br> tags => ['frontend'],<br> measure => 'my.org/measure/video_size',<br> aggregation => default_size_distribution()}).<br><br>default_size_distribution() -><br> {oc_stat_aggregation_distribution,<br> [{buckets, [0, 1 bsl 16, 1 bsl 32]}]}.</code></pre></p><br><br>
<p>The main module called to actually do the video processing is <span class="code1">helloworld</span>. It creates a tag for who made the process request to include with the record statistic and creates a span for the duration of the video processing (a random sleep between 0 and 10 seconds):</p>
<p><pre><code>-module(helloworld).<br><br>-export([process/0]).<br><br>process() -><br> %% create a tag for who sent the request and start a child span<br> Tags = oc_tags:new(#{'frontend' => "mobile-ios9.3.5"}),<br> ocp:with_child_span(<<"my.org/ProcessVideo">>),<br><br> %% sleep for 0-10 seconds to simulate processing time<br> timer:sleep(timer:seconds(rand:uniform(10))),<br><br> %% finish the span<br> ocp:finish_span(),<br><br> %% record the size of the video<br> oc_stat:record(Tags, 'my.org/measure/video_size', 25648).</code></pre></p><br><br>
<p>Run the application with <span class="code1">rebar3 shell</span> and see the stats and span reported to the console:</p>
<p><pre><code>$ rebar3 shell<br>...<br>===> Booted opencensus<br>===> Booted helloworld<br>> helloworld:process().<br>ok<br>{span,<<"my.org/ProcessVideo">>,1201374966367397737078249396493886473,<br> 10421649746227310879,undefined,1,<br> {-576460748652616660,2097430124176280981},<br> {-576460740651723247,2097430124176280981},<br> #{},undefined,[],[],undefined,undefined,undefined}<br>video_size: #{rows =><br> [#{tags => #{"frontend" => "mobile-ios9.3.5"},<br> value =><br> #{buckets =><br> [{0,0},{65536,1},{4294967296,0},{infinity,0}],<br> count => 1,mean => 25648.0,sum => 25648}}],<br> type => distribution}</code></pre></p><br><br>
</div>
<!-- END CENTER COULMN -->
<!-- ERLANG CONTENT END -->
</div>
</div>
</div>
</section>
<!-- ====== ERLANG END ====== -->
<!-- ====== CONTACT START ====== -->
<section class="sections contact" id="contact">
<div class="container">
<div class="row">
<div class="item">
<!-- FOOTER LINKS START -->
<!-- LEFTS LINKS FORM START -->
<div class="left-links">
<div class="col-md-6">
<p class="lead">OpenCensus</p>
<p>Copyright © OpenCensus 2018 | All Rights Reserved.</p>
<br>
</div>
</div>
<!-- LEFT LINKS END -->
<!-- RIGHT LINKS START -->
<!-- DOCUMENTS START -->
<div class="col-md-2">
<h6 class="ctit">Documents</h6>
<p><a href="overview.html">Overview</a></p><br>
<p><a href="quickstart.html">Quickstart</a></p><br>
<p><a href="guides.html">Guides</a></p><br>
<p><a href="https://github.com/census-instrumentation">Tutorials</a></p><br>
<p><a href="reference.html">API Reference</a></p><br>
</div>
<!-- DOCUMENTS END -->
<!-- RESOURCES START -->
<div class="col-md-2">
<h6 class="ctit">Resources</h6>
<p><a href="about.html">About</a></p><br>
<p><a href="blog.html">Blog</a></p><br>
<p><a href="faq.html">FAQ</a></p><br>
<p><a href="glossary.html">Glossary</a></p><br>
</div>
<!-- RESOURCES END -->
<!-- COMMUNITY START -->
<div class="col-md-2">
<h6 class="ctit">Community</h6>
<p><a href="community.html">Community</a></p><br>
<p><a href="https://github.com/census-instrumentation">Github</a></p><br>
<p><a href="https://twitter.com/opencensusio">Twitter</a></p><br>
<p><a href="https://www.facebook.com/opencensus">Facebook</a></p><br>
<p><a href="https://plus.google.com/communities/112482248706262039896">Google+</a></p><br>
<p><a href="https://gitter.im/census-instrumentation/Lobby">Gitter</a></p><br>
</div>
<!-- COMMUNITY END -->
<!-- FOOTER LINKS END -->
</div>
</div>
</div>
</section>
<!-- ====== CONTACT END ====== -->
<!-- ====== JS ====== -->
<!-- JQUERY -->
<script src="js/jquery.v1.12.4.js"></script>
<!-- BOOTSTRAP JS -->
<script src="js/bootstrap.min.js"></script>
<!-- COUNT TO JS -->
<script src="js/jquery.countTo.js"></script>
<!-- ISOTOPE JS -->
<script src="js/isotope.pkgd.min.js"></script>
<!-- MASONRY JS -->
<script src="js/masonry.pkgd.min.js"></script>
<!-- Magnific Popup core JS -->
<script src="js/jquery.magnific-popup.min.js"></script>
<!-- PARSLEY file -->
<script src="js/parsley.js"></script>
<!-- OWL CAROUSEL JS -->
<script src="js/owl.carousel.min.js"></script>
<!-- SCROLLIT file -->
<script src="js/scrollIt.min.js"></script>
<!-- ACCORDION JS -->
<script src="js/accordion.js"></script>
<!-- custom js -->
<script src="js/main.js"></script>
</body>
</html>