|
1 | 1 | # Apress Source Code
|
2 | 2 |
|
3 |
| -This repository accompanies [Practical OpenTelemetry: Adopting Open Observability Standards Across Your Organization](https://www.link.springer.com/book/10.1007/9781484290743) by Daniel Gomez Blanco (Apress, 2023). |
| 3 | +This repository accompanies [Practical OpenTelemetry: Adopting Open Observability Standards Across Your Organization](https://www.link.springer.com/book/10.1007/9781484290743) |
| 4 | +by Daniel Gomez Blanco (Apress, 2023). |
4 | 5 |
|
5 | 6 | [comment]: #cover
|
6 | 7 | 
|
7 | 8 |
|
8 | 9 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
|
9 | 10 |
|
| 11 | +## Scope |
| 12 | + |
| 13 | +As mentioned within the introduction, most code snippets in the book are meant |
| 14 | +to be considered in isolation to illustrate the concepts discussed in each chapter. The intention is not to create yet |
| 15 | +another full-fledged OpenTelemetry demo environment, so their source code has not been made available in this repo. This |
| 16 | +is intentional, as OpenTelemetry provides its official OpenTelemetry Demo (available at |
| 17 | +https://github.com/open-telemetry/opentelemetry-demo) for this purpose, which allows users to work with OpenTelemetry |
| 18 | +instrumented services and visualise the telemetry produced in the observability platform of their choice. |
| 19 | + |
| 20 | +However, *Chapter 4* demonstrates the power of standard instrumentation to automatically generate and export telemetry |
| 21 | +from within an existing Java application that has not been previously instrumented with OpenTelemetry. The resources in |
| 22 | +this project will make it easy for readers to stand up the examples described in this chapter. |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +This project relies on GNU Make, Git, Java and Docker to run the `dropwizard-example` application, available at |
| 27 | +https://github.com/dropwizard/dropwizard. It has been tested with the following versions: |
| 28 | + |
| 29 | +* MacOs Monterrey 12.5.1 |
| 30 | +* GNU Make 3.81 |
| 31 | +* Git 2.39.0 |
| 32 | +* curl 7.79.1 |
| 33 | +* Docker 20.10.20 |
| 34 | +* OpenJDK 17 |
| 35 | + |
| 36 | +The application and the (minimal) telemetry stack this application spins up consists of: |
| 37 | + |
| 38 | +* Dropwizard v2.1.1 |
| 39 | +* OpenTelemetry Java Agent 1.21.0 |
| 40 | +* OpenTelemetry Collector (Contrib) 0.64.0 |
| 41 | +* Prometheus 2.38.0 |
| 42 | +* Jaeger (All-in-One Distro) 1.37.0 |
| 43 | + |
| 44 | +To install and build the necessary resources: |
| 45 | + |
| 46 | +```shell |
| 47 | +make |
| 48 | +``` |
| 49 | + |
| 50 | +This will clone and build the `dropwizard-example` application. Even though tests are skipped to speed the process, this |
| 51 | +Maven build can still a little while to complete (the intention is not to deviate from the `dropwizard-example` build |
| 52 | +instructions). This step will also initialise the in-memory database, download the OpenTelemetry Java Agent and build |
| 53 | +our `cache-client-extension` processor. It is also possible to execute these steps individually as defined in the |
| 54 | +`Makefile`. |
| 55 | + |
| 56 | +Any changes to source code will be automatically rebuilt by running `make` again without the need to delete any |
| 57 | +resources. However, to clean up all build artefacts generated by this process, you can run: |
| 58 | + |
| 59 | +```shell |
| 60 | +make clean |
| 61 | +``` |
| 62 | + |
| 63 | +In addition to deleting build artefacts, this command will also delete any stopped Docker containers. |
| 64 | + |
| 65 | +## Running the application |
| 66 | +The `Makefile` provides a simple way to run the application in multiple modes, including the snippets in described in |
| 67 | +the book: |
| 68 | + |
| 69 | +```shell |
| 70 | +# Run the application without OpenTelemetry instrumentation |
| 71 | +make run-without-otel |
| 72 | + |
| 73 | +# Run the application with OpenTelemetry instrumentation |
| 74 | +make run-app |
| 75 | + |
| 76 | +# Stand up Docker Compose stack with OpenTelemetry Collector, Prometheus and Jaeger |
| 77 | +make run-stack |
| 78 | + |
| 79 | +# Run app with OpenTelemetry instrumentation (logs will be produced in the same terminal) |
| 80 | +make run-all |
| 81 | + |
| 82 | +# Run app using the cache-client-extension SpanProcessor |
| 83 | +make run-app-with-extension |
| 84 | + |
| 85 | +# Run app using the cache-client-extension SpanProcessor and telemetry stack in parallel |
| 86 | +make run-all-with-extension |
| 87 | +``` |
| 88 | + |
| 89 | +As mentioned in Chapter 4, running `dropwizard-example` will generate some `WARN` level logs, as the application comes |
| 90 | +pre-configured to push metrics to Graphite, which we won't use in this example. The following links, also cited in |
| 91 | +Chapter 4, can be used to send some requests to the application and to evaluate the telemetry produced: |
| 92 | + |
| 93 | +* http://localhost:8080/hello-world: Welcome message from `dropwizard-example`. |
| 94 | +* http://localhost:9090: Prometheus web interface, to visualise metrics (with exemplars) produced. |
| 95 | +* http://localhost:16686: Jaeger UI, to examine traces for operations being handled by our application. |
| 96 | + |
| 97 | +To interact with the database, as detailed in the example illustrated in Figure 4-2, you can send a request to the |
| 98 | +`/people` endpoint as follows: |
| 99 | + |
| 100 | +```shell |
| 101 | +curl -H "Content-Type: application/json" -X POST \ |
| 102 | + -d '{"fullName":"Other Person","jobTitle":"Other Title"}' \ |
| 103 | + http://localhost:8080/people |
| 104 | +``` |
| 105 | + |
| 106 | +Navigating to http://localhost:8080/people will show the records currently present in the database. |
| 107 | + |
| 108 | +To showcase the concepts in _Chapter 8 - Logs_, this project also provides the following commands: |
| 109 | + |
| 110 | +```shell |
| 111 | +# Run app exporting logs in OTLP to the default OpenTelemetry Collector address |
| 112 | +make run-app-with-logs |
| 113 | + |
| 114 | +# Run app exporting logs in OTLP and telemetry stack in parallel |
| 115 | +make run-all-with-logs |
| 116 | +``` |
| 117 | + |
| 118 | +In addition to configure the application to export logs via OTLP, this will use a modified `example.yml` Dropwizard |
| 119 | +config file called `chapter8.example.yml` which showcases OpenTelemetry instrumentation adding attributes to the default |
| 120 | +`console` logger, as discussed in _Chapter 8 - Logs_. Navigating to |
| 121 | +http://localhost:8080/hello-world/date?date=2023-01-15 will generate a request that showcases the use of MDC |
| 122 | +instrumentation to annotate log lines with the trace and span ID corresponding to the given request. |
| 123 | + |
10 | 124 | ## Releases
|
11 | 125 |
|
12 | 126 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
|
|
0 commit comments