Reader small image

You're reading from  Cloud-Native Observability with OpenTelemetry

Product typeBook
Published inMay 2022
PublisherPackt
ISBN-139781801077705
Edition1st Edition
Right arrow
Author (1)
Alex Boten
Alex Boten
author image
Alex Boten

Alex Boten is a senior staff software engineer that has spent the last ten years helping organizations adapt to a cloud-native landscape. From building core network infrastructure to client mobile applications and everything in between, Alex has first-hand knowledge of how difficult troubleshooting distributed applications is. This led him to the domain of observability and to contributing to related open source projects. An approver and maintainer in several OpenTelemetry projects, Alex has helped implement and evolve the project from its early days in 2019 into the massive community effort that it is today. Alex has contributed to the Python and Go OpenTelemetry implementations, as well as to the specification and the collector projects. More than anything, Alex by codeboten on Twitter loves making sense of the technology around us and sharing his learnings with others.
Read more about Alex Boten

Right arrow

Preface

Cloud-Native Observability with OpenTelemetry is a guide to helping you look for answers to questions about your applications. This book teaches you how to produce telemetry from your applications using an open standard to retain control of data. OpenTelemetry provides the tools necessary for you to gain visibility into the performance of your services. It allows you to instrument your application code through vendor-neutral APIs, libraries and tools.

By reading Cloud-Native Observability with OpenTelemetry, you'll learn about the concepts and signals of OpenTelemetry - traces, metrics, and logs. You'll practice producing telemetry for these signals by configuring and instrumenting a distributed cloud-native application using the OpenTelemetry API. The book also guides you through deploying the collector, as well as telemetry backends necessary to help you understand what to do with the data once it's emitted. You'll look at various examples of how to identify application performance issues through telemetry. By analyzing telemetry, you'll also be able to better understand how an observable application can improve the software development life cycle.

By the end of this book, you'll be well-versed with OpenTelemetry, be able to instrument services using the OpenTelemetry API to produce distributed traces, metrics and logs, and more.

Who this book is for

This book is for software engineers and systems operators looking to better understand their infrastructure, services, and applications by using telemetry data like never before. Working knowledge of Python programming is assumed for the example applications you'll build and instrument using the OpenTelemetry API and SDK. Some familiarity with Go programming, Linux, Docker, and Kubernetes is preferable to help you set up additional components in various examples throughout the book.

What this book covers

Chapter 1, The History and Concepts of Observability, provides an overview of the evolution of observability. It describes the challenges and fragmentation that ultimately created the need for an open standard. It provides an overview of both OpenTracing and OpenCensus. The last section of this chapter dives into OpenTelemetry, how it started, and how it got to where it is today. This concepts chapter will provide you with an overview of different concepts vital in understanding OpenTelemetry. This chapter introduces signals before going over the pipeline for generating, processing, and exporting telemetry. The resources section will describe the purpose of resources.

Chapter 2, OpenTelemetry Signals – Traces, Metrics, and Logs, describes the different signals that comprise OpenTelemetry: traces, metrics, and logs. It begins by giving you an understanding of the concepts of distributed tracing by defining spans, traces, and context propagation. The following section explores metrics by looking at the different measurements and the instruments OpenTelemetry offers to capture this information. The section on logging describes how logging fits in with the other signals in OpenTelemetry. Semantic conventions are also covered in this chapter to understand their significance and role in each signal.

Chapter 3, Auto-Instrumentation, explains the challenges of manual instrumentation and how the OpenTelemetry project sets out to solve those challenges. After that, you will dive into the mechanics of auto instrumentation in different languages.

Chapter 4, Distributed Tracing – Tracing Code Execution, begins by introducing the grocery store application we will instrument throughout the book. You will then start using the OpenTelemetry APIs to configure a tracing pipeline and its various components: the tracer provider, span processor, and exporter. After obtaining a tracer, you will instrument code to generate traces. The remainder of the chapter will discuss augmenting that tracing data with attributes, events, links, statuses, and exceptions.

Chapter 5, Metrics – Recording Measurements, teaches you how to capture application metrics. You will begin by configuring the components of a metrics pipeline: the meter provider, meter, and exporter. The chapter then describes the instruments available in OpenTelemetry to collect metrics before using each one in the context of the grocery store application.

Chapter 6, Logging – Capturing Events, covers logging, the last of the core signals of OpenTelemetry discussed in this book. The chapter walks you through configuring the components of the logging pipeline to emit telemetry. You will then use existing logging libraries to enhance logged events through correlation with OpenTelemetry.

Chapter 7, Instrumentation Libraries, teaches you how to use instrumentation libraries to instrument the grocery store application automatically after learning how to do so manually. Using auto instrumentation and environment variables supported by OpenTelemetry, this chapter shows you how to obtain telemetry from your code quickly.

Chapter 8, OpenTelemetry Collector, explores another core component that OpenTelemetry provides: the OpenTelemetry Collector. The Collector allows users to collect and aggregate data before transmitting it to various backends. This chapter describes the concepts present in the Collector, presents its use cases, and explains the challenges it solves. After learning about the OpenTelemetry Protocol (OTLP), you will modify the grocery store application to emit telemetry to the collector via OTLP.

Chapter 9, Deploying the Collector, puts the OpenTelemetry Collector to work in a Kubernetes environment in various deployment scenarios. You will use Kubernetes to deploy the Collector as a sidecar, agent, and gateway to collect application-level and system-level telemetry.

Chapter 10, Configuring Backends, teaches you about various open source telemetry backend options to store and visualize data. This chapter explores using OpenTelemetry with Zipkin, Jaeger, Prometheus, and Loki utilizing a local environment. You will configure exporters in application code and the OpenTelemetry Collector to emit data to these backends. After instrumenting and collecting all the telemetry from applications, it's finally time to start using this information to identify issues in a system.

Chapter 11, Diagnosing Problems, dives into techniques used to correlate data across the different OpenTelemetry signals to identify the root cause of common problems in production effectively. This chapter introduces you to chaos engineering and tools to generate synthetic loads and service interruptions to produce different scenarios.

Chapter 12, Sampling, explains the concept of sampling and how it applies to distributed tracing. Head, tail, and probability sampling strategies are introduced in this chapter. You will configure sampling using the OpenTelemetry APIs and the OpenTelemetry Collector, comparing the results of different sampling configurations.

To get the most out of this book

The examples in this book were developed on macOS x86-64 using versions of Python ranging from 3.6 to 3.9. The latest version of OpenTelemetry for Python tested is version 1.10.0, which includes experimental support for both metrics and logging. It's likely that the API will change in subsequent releases, so be aware of the version installed as you go through the examples. Consult the changelog of the OpenTelemetry Python repository (https://github.com/open-telemetry/opentelemetry-python/blob/main/CHANGELOG.md) for the latest updates.

Many examples in the book rely on Docker and Docker Compose to deploy environments locally. As of January 2022, the license for Docker Desktop still allows users to install it for free for personal use, education, and non-commercial open source projects. If the licensing prevents you from using Docker Desktop, there are alternatives available.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Cloud-Native-Observability. If there's an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781801077705_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The code then calls the global set_meter_provider method to set the meter provider for the entire application."

A block of code is set as follows:

from opentelemetry._metrics import set_meter_provider
from opentelemetry.sdk._metrics import MeterProvider
from opentelemetry.sdk.resources import Resource
def configure_meter_provider():
    provider = MeterProvider(resource=Resource.create())
    set_meter_provider(provider)
if __name__ == "__main__":
    configure_meter_provider()

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

from opentelemetry._metrics import get_meter_provider, set_meter_provider
...
if __name__ == "__main__":
    configure_meter_provider()
    meter = get_meter_provider().get_meter(
        name="metric-example",
        version="0.1.2",
        schema_url=" https://opentelemetry.io/schemas/1.9.0",
    )

Any command-line input or output is written as follows:

$ git clone https://github.com/PacktPublishing/Cloud-Native-Observability
$ cd Cloud-Native-Observability/chapter7

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: "Search for traces by clicking the Run Query button."

Tips or Important Notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you've read Cloud-Native Observability with OpenTelemetry, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Cloud-Native Observability with OpenTelemetry
Published in: May 2022Publisher: PacktISBN-13: 9781801077705
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alex Boten

Alex Boten is a senior staff software engineer that has spent the last ten years helping organizations adapt to a cloud-native landscape. From building core network infrastructure to client mobile applications and everything in between, Alex has first-hand knowledge of how difficult troubleshooting distributed applications is. This led him to the domain of observability and to contributing to related open source projects. An approver and maintainer in several OpenTelemetry projects, Alex has helped implement and evolve the project from its early days in 2019 into the massive community effort that it is today. Alex has contributed to the Python and Go OpenTelemetry implementations, as well as to the specification and the collector projects. More than anything, Alex by codeboten on Twitter loves making sense of the technology around us and sharing his learnings with others.
Read more about Alex Boten