Name Date Size #Lines LOC

..--

gradle/wrapper/H25-Apr-2025-65

spring/servlet/H25-Apr-2025-688494

src/main/H25-Apr-2025-2,2871,422

README.mdH A D25-Apr-20255 KiB201149

build.gradleH A D25-Apr-20259.6 KiB272235

gradlewH A D25-Apr-20255.2 KiB173128

gradlew.batH A D25-Apr-20252.2 KiB8561

pom.xmlH A D25-Apr-202510.3 KiB292290

settings.gradleH A D25-Apr-202541 21

README.md

1# OpenCensus Examples
2
3## To build the examples use
4
5### Gradle
6```bash
7./gradlew installDist
8```
9
10### Maven
11```bash
12mvn package appassembler:assemble
13```
14
15To build Spring Servlet example
16```bash
17cd spring/servlet
18mvn package appassembler:assemble
19```
20
21
22## To run "TagContextExample" use
23
24### Gradle
25```bash
26./build/install/opencensus-examples/bin/TagContextExample
27```
28
29### Maven
30```bash
31./target/appassembler/bin/TagContextExample
32```
33
34## To run "ZPagesTester"
35
36### Gradle
37```bash
38./build/install/opencensus-examples/bin/ZPagesTester
39```
40
41### Maven
42```bash
43./target/appassembler/bin/ZPagesTester
44```
45
46Available pages:
47* For tracing page go to [localhost:8080/tracez][ZPagesTraceZLink].
48* For tracing config page go to [localhost:8080/traceconfigz][ZPagesTraceConfigZLink].
49* For RPC stats page go to [localhost:8080/rpcz][ZPagesRpcZLink].
50* For stats and measures on all registered views go to [localhost:8080/statsz][ZPagesStatsZLink].
51
52[ZPagesTraceZLink]: http://localhost:8080/tracez
53[ZPagesTraceConfigZLink]: http://localhost:8080/traceconfigz
54[ZPagesRpcZLink]: http://localhost:8080/rpcz
55[ZPagesStatsZLink]: http://localhost:8080/statsz
56
57## To run "QuickStart" example use
58
59### Gradle
60```bash
61./build/install/opencensus-examples/bin/QuickStart
62```
63
64### Maven
65```bash
66./target/appassembler/bin/QuickStart
67```
68
69## To run "gRPC Hello World" example use
70
71Please note all the arguments are optional. If you do not specify these arguments, default values
72will be used:
73
74* host and serverPort will be "localhost:50051"
75* user will be "world"
76* cloudProjectId will be null (which means no stats/spans will be exported to Stackdriver)
77* server zPagePort will be 3000
78* client zPagePort will be 3001
79* Prometheus port will be 9090
80
81
82However, if you want to specify any of these arguements, please make sure they are in order.
83
84### Gradle
85```bash
86./build/install/opencensus-examples/bin/HelloWorldServer serverPort cloudProjectId zPagePort prometheusPort
87./build/install/opencensus-examples/bin/HelloWorldClient user host serverPort cloudProjectId zPagePort
88```
89
90### Maven
91```bash
92./target/appassembler/bin/HelloWorldServer serverPort cloudProjectId zPagePort prometheusPort
93./target/appassembler/bin/HelloWorldClient user host serverPort cloudProjectId zPagePort
94```
95
96## To run "Repl" example
97
98See the full tutorial on [OpenCensus website](https://opencensus.io/quickstart/java/metrics/).
99
100First run:
101
102### Gradle
103```bash
104./build/install/opencensus-examples/bin/Repl
105```
106
107### Maven
108```bash
109./target/appassembler/bin/Repl
110```
111
112Then start the Prometheus process:
113```bash
114cd src/main/java/io/opencensus/examples/quickstart/
115prometheus --config.file=prometheus.yaml
116```
117
118Stats will be shown on Prometheus UI on http://localhost:9090.
119
120## To run "StackdriverQuickstart" use
121
122See the full tutorial on [OpenCensus website](https://opencensus.io/guides/exporters/supported-exporters/java/stackdriver/).
123
124### Gradle
125```bash
126./build/install/opencensus-examples/bin/StackdriverQuickstart
127```
128
129### Maven
130```
131./target/appassembler/bin/StackdriverQuickstart
132```
133
134## To run HTTP Server and Client
135
136`HttpJettyServer` is a web service using Jetty Server on top of http-servlet.
137`HttpJettyClient` is a web client using Jetty Client that sends request to `HttpettyServer`.
138Both `HttpJettyServer` and `HttpJettyClient` are instrumented with OpenCensus.
139
140Traces from both client and server can be viewed in their respective logs on console.
141Stats are available from Prometheus server running at
142- http://localhost:9091/metrics - for client stats
143- http://localhost:9090/metrics - for server stats
144
145
146### Gradle
147```bash
148./build/install/opencensus-examples/bin/HttpJettyServer
149./build/install/opencensus-examples/bin/HttpJettyClient
150```
151
152### Maven
153```bash
154./target/appassembler/bin/HttpJettyServer
155./target/appassembler/bin/HttpJettyClient
156```
157
158## To run OcAgentExportersQuickStart
159
160### Gradle
161```bash
162./build/install/opencensus-examples/bin/OcAgentExportersQuickStart agentEndpoint # default is localhost:56678
163```
164
165### Maven
166```bash
167./target/appassembler/bin/OcAgentExportersQuickStart agentEndpoint # default is localhost:56678
168```
169
170You also need to install and start OpenCensus-Agent in order to receive the traces and metrics.
171For more information on setting up Agent, see [tutorial](https://opencensus.io/agent/).
172
173## To run Spring HTTP Server and Client
174
175`SpringServletApplication` is a web service application using Spring framework. The application
176is instrumented with opencensus simply by incuding opencensus-contrib-spring-starter package.
177The instrumentation enables tracing on incoming and outgoing http requests. On receiving GET
178request, the server originates multiple GET requests to itself using AsyncRestTemplate on different
179endpoint.
180
181Send a http GET request using curl to see the traces on console.
182```
183curl http://localhost:8080
184```
185
186Stats are available from Prometheus server running at
187- http://localhost:9090/metrics - for server and client stats
188
189### Gradle
190```bash
191cd spring/servlet
192./gradlew bootRun
193```
194
195### Maven
196```bash
197cd spring/servlet
198./target/appassembler/bin/SpringServletApplication
199```
200
201