<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anas T</title>
    <description>The latest articles on DEV Community by Anas T (@0anas0).</description>
    <link>https://dev.to/0anas0</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1083894%2Fccad642b-4b93-4aee-ba2e-b7b698dee93a.jpg</url>
      <title>DEV Community: Anas T</title>
      <link>https://dev.to/0anas0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0anas0"/>
    <language>en</language>
    <item>
      <title>A Beginner's Guide to Auto-Instrumenting a Flask App with OpenTelemetry and SigNoz</title>
      <dc:creator>Anas T</dc:creator>
      <pubDate>Tue, 08 Apr 2025 14:07:48 +0000</pubDate>
      <link>https://dev.to/0anas0/a-beginners-guide-to-auto-instrumenting-a-flask-app-with-opentelemetry-and-signoz-896</link>
      <guid>https://dev.to/0anas0/a-beginners-guide-to-auto-instrumenting-a-flask-app-with-opentelemetry-and-signoz-896</guid>
      <description>&lt;p&gt;Understanding what your code is doing — &lt;em&gt;really&lt;/em&gt; doing — is essential. That’s where observability comes in.&lt;/p&gt;

&lt;p&gt;In this hands-on tutorial, you’ll learn how to instrument a simple Python Flask app using OpenTelemetry and send that data to SigNoz, an open-source observability platform. Step by step, we’ll walk through everything you need to get visibility into your application.&lt;/p&gt;

&lt;p&gt;By the end, you’ll know how to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enable auto-instrumentation&lt;/li&gt;
&lt;li&gt;Add custom spans&lt;/li&gt;
&lt;li&gt;Track custom metrics&lt;/li&gt;
&lt;li&gt;Capture logs&lt;/li&gt;
&lt;li&gt;Correlate logs with traces&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Is OpenTelemetry and Why Use It?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://signoz.io/guides/what-is-opentelemetry/" rel="noopener noreferrer"&gt;OpenTelemetry&lt;/a&gt; is an open-source framework that helps you collect data about your application's performance and behavior. It gathers three types of telemetry data: traces, metrics, and logs. The data together provide a complete picture of how your app is working.&lt;/p&gt;

&lt;p&gt;For beginners, OpenTelemetry is valuable because it simplifies monitoring without requiring deep expertise, and it works with many tools, like SigNoz, to display the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Telemetry Data: Traces, Metrics, and Logs
&lt;/h3&gt;

&lt;p&gt;Telemetry data is the information your app produces to show what it's doing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Traces&lt;/strong&gt; track the journey of a request through your app&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metrics&lt;/strong&gt; measure things like how many requests happen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logs&lt;/strong&gt; record specific events or messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they help you spot problems, measure performance, and debug issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is SigNoz and How Does It Fit In?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://signoz.io/blog/opentelemetry-apm/" rel="noopener noreferrer"&gt;SigNoz&lt;/a&gt; is an open-source tool that takes the telemetry data from OpenTelemetry and turns it into easy-to-read charts and dashboards. It's designed to work seamlessly with OpenTelemetry, making it perfect for anyone who wants to see their app's data without complex setup. SigNoz will be our window into the Flask app's performance in this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Environment
&lt;/h2&gt;

&lt;p&gt;Before we start instrumenting our Flask app, we need to prepare our system with the right tools. This section walks you through:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Installing Python&lt;/li&gt;
&lt;li&gt;Creating a virtual environment to manage packages safely&lt;/li&gt;
&lt;li&gt;Setting up SigNoz locally&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Following the steps, you'll have a clean workspace ready for OpenTelemetry.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Python and Creating a Virtual Environment
&lt;/h3&gt;

&lt;p&gt;We'll use Python and Flask, a simple web framework, for our app. First, ensure that Python 3.8 or newer is installed by running &lt;code&gt;python3 --version&lt;/code&gt; on your terminal.&lt;/p&gt;

&lt;p&gt;If Python is not installed, download it from &lt;a href="http://python.org/" rel="noopener noreferrer"&gt;python.org&lt;/a&gt; or use your system's package manager (e.g., &lt;code&gt;sudo apt install python3&lt;/code&gt; on Ubuntu).&lt;/p&gt;

&lt;p&gt;Verify that pip is available with the &lt;code&gt;pip3 --version&lt;/code&gt;; if not, install it with &lt;code&gt;sudo apt install python3-pip&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We'll create a virtual environment to avoid conflicts with your system's Python. This self-contained Python setup lets you install packages without affecting the rest of your system.&lt;/p&gt;

&lt;p&gt;Run these commands in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv otel-venv
&lt;span class="nb"&gt;source &lt;/span&gt;otel-venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running &lt;code&gt;source otel-venv/bin/activate&lt;/code&gt;, your terminal prompt should change (e.g., &lt;code&gt;(otel-venv)&lt;/code&gt;), indicating you're in the virtual environment. Now, any packages you install with pip will stay isolated here.&lt;/p&gt;

&lt;p&gt;If you ever need to exit the virtual environment, type &lt;code&gt;deactivate&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up SigNoz Locally
&lt;/h3&gt;

&lt;p&gt;SigNoz will collect and display our telemetry data, and we'll run it using Docker. Open a terminal and run these commands to set up SigNoz:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="nt"&gt;-b&lt;/span&gt; main https://github.com/SigNoz/signoz.git
&lt;span class="nb"&gt;cd &lt;/span&gt;signoz/deploy/
./install.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This downloads SigNoz and starts it. Once finished, SigNoz will be accessible at &lt;code&gt;http://localhost:8080&lt;/code&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frftw9gxpnbq8pytz161f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frftw9gxpnbq8pytz161f.png" alt="Image description" width="800" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You've now set up the backend to receive data from our app.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating a Simple Flask Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's build a basic Flask app to instrument. Create a file called &lt;code&gt;app.py&lt;/code&gt; and add this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to the Flask App!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Task completed!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This app has two endpoints: one to greet users (&lt;code&gt;http://localhost:5000&lt;/code&gt;) and another to simulate a task (&lt;code&gt;http://localhost:5000/task&lt;/code&gt;). This gives us something simple yet practical to monitor.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Auto-Instrumenting the Flask App with OpenTelemetry&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Auto-instrumentation lets OpenTelemetry automatically track your app's activity without changing much code. It's a beginner-friendly way to monitor and capture data like request times and errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installing OpenTelemetry Packages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With your virtual environment active (run &lt;code&gt;source otel-venv/bin/activate&lt;/code&gt; if it's not), install the necessary OpenTelemetry packages.&lt;/p&gt;

&lt;p&gt;In your terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;opentelemetry-distro &lt;span class="se"&gt;\&lt;/span&gt;
opentelemetry-exporter-otlp &lt;span class="se"&gt;\&lt;/span&gt;
flask &lt;span class="se"&gt;\&lt;/span&gt;
opentelemetry-instrumentation-flask &lt;span class="se"&gt;\&lt;/span&gt;
opentelemetry-instrumentation-logging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; opentelemetry-bootstrap &lt;span class="nt"&gt;--action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-distro&lt;/code&gt;: Provides auto-instrumentation for Python apps.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-exporter-otlp&lt;/code&gt;: Sends data to SigNoz using the OTLP protocol.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flask&lt;/code&gt;: Ensures Flask is installed for our app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-instrumentation-flask&lt;/code&gt;: Instruments Flask applications to automatically capture traces.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-instrumentation-logging&lt;/code&gt;: Hooks into Python's built-in logging module to enrich log messages with trace and span context.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-bootstrap --action=install&lt;/code&gt;: Automatically installs required dependencies for OpenTelemetry instrumentation based on detected libraries in your environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Configuring Auto-Instrumentation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We'll use a command that wraps our app with OpenTelemetry to enable auto-instrumentation. Update your terminal command to run the app like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;opentelemetry-instrument &lt;span class="nt"&gt;--traces_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--metrics_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--logs_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--service_name&lt;/span&gt; flask-app python3 app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command tells OpenTelemetry to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collect traces, metrics, and logs&lt;/li&gt;
&lt;li&gt;Send them to SigNoz (running locally at &lt;code&gt;localhost:4317&lt;/code&gt; by default).&lt;/li&gt;
&lt;li&gt;Name our service &lt;code&gt;flask-app&lt;/code&gt; for easy identification in SigNoz.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You've now auto-instrumented the app, and it's ready to send basic telemetry data to SigNoz.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Viewing Auto-Instrumented Traces&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hit &lt;code&gt;http://localhost:5000&lt;/code&gt; and &lt;code&gt;http://localhost:5000/task&lt;/code&gt; a few times to generate data. In SigNoz, go to the “Traces” tab. You'll see traces for requests to &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;/task&lt;/code&gt;, showing timing and endpoints automatically captured by OpenTelemetry:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg664gm953nh60ozna2lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg664gm953nh60ozna2lq.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This shows how requests flow through your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Adding Custom Spans for Detailed Tracing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Auto-instrumentation is great, but custom spans let you track specific parts of your code, like a slow task. A span is a single unit of work in a trace, giving you detailed timing info.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Modifying the App to Include Custom Spans&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Update &lt;code&gt;app.py&lt;/code&gt; to add a custom span for the &lt;code&gt;/task&lt;/code&gt; endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tracer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_tracer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to the Flask App!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;tracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_as_current_span&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;process-task&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Task completed!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;tracer.start_as_current_span("process-task")&lt;/code&gt; creates a custom span around the task logic. Rerun the app with the same &lt;code&gt;opentelemetry-instrument&lt;/code&gt; command we used above and generate data.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Analysing Custom Spans&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the same “Traces” tab, click a &lt;code&gt;/task&lt;/code&gt; trace to see the “process-task” span with its duration:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flko1dggysivwekvwsvsk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flko1dggysivwekvwsvsk.png" alt="Image description" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Sending Custom Metrics to Track Performance&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Metrics measure things over time, like how many requests your app handles. Custom metrics let you track what matters to you, beyond what auto-instrumentation provides.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Implementing Custom Metrics in the App&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Add a custom metric to count requests to the &lt;code&gt;/task&lt;/code&gt; endpoint. Update &lt;code&gt;app.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tracer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_tracer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;meter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_meter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;task_counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;meter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;task_requests&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Number of task requests&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to the Flask App!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;tracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_as_current_span&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;process-task&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;task_counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Task completed!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;task_counter&lt;/code&gt; metric increments each time &lt;code&gt;/task&lt;/code&gt; is called.&lt;/p&gt;

&lt;p&gt;Rerun the app using the same auto instrument code we used above and generate new data.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Viewing custom metrics on Signoz&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;On Signoz, follow these steps to create a dashboard with the custom metric:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click “Dashboards” in the navigation&lt;/li&gt;
&lt;li&gt;Create a new dashboard

&lt;ol&gt;
&lt;li&gt;Click “+ New Panel.”&lt;/li&gt;
&lt;li&gt;Choose “Time Series” as the Panel Type.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;In the Query Builder,

&lt;ol&gt;
&lt;li&gt;select &lt;code&gt;task_requests&lt;/code&gt; from the Metrics dropdown.&lt;/li&gt;
&lt;li&gt;Set Aggregation to “Increase” (for counters).&lt;/li&gt;
&lt;li&gt;Save the panel and dashboard (e.g., name it “Flask Metrics”).&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9cq0yaw2j7u9u7vz19q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9cq0yaw2j7u9u7vz19q.png" alt="Image description" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Capturing Logs and Correlating with Traces&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Logs are messages your app produces, like status updates or errors. Correlating them with traces links these messages to specific requests, making it easier to debug issues by seeing the full context of a request's journey.&lt;/p&gt;

&lt;p&gt;In this section, we'll add logging to our Flask app, enable trace-log correlation using OpenTelemetry, and view the results in SigNoz.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adding Logging to the Flask App&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We'll update &lt;code&gt;app.py&lt;/code&gt; to include logging with trace context, using OpenTelemetry to capture and correlate logs with traces. We'll also use auto-instrumentation for Flask traces and metrics.&lt;/p&gt;

&lt;p&gt;Update &lt;code&gt;app.py&lt;/code&gt; with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry.instrumentation.flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FlaskInstrumentor&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry.instrumentation.logging&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LoggingInstrumentor&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="c1"&gt;# Configure logging with OpenTelemetry
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OpenTelemetryLogFormatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Formatter&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Add trace and span context to log record
&lt;/span&gt;        &lt;span class="n"&gt;current_span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_current_span&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current_span&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;span_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_span_context&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;span_context&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;span_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_valid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;span_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;032&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;span_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;016&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;00000000000000000000000000000000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0000000000000000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;00000000000000000000000000000000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0000000000000000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create formatter
&lt;/span&gt;&lt;span class="n"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenTelemetryLogFormatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%(asctime)s - %(name)s - %(levelname)s - trace_id=%(trace_id)s span_id=%(span_id)s - %(message)s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set up root logger
&lt;/span&gt;&lt;span class="n"&gt;root_logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;root_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StreamHandler&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setFormatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;formatter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;root_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create Flask app
&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Disable Werkzeug's default logger
&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;handlers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="n"&gt;werkzeug_logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;werkzeug&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;werkzeug_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;disabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# Create a custom logger for HTTP access
&lt;/span&gt;&lt;span class="n"&gt;http_logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http.access&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;http_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;http_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Custom logging middleware
&lt;/span&gt;&lt;span class="nd"&gt;@app.before_request&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;before_request&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Store request start time
&lt;/span&gt;    &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nd"&gt;@app.after_request&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;after_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Calculate request duration
&lt;/span&gt;    &lt;span class="n"&gt;duration_ms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;

    &lt;span class="c1"&gt;# Log the request with the current trace context
&lt;/span&gt;    &lt;span class="n"&gt;http_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%s - - [%s] &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s %s %s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; %s %s (%.2fms)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remote_addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%d/%b/%Y %H:%M:%S&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SERVER_PROTOCOL&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content_length&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;duration_ms&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;

&lt;span class="c1"&gt;# Instrument Flask for traces and logs
&lt;/span&gt;&lt;span class="nc"&gt;FlaskInstrumentor&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;instrument_app&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;LoggingInstrumentor&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;instrument&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Custom metric
&lt;/span&gt;&lt;span class="n"&gt;meter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_meter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;task_counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;meter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;task_requests&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Number of task requests&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Tracer for custom spans
&lt;/span&gt;&lt;span class="n"&gt;tracer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_tracer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Home endpoint accessed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome to the Flask App!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;tracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_as_current_span&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;task_processing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;task_counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Task endpoint accessed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Task completed!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Custom Log Formatter&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;OpenTelemetryLogFormatter&lt;/code&gt; extracts trace and span IDs from the current span context&lt;/li&gt;
&lt;li&gt;Correctly handles the span context properties to avoid errors&lt;/li&gt;
&lt;li&gt;Formats IDs as hexadecimal strings with proper padding&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;HTTP Request Logging&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Disables Werkzeug's default logger, which doesn't capture trace context&lt;/li&gt;
&lt;li&gt;Implements custom request hooks with &lt;code&gt;before_request&lt;/code&gt; and &lt;code&gt;after_request&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Logs HTTP requests within the trace context to ensure correlation&lt;/li&gt;
&lt;li&gt;Includes request duration similar to standard web server logs&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Auto-Instrumentation&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;FlaskInstrumentor().instrument_app(app)&lt;/code&gt; automatically generates traces for Flask HTTP requests&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;LoggingInstrumentor().instrument()&lt;/code&gt; enables log collection with trace context&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Enabling Log-Trace Correlation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To correlate logs with traces, we'll use OpenTelemetry's auto-instrumentation to capture traces, metrics, and logs and send them to SigNoz.&lt;/p&gt;

&lt;p&gt;Run the app with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;opentelemetry-instrument &lt;span class="nt"&gt;--traces_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--metrics_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--logs_exporter&lt;/span&gt; otlp &lt;span class="nt"&gt;--service_name&lt;/span&gt; flask-app python3 app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true&lt;/code&gt; enables OpenTelemetry to capture logs and include trace context.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opentelemetry-instrument&lt;/code&gt; runs the app with auto-instrumentation, exporting traces, metrics, and logs to SigNoz.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup links log messages to their corresponding traces using trace IDs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Analyzing correlated logs with traces
&lt;/h3&gt;

&lt;p&gt;Follow the given steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit &lt;code&gt;http://localhost:5000/&lt;/code&gt; and &lt;code&gt;http://localhost:5000/task&lt;/code&gt; to generate some requests&lt;/li&gt;
&lt;li&gt;Go to the “Logs” tab on Signoz&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;otelTraceID&lt;/code&gt; and &lt;code&gt;otelSpanID&lt;/code&gt; in the column settings&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qwt2pxrj87x1kp9ycva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qwt2pxrj87x1kp9ycva.png" alt="Image description" width="657" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can see correlated logs with traces:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqj4bo5n1p7f0b9goir07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqj4bo5n1p7f0b9goir07.png" alt="Image description" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also click on a log entry to see its details. You'll see a &lt;code&gt;trace_id&lt;/code&gt; field, which you can click to jump to the matching trace in the “Traces” tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fziqt2guio00oqlna5f68.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fziqt2guio00oqlna5f68.png" alt="Image description" width="800" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, go to the “Traces” tab, select a trace, and click “Go to related logs” to see the logs associated with that trace:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frexc6w96yuj7f2bwlhlu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frexc6w96yuj7f2bwlhlu.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The correlation links each log to its request's journey, helping you debug issues by seeing both the log messages and the trace details together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep digging
&lt;/h2&gt;

&lt;p&gt;Observability opens a window into your application's inner workings. It’s how you learn from your systems. And the more you see, the better you build. This is just the start. Keep digging.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>beginners</category>
      <category>monitoring</category>
      <category>opentelemetry</category>
    </item>
    <item>
      <title>What is Envoy Proxy?</title>
      <dc:creator>Anas T</dc:creator>
      <pubDate>Tue, 16 May 2023 18:11:30 +0000</pubDate>
      <link>https://dev.to/0anas0/what-is-envoy-proxy-3ok3</link>
      <guid>https://dev.to/0anas0/what-is-envoy-proxy-3ok3</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Why is Envoy Proxy required?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Challenges are plenty for organizations moving their applications from monolithic to microservices architecture. Managing and monitoring the sheer number of distributed services across Kubernetes and public cloud often exhausts app developers, cloud teams, and SREs. Below are some of the major network-level operational hassles of microservices, which shows why Envoy proxy is required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lack of secure network connection
&lt;/h3&gt;

&lt;p&gt;Kubernetes is not inherently secure because services are allowed to talk to each other freely. It poses a great threat to the infrastructure since an attacker who gains access to a pod can move laterally across the network and compromise other services. This can be a huge problem for security teams, as it is harder to ensure the safety and integrity of sensitive data. Also, the traditional perimeter-based firewall approach and intrusion detection systems will not help in such cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Complying with security policies is a huge challenge
&lt;/h3&gt;

&lt;p&gt;There is no developer on earth who would enjoy writing security logic to ensure authentication and authorization, instead of brainstorming business problems. However, organizations who want to adhere to policies such as HIPAA or GDPR, ask their developers to write security logic such as mTLS encryption in their applications. Such cases in enterprises will lead to two consequences: frustrated developers, and security policies being implemented locally and in siloes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lack of visibility due to complex network topology
&lt;/h3&gt;

&lt;p&gt;Typically, microservices are distributed across multiple Kubernetes clusters and cloud providers. Communication between these services within and across cluster boundaries will contribute to a complex network topology in no time. As a result, it becomes hard for Ops teams and SREs to have visibility over the network, which impedes their ability to identify and resolve network issues in a timely manner. This will lead to frequent application downtime and compromised SLA.&lt;/p&gt;

&lt;h3&gt;
  
  
  Complicated service discovery
&lt;/h3&gt;

&lt;p&gt;Services are often created and destroyed in a dynamic microservices environment. Static configurations provided by old-generation proxies are ineffective to keep track of services in such an environment. This makes it difficult for application engineers to configure communication logic between services. Because they have to manually update the configuration file whenever a new service is deployed or deleted. It leads to application developers spending more of their time configuring the networking logic rather than coding the business logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inefficient load balancing and traffic routing
&lt;/h3&gt;

&lt;p&gt;It is crucial for platform architects and cloud engineers to ensure effective traffic routing and load balancing between services. However, it is a time-consuming and error-prone process for them to manually configure routing rules and load balancing policies for each service, especially when they have a fleet of them. Also, traditional load balancers with simple algorithms would result in inefficient resource utilization and suboptimal load balancing in the case of microservices. All these lead to increased latency, and service unavailability due to improper traffic routing.&lt;/p&gt;

&lt;p&gt;With the rise in the adoption of microservices architecture, there was a need for a fast, intelligent proxy that can handle the complex service-to-service connection across the cloud. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introducing Envoy proxy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.envoyproxy.io/"&gt;Envoy&lt;/a&gt; is an open-source edge and service proxy, originally developed by &lt;a href="https://www.lyft.com/"&gt;Lyft&lt;/a&gt; to facilitate their migration from a monolith to cloud-native microservices architecture. It also serves as a communication bus for microservices (refer to fig. A below) across the cloud, enabling them to communicate with each other in a rapid, secure, and efficient manner.&lt;/p&gt;

&lt;p&gt;Envoy proxy abstracts network and security from the application layer to an infrastructure layer. This helps application developers simplify developing cloud-native applications by saving hours spent on configuring network and security logic.&lt;/p&gt;

&lt;p&gt;Envoy proxy provides advanced load balancing and traffic routing capabilities that are critical to run large, complex distributed applications. Also, the modular architecture of Envoy helps cloud and platform engineers to customize and extend its capabilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aUE2pZ7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnip3g67re9yy1cys4s5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aUE2pZ7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnip3g67re9yy1cys4s5.png" alt="Envoy proxy intercepting traffic between services" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Envoy proxy architecture with Istio&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Envoy proxies are deployed as sidecar containers alongside application containers. The sidecar proxy then intercepts and takes care of the service-to-service connection (refer to fig B below) and provides a variety of features. This network of proxies is called a data plane, and it is configured and monitored from a control plane provided by Istio. These two components together form the &lt;a href="https://imesh.ai/blog/what-is-istio/"&gt;Istio service mesh&lt;/a&gt; architecture, which provides a powerful and flexible infrastructure layer for managing and securing microservices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yqRPPw_1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y63rxoammuphouglcnv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yqRPPw_1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y63rxoammuphouglcnv9.png" alt="Istio sidecar architecture with Envoy proxy data plane" width="700" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Envoy proxy features&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Envoy proxy offers the following features at a high level. (Visit &lt;a href="https://www.envoyproxy.io/docs/envoy/v1.25.4/intro/what_is_envoy"&gt;Envoy docs&lt;/a&gt; for more information on the features listed below.)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Out-of-process architecture&lt;/strong&gt;: It means that the Envoy proxy runs independently as a separate process, apart from the application process. It can be deployed as a sidecar proxy and also as a gateway without requiring any changes to the application. Envoy is also compatible with any application language like Java or C++, which provides greater flexibility for application developers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;L3/L4 and L7 filter architecture&lt;/strong&gt;: Envoy supports filters and allows customizing traffic at the network layer (L3/L4) and at the application layer ( L7). This allows for more control over the network traffic and offers granular traffic management capabilities such as TLS client certificate authentication, buffering, rate limiting, and routing/forwarding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP/2 and HTTP/3 support&lt;/strong&gt;: Envoy supports HTTP/1.1, HTTP/2, and HTTP/3 (currently in alpha) protocols. This enables seamless communication between clients and target servers using different versions of HTTP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP L7 routing&lt;/strong&gt;: Envoy’s HTTP L7 routing subsystem can route and redirect requests based on various criteria, such as path, authority, and content type. This feature is useful for building front/edge proxies and service-to-service meshes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;gRPC support&lt;/strong&gt;: Envoy supports gRPC, a Google RPC framework that uses HTTP/2 or above as its underlying transport. Envoy can act as a routing and load balancing substrate for gRPC requests and responses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Service discovery and dynamic configuration&lt;/strong&gt;: Envoy supports service discovery and dynamic configuration through a layered set of APIs that provide dynamic updates about backend hosts, clusters, routing, listening sockets, and cryptographic material. This allows for centralized management and simpler deployment, with options for DNS resolution or static config files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Health checking&lt;/strong&gt;: For building an Envoy mesh, service discovery is treated as an eventually consistent process. Envoy has a health checking subsystem that can perform active and passive health checks to determine healthy load balancing targets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Advanced load balancing&lt;/strong&gt;: Envoy’s self-contained proxy architecture allows it to implement advanced load balancing techniques, such as automatic retries, circuit breaking, request shadowing, and outlier detection, in one place, accessible to any application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Front/edge proxy support&lt;/strong&gt;: Using the same software at the edge provides benefits such as observability, management, and identical service discovery and load balancing algorithms. Envoy’s feature set makes it well-suited as an edge proxy for most modern web application use cases, including TLS termination, support for multiple HTTP versions, and HTTP L7 routing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best-in-class observability&lt;/strong&gt;: Envoy provides robust statistics support for all subsystems and supports distributed tracing via third-party providers, making it easier for SREs and Ops teams to monitor and debug problems occurring at both the network and application levels.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Given its powerful set of features, Envoy proxy has become a popular choice for organizations to manage and secure microservices. In practice, it has two main use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Use cases of Envoy proxy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Envoy proxy can be used as both a sidecar service proxy and a gateway.&lt;/p&gt;

&lt;h3&gt;
  
  
  Envoy sidecar proxy
&lt;/h3&gt;

&lt;p&gt;As we have seen in the Isito architecture, Envoy proxy constitutes the data plane and manages the traffic flow between services deployed in the mesh. The sidecar proxy provides features such as service discovery, load balancing, traffic routing, etc., and offers visibility and security to the network of microservices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Envoy Gateway as API
&lt;/h3&gt;

&lt;p&gt;Envoy proxy can be deployed as an API gateway and as an ingress (read the Envoy Gateway project). Envoy Gateway is deployed at the edge of the cluster to manage external traffic flowing into the cluster and between multicloud applications (north-south traffic). Envoy Gateway helped application developers who were toiling to configure Envoy proxy (Istio-native) as API and ingress controller, instead of purchasing a third-party solution like NGINX. With its implementation, they have a central location to configure and manage ingress and egress traffic, and apply security policies such as authentication and access control.&lt;/p&gt;

&lt;p&gt;Below is a diagram of Envoy Gateway architecture and its components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YKMDUrwA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3e44tm0c4rrpv0mftii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YKMDUrwA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3e44tm0c4rrpv0mftii.png" alt="Envoy gateway architecture" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To read more about Envoy API gateway architecture, features, and learn how to get started with it, follow this link: &lt;a href="https://imesh.ai/blog/what-is-envoy-gateway/"&gt;What is Envoy Gateway, and why is it required for Kubernetes?&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Benefits of Envoy proxy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Envoy’s ability to abstract network and security layers offers several benefits for IT teams such as developers, SREs, cloud engineers, and platform teams. Following are a few of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Effective network abstraction
&lt;/h3&gt;

&lt;p&gt;The out-of-process architecture of Envoy helps it to abstract the network layer from the application to its own infrastructure layer. This allows for faster deployment for application developers, while also providing a central plane to manage communication between services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fine-grained traffic management
&lt;/h3&gt;

&lt;p&gt;With its support for the network (L3/L4) and application (L7) layers, Envoy provides flexible and granular traffic routing, such as traffic splitting, retry policies, and load balancing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ensure zero trust security at L4/L7 layers
&lt;/h3&gt;

&lt;p&gt;Envoy proxy helps to implement authentication among services inside a cluster with stronger identity verification mechanisms like mTLS and JWT. You can achieve authorization at the L7 layer with Envoy proxy easily and ensure zero trust. (You can implement AuthN/Z policies with Istio service mesh — the control plane for Envoy.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Control east-west and north-south traffic for multicloud apps
&lt;/h3&gt;

&lt;p&gt;Since enterprises deploy their applications into multiple clouds, it is important to understand and control the traffic or communication in and out of the data centers. Since Envoy proxy can be used as a sidecar and also an API gateway, it can help manage east-west traffic and also north-south traffic, respectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monitor traffic and ensure optimum platform performance
&lt;/h3&gt;

&lt;p&gt;Envoy aims to make the network understandable by emitting statistics, which are divided into three categories: downstream statistics for incoming requests, upstream statistics for outgoing requests, and server statistics for describing the Envoy server instance. Envoy also provides logs and metrics that provide insights into traffic flow between services, which is also helpful for SREs and Ops teams to quickly detect and resolve any performance issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Get started with Envoy Proxy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Below are some resources to help you get started with Envoy Proxy.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to set up Envoy Proxy in Linux
&lt;/h3&gt;

&lt;p&gt;The following video will give you a high-level overview of Envoy architecture and components such as listeners, network chain filters, routers, and clusters. It will be followed by a demo of installing Envoy on Ubuntu. You will also see a sample flask application and how Envoy configuration is written to define all the components.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/RgNk45dxJUs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploying Envoy in K8s and Configuring as Load Balancer
&lt;/h3&gt;

&lt;p&gt;This video discusses different deployment types and their use cases, and it shows a demo of Envoy deployment into Kubernetes and how to set it as a load balancer (edge proxy).&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qqG64yt4H5c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;About IMESH&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;IMESH &lt;a href="https://www.imesh.ai/pricing.html."&gt;offers solutions&lt;/a&gt; to help organizations adopt Istio service mesh without any implementation or operational hassle. IMESH provides a platform built on top of Istio and Envoy API gateway to help start with Istio from Day 1. The platform is hardened for production and is fit for multicloud and hybrid cloud applications.&lt;/p&gt;

&lt;p&gt;IMESH also provides consulting services and expertise to help you adopt Istio rapidly in your organization. We make it easier to deploy Istio into production and ensure there are no unintended container crashes or application misbehavior. IMESH also offers a strong visibility layer on top of Istio, which provides Ops and SREs with a multicluster view of services, dependencies, and network traffic. If you are interested, please &lt;a href="https://imesh.ai/contact-us.html"&gt;talk to an Istio expert&lt;/a&gt; or &lt;a href="https://imesh.ai/request-an-istio-service-mesh-demo.html"&gt;book an Istio demo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>istio</category>
      <category>envoy</category>
      <category>opensource</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>5 Reasons Why You Should Choose Enterprise Istio Over DIY</title>
      <dc:creator>Anas T</dc:creator>
      <pubDate>Mon, 15 May 2023 09:07:44 +0000</pubDate>
      <link>https://dev.to/0anas0/5-reasons-why-you-should-choose-enterprise-istio-over-diy-5chc</link>
      <guid>https://dev.to/0anas0/5-reasons-why-you-should-choose-enterprise-istio-over-diy-5chc</guid>
      <description>&lt;p&gt;&lt;a href="https://imesh.ai/blog/what-is-istio/"&gt;Istio service mesh&lt;/a&gt; is an open-source platform that simplifies the security and network of cloud-native applications. It abstracts the network and security layer from the application into the infrastructure layer. This is helpful in securing and managing communication between microservices, improving developer experience, and achieving &lt;a href="https://imesh.ai/blog/top-10-pillars-of-zero-trust-network/"&gt;zero trust networks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are two operating models for Istio: DIY and managed Istio with enterprise support.&lt;/strong&gt; The DIY approach, where organizations deploy and manage Istio on their own, is prone to some challenges, such as lack of technical expertise, resource availability, etc. In this blog, we will explore these challenges of self-managing Istio in detail and see how &lt;a href="https://imesh.ai/enterprise-istio-support.html"&gt;enterprise Istio support&lt;/a&gt; can bring immense value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges of self-managing Istio
&lt;/h2&gt;

&lt;p&gt;Self-managing any open-source software comes with a set of challenges. A complex piece of software like Istio is no exception to this. Below are the 5 dimensions of challenges enterprises will face while implementing Istio in the DIY operating model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cxx0J3pN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/5-dimensions-of-challenges-with-Istio-DIY-model.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cxx0J3pN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/5-dimensions-of-challenges-with-Istio-DIY-model.jpg" alt="5 dimensions of challenges with Istio DIY model" width="800" height="518"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;5 dimensions of challenges with Istio DIY model&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Ownership problems
&lt;/h3&gt;

&lt;p&gt;Most open-source products are not plug-and-play solutions. Implementing them requires someone or a team to take full ownership of their implementation and maintenance. Otherwise, it may lead to suboptimal performance, unpatched security vulnerabilities, and downtime. So the following questions have to be addressed before considering Istio or any other open-source solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who will analyze if the product is hardened and ensure it does not compromise enterprise security?&lt;/li&gt;
&lt;li&gt;Who will perform the required experimentation or chaos engineering?&lt;/li&gt;
&lt;li&gt;Who will troubleshoot when the software breaks?&lt;/li&gt;
&lt;li&gt;Who will be in charge of fixing vulnerabilities and bugs?&lt;/li&gt;
&lt;li&gt;Who will take care of the product’s lifecycle management?&lt;/li&gt;
&lt;li&gt;Who will collaborate with multiple departments for its enterprise-level implementation?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ideally, Istio owners also need to closely follow Istio’s development to keep the product up-to-date with the latest releases and security patches. But the problem is that it takes time for the community to patch specific bugs and fix security vulnerabilities. Waiting for the fix to be released and letting the infrastructure be vulnerable meanwhile is not a brilliant solution. So Istio owners will have to investigate and resolve the issue themselves, which requires an in-depth understanding of Istio’s architecture and underlying infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assuming developers or platform teams have learned Istio in full capacity to implement and maintain it, they are required to do a lot of troubleshooting. This brings the question: What should the developers ultimately do? Maintain an open-source solution like Istio, or code business logic.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Learning curve
&lt;/h3&gt;

&lt;p&gt;Enterprises that are confident in their IT teams’ competency usually venture into the idea of handling Istio by themselves. However, operating Istio in the DIY model may backfire, given its complexity. Istio is a heavy-weight platform that abstracts the network and security infrastructure. Understanding it completely — including its shortcomings and making enhancements to it — &lt;strong&gt;requires crossing a huge learning curve&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On top of learning Istio itself, there is the data plane, which is implemented using &lt;a href="https://imesh.ai/blog/what-is-envoy-proxy/"&gt;Envoy proxies&lt;/a&gt;. Envoy proxies are powerful and configurable proxies that have their own set of features, configurations, and capabilities that need to be understood separately. Above all, in general, developers also have to understand the following concepts to learn Istio properly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes API controller&lt;/li&gt;
&lt;li&gt;CNI (Container Network Interface)&lt;/li&gt;
&lt;li&gt;Ingress and egress&lt;/li&gt;
&lt;li&gt;Multicluster configurations&lt;/li&gt;
&lt;li&gt;API gateway integrations&lt;/li&gt;
&lt;li&gt;And the list goes on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that I am not saying this to overwhelm and restrain anyone from learning Istio, but to shed some light on the reality of the learning curve in the DIY model of service mesh. And it is true whether you are using &lt;a href="https://imesh.ai/blog/istio-vs-linkerd-the-best-service-mesh-for-2023/"&gt;Istio or Linkerd&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Documentation problems
&lt;/h3&gt;

&lt;p&gt;We can consider documentation pages the “soul” of any open-source project. It helps users to understand the product and use it effectively. Some solutions, such as Kubernetes, are popular for maintaining a comprehensive documentation page. In a sense, the documentation makes or breaks an open-source product. If the steps outlined on the page are constantly throwing errors, the users will eventually hesitate to dig deeper and stop using the product.&lt;/p&gt;

&lt;p&gt;Istio has a well-maintained documentation page with clear instructions and step-by-step tutorials. However, there are a few problems here and there. For example, those who had followed &lt;a href="https://istio.io/latest/docs/setup/install/multicluster/primary-remote_multi-network/"&gt;Istio multi-cluster with multi-network setup&lt;/a&gt; a few weeks back must have gotten errors while implementing and configuring Istio, until &lt;a href="https://www.linkedin.com/in/ravi-verma-89325334/"&gt;Ravi Verma&lt;/a&gt;, CTO of IMESH, fixed it recently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PhhF-KIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/image-6-1024x265.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PhhF-KIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/image-6-1024x265.png" alt="Istio multi-cluster with multi-network setup fix by IMESH" width="800" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The challenge here is that there is a &lt;strong&gt;lack of volunteers&lt;/strong&gt; to update and maintain the documentation page on time. The speed at which Istio evolves is also another reason adding to this. And the rapid evolution has made some documentation or examples outdated, maybe because of functionality changes or interface changes. They will no longer be accurate or applicable to the current version of Istio you are using.  &lt;/p&gt;

&lt;p&gt;In such a case, when the documentation is not working as expected, the developers will have to reach out to Istio maintainers through the Slack channel to sort it out. This can be a time-consuming process and result in delayed troubleshooting.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Customization challenges
&lt;/h3&gt;

&lt;p&gt;Open-source solutions are tested in a specific environment. They are suitable only for environments similar to the ones in which it is tested (not unique to open-source). In real-life scenarios, enterprises run different environments and the requirements vary from one to another. They will need a lot of customization to make the product seamlessly integrate with their existing tech stack.  &lt;/p&gt;

&lt;p&gt;Also, &lt;strong&gt;with Istio, there are no one-size-fits-for-all use cases&lt;/strong&gt;. Organizations will have different requirements, and it takes some amount of resources to make Istio fit their needs. Below are some what-if scenarios where heavy customization is required: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The latest version of Istio (v1.17) supports K8s versions 1.23, 1.24, 1.25, and 1.26. What if you have an older version of K8s?&lt;/li&gt;
&lt;li&gt;What if you need to implement Istio in hybrid environments — Fargate/Lambda/GKE/on-prem VMs?&lt;/li&gt;
&lt;li&gt;What if you have to integrate Istio with AWS CA or DigiCert Enterprise PKI Manager or any other certificate manager to implement certification rotation for &lt;a href="https://imesh.ai/blog/what-is-mtls-and-how-to-implement-it-with-istio/"&gt;mTLS&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;What if you are already using an API gateway, such as Kong, Mulesoft, or Apigee? How to make the Istio integrate with an already invested infrastructure?&lt;/li&gt;
&lt;li&gt;What if you are using AuthN/AuthZ providers like Microsoft AD with x versions for which Istio does not provide out-of-the-box support?&lt;/li&gt;
&lt;li&gt;What if you are using Spinnaker or Argo CD or Tekton CD for deployment and want to configure Istio and Envoy as resources for deployment into multiple clusters?&lt;/li&gt;
&lt;li&gt;What if you want a complicated architecture like Istio-on-Istio deployment?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are only a few of the custom requirements/integrations enterprises require while configuring Istio. Sometimes they can be much more complicated.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Version upgrades
&lt;/h3&gt;

&lt;p&gt;Challenges are plenty in upgrading versions of open-source solutions that are implemented enterprise-wide. Upgrading to a new version may introduce compatibility issues with existing applications and infrastructure, and this can lead to unexpected downtime. Having enough technical expertise is inevitable to carry out version upgrades so that it does not break customizations and integrations, and bring down your applications.  &lt;/p&gt;

&lt;p&gt;(Trust me, this is the first thing that comes to everyone’s mind during version upgrade conversations.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WY3Niq4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/two-buttons-meme.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WY3Niq4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/two-buttons-meme.jpg" alt="Istio version upgrade challenge meme" width="500" height="756"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Source: stack.io&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Istio is one of the most popular projects in CNCF, with &lt;a href="https://istio.teststats.cncf.io/d/5/companies-table?orgId=1"&gt;over 500 companies&lt;/a&gt; including Google, Microsoft, and IBM contributing to it. The active community of contributors of Istio leads to faster releases of new features. However, dealing with upgrades itself can become a problem for developers. For instance, &lt;strong&gt;matching the Istio version to the underlying version of Kubernetes can be painful and time-consuming&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are many questions DevOps, architects, and cloud platform teams need to ask themselves:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is your current Istio version inadequate to meet your requirements?&lt;/li&gt;
&lt;li&gt;Does the new version, say v1.17, have all the features to help achieve your security and network management goals?&lt;/li&gt;
&lt;li&gt;Is the new Istio version stable?&lt;/li&gt;
&lt;li&gt;Will the new features significantly outweigh the cost of migrating to the new Istio version?&lt;/li&gt;
&lt;li&gt;What is the estimated cost of running the latest version of Istio?&lt;/li&gt;
&lt;li&gt;What is the estimated impact of the new version of Istio?&lt;/li&gt;
&lt;li&gt;What are the CVE risk mitigation strategies? How to ensure FIPS compliance?
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finding all these answers can be overwhelming for a team, and the discussion can stretch for months. Meanwhile, there is another major Istio release.&lt;/p&gt;

&lt;p&gt;Recently, Istio launched &lt;a href="https://imesh.ai/blog/what-is-istio-ambient-mesh/"&gt;ambient mesh&lt;/a&gt;, which has a completely different architecture aimed at solving the latency problem with Istio. Istio ambient mesh will be very compelling for existing Istio users to cut down their cloud bills. But the DIY model will only generate more problems in hand for developers to leave their core work and focus on upgrading Istio.&lt;/p&gt;
&lt;h2&gt;
  
  
  How enterprise Istio support can help
&lt;/h2&gt;

&lt;p&gt;The negative impact of managing Istio in a DIY operating model can be catastrophic at times, such as resulting in unexpected downtime. And since the developers maintaining Istio have to spend too much time learning and troubleshooting Istio along with their core work, the possible degradation of developer experience cannot also be overlooked.&lt;/p&gt;

&lt;p&gt;One ideal solution to avoid all the challenges of self-managing Istio and its negative impact is to choose enterprise Istio support. The enterprise Istio support solution is there to make the implementation of Istio and its management painless. IMESH provides &lt;a href="https://imesh.ai/enterprise-istio-support.html"&gt;enterprise Istio support&lt;/a&gt;, and here are three ways we can help.&lt;/p&gt;
&lt;h3&gt;
  
  
  Faster Istio implementation for multicloud and multicluster
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://imesh.ai/blog/secure-multicloud-and-multicluster-apps-with-istio/"&gt;Enabling Istio to secure multicluster and multicloud apps&lt;/a&gt; can cause endless troubleshooting in the DIY approach. Although Istio is Kubernetes-native, it needs careful planning and engineering to enable traffic management between multiple clusters and VMs. &lt;/p&gt;

&lt;p&gt;IMESH offers support for all kinds of workloads deployed in private or public clouds, Kubernetes, or VMs. Watch the video below to have a peek at how to get started with multicluster Istio in EKS and GKE.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/-X6ceIUhHIc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Enterprise customization for production usage
&lt;/h3&gt;

&lt;p&gt;Each enterprise requires custom integrations to implement Istio because they have different processes, tools, security standards, and governance policies. IMESH offers pre-built integrations and customizations for over 40 &lt;a href="https://imesh.ai/integration.html"&gt;DevOps tools&lt;/a&gt;. We also integrate with CD tools, such as Spinnaker and Argo CD, to help you deploy the security and network policies rapidly into target clusters.&lt;/p&gt;

&lt;p&gt;(Non-exhaustive) List of software that IMESH can integrate Istio service mesh with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data centers: AWS/GCP/Azure/On-prem VMs&lt;/li&gt;
&lt;li&gt;Kubernetes: On-prem K8s/EKS/AKS/GKE&lt;/li&gt;
&lt;li&gt;API Gateway: Mulesoft/APIgee/Kong/&lt;/li&gt;
&lt;li&gt;Ingress controllers: NGINX/HA proxy/Ambassador&lt;/li&gt;
&lt;li&gt;CD tools: Spinnaker/GitHub Action/Tekton&lt;/li&gt;
&lt;li&gt;GitOps tool: Argo CD/ Flux CD/ Argo Rollouts&lt;/li&gt;
&lt;li&gt;SCM: Git/Bitbucket/GitLab&lt;/li&gt;
&lt;li&gt;SSO(IAM): Google SSO/OAuth2.0/SAML/OKTA&lt;/li&gt;
&lt;li&gt;RBAC: LDAP/Azure AD&lt;/li&gt;
&lt;li&gt;Key management: Vault&lt;/li&gt;
&lt;li&gt;Certificate management: Lets Encrypt/AWS CA/ GCP CA/ SPIRE&lt;/li&gt;
&lt;li&gt;Monitoring: Prometheus/Zipkin/Skywalking/Stackdriver&lt;/li&gt;
&lt;li&gt;Logging: Datadog/Splunk&lt;/li&gt;
&lt;li&gt;Tracing: Jaeger&lt;/li&gt;
&lt;li&gt;Notification: Slack/Jira/MS Teams/PagerDuty &lt;/li&gt;
&lt;li&gt;Configuration management: Terraform&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rely on Istio experts for lifecycle management and CVE fixes
&lt;/h3&gt;

&lt;p&gt;There is a problem VPs and Directors of Engineering face when they have got someone who is doing a good job with Istio. Let us say if a team member in your organization is in charge of everything Istio, what happens when they leave suddenly? This can lead to operation disruptions and downtime, especially if you have configured Istio for multicluster/multicloud communications. From our interactions with various enterprises, we can say for sure that it happens quite a lot; &lt;strong&gt;Istio experts are hard to find and even harder to retain&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;With IMESH enterprise Istio support, you can ensure the &lt;strong&gt;availability of Istio experts around the clock&lt;/strong&gt;. They are specialized in setting up Istio for enterprise applications across multicloud and environments. Istio experts from &lt;strong&gt;IMESH can also help in seamlessly onboarding your developers, Ops, SRE, and Platform teams to Istio&lt;/strong&gt;. Regardless of your team size, environment size, or cluster size, IMESH’s Istio support team is obsessed with quickly providing value.  &lt;/p&gt;

&lt;p&gt;To understand the level of expertise our team has and experience it firsthand, you can watch some videos from &lt;a href="https://www.youtube.com/@imesh.ai_inc"&gt;IMESH YouTube channel&lt;/a&gt; where our Istio experts show demonstrations around Istio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LwAYL5PA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/IMESH-enterprise-Istio-support-and-services.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LwAYL5PA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/IMESH-enterprise-Istio-support-and-services.png" alt="IMESH enterprise Istio support and services" width="792" height="458"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;IMESH enterprise Istio support and services&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of IMESH enterprise Istio support
&lt;/h2&gt;

&lt;p&gt;IMESH provides Istio training, administration, and operation training. Besides, we provide advanced concepts training to developers, application/platform teams, SecOps, and SREs. Some major benefits of &lt;a href="https://imesh.ai/enterprise-istio-support.html"&gt;IMESH enterprise Istio support&lt;/a&gt; include the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;3X faster time to implement Istio&lt;/strong&gt; for your Kubernetes and VM workloads within SLA&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;$2Mn savings in the cost of ownership of maintaining Istio and Envoy&lt;/strong&gt; with faster time to vulnerability fixes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;100% security of traffic and data-in-transit&lt;/strong&gt; with faster implementation of certificates and authorization and authentication in your environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZfkfNjT1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/Benefits-of-IMESH-enterprise-Istio-support-1024x358.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZfkfNjT1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/05/Benefits-of-IMESH-enterprise-Istio-support-1024x358.png" alt="Benefits of IMESH enterprise Istio support" width="800" height="280"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Benefits of IMESH enterprise Istio support&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interested in trying enterprise Istio (free pilot)?
&lt;/h2&gt;

&lt;p&gt;Open-source solutions are not cheap. It takes a huge amount of resources to deploy and manage them. As we saw above, Istio is no exception to this pattern. IMESH helps enterprises with their Istio and Envoy journey, and you can test Istio before production by &lt;a href="https://imesh.ai/book-istio-service-mesh-pilot.html"&gt;booking a free Istio pilot&lt;/a&gt;. Our experts will help you deploy Istio in a pilot environment to determine the security benefits it can bring to your fleet of microservices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the core Istio features&lt;/li&gt;
&lt;li&gt;Implement mTLS&lt;/li&gt;
&lt;li&gt;Experiment with advanced network strategies&lt;/li&gt;
&lt;li&gt;Visualize network performance and behavior&lt;/li&gt;
&lt;li&gt;Evaluate the cost, time, and risk for the project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Book the free Istio pilot here: &lt;a href="https://imesh.ai/book-istio-service-mesh-pilot.html"&gt;https://imesh.ai/book-istio-service-mesh-pilot.html&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://dev.to/imesh/5-reasons-why-you-should-choose-enterprise-istio-over-diy-52a-temp-slug-2527291"&gt;5 Reasons Why You Should Choose Enterprise Istio Over DIY&lt;/a&gt; appeared first on &lt;a href="https://imesh.ai/blog"&gt;IMESH&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>istio</category>
      <category>servicemesh</category>
      <category>kubernetes</category>
      <category>enterprise</category>
    </item>
    <item>
      <title>Zero Trust Network for Microservices with Istio</title>
      <dc:creator>Anas T</dc:creator>
      <pubDate>Fri, 24 Mar 2023 07:41:06 +0000</pubDate>
      <link>https://dev.to/0anas0/zero-trust-network-for-microservices-with-istio-289b</link>
      <guid>https://dev.to/0anas0/zero-trust-network-for-microservices-with-istio-289b</guid>
      <description>&lt;p&gt;Security was mostly perimeter-based while building monolithic applications. This means securing the network perimeter and access control using firewalls. With the advent of microservices architecture, static and network-based perimeters are no longer effective.&lt;/p&gt;

&lt;p&gt;Nowadays, applications are deployed and managed by container orchestration systems like Kubernetes, which are spread across the cloud. Zero trust network (ZTN) is a different approach to secure data across cloud-based networks. In this article, we will explore how ZTN can help secure microservices.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Zero Trust Network (ZTN)?
&lt;/h2&gt;

&lt;p&gt;Zero trust network is a security paradigm that does not grant implicit trust to users, devices, and services, and continuously verifies their identity and authorization to access resources.  &lt;/p&gt;

&lt;p&gt;In a microservices architecture, if a service (client) receives a request from another service (server), the server should not assume the trustworthiness of the client. The server should continuously authenticate and authorize a client first and then allow the communication to happen securely (refer to fig. A below).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---2BLTycY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Zero-Trust-Network.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---2BLTycY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Zero-Trust-Network.png" alt="Zero Trust Network" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fig. A – A Zero Trust Network (ZTN) environment where continuous authentication and authorization are enforced between microservices across multicloud&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is a zero trust network environment inevitable for microservices?
&lt;/h2&gt;

&lt;p&gt;The importance of securing the network and data in a distributed network of services cannot be stressed enough. Below are a few challenges why a ZTN environment is necessary for microservices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Lack of ownership on the network:&lt;/strong&gt; Applications moved from perimeter-based to multiple clouds and data centers with microservices. As a result, the network has also got distributed, giving more attack surface to intruders.
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increased network and security breaches:&lt;/strong&gt; Data and security breaches among cloud providers have become increasingly common since applications moved to public clouds. In 2022, &lt;a href="https://www.ibm.com/reports/data-breach"&gt;nearly half of all data breaches occurred in the cloud&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Managing multicluster network policies has become tedious:&lt;/strong&gt; Organizations deploy hundreds of services across multiple Kubernetes clusters and environments. Network policies are local to clusters and do not usually work for multiple clusters. They require a lot of customization and development to define and implement security and routing policies in multicluster and multicloud traffic. Thus, configuring and managing consistent network policies and firewall rules for each service becomes an everlasting and frustrating process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Service-to-service connection is not inherently secure in K8s:&lt;/strong&gt; By default, one service can talk to another service inside a cluster. So, if a service pod is hacked, an attacker can quickly hack other services in that cluster easily (also known as vector attack). Kubernetes does not provide out-of-the-box encryption or authentication for communication between pods or services. Although K8s offers additional security features like enabling mTLS, it is a complex process and has to be implemented manually for each service.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lack of visibility into the network traffic:&lt;/strong&gt; If there is a security breach, the Ops and SRE team should be able to react to the incident faster. Poor real-time visibility into the network traffic across environments becomes a bottleneck for SREs to diagnose issues in time. This impedes their ability for incident response, which leads to high mean time for recovery (MTTR) and catastrophic security risks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In theory, a zero trust network (ZTN) philosophy solves all the above challenges. Istio service mesh helps Ops and SREs to implement ZTN and secure microservices across the cloud. &lt;/p&gt;

&lt;p&gt;Please read &lt;a href="https://imesh.ai/blog/top-10-pillars-of-zero-trust-network/"&gt;top 10 pillars of zero trust network considered by top CISOs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Istio service mesh enables ZTN for microservices
&lt;/h2&gt;

&lt;p&gt;Istio is a popular open-source service mesh implementation software that provides a way to manage and secure communication between microservices. Istio abstracts the network into a dedicated layer of infrastructure and provides visibility and control over all communication between microservices.&lt;/p&gt;

&lt;p&gt;Istio works by injecting an Envoy proxy (a small sidecar daemon) alongside each service in the mesh (refer to fig. B). Envoy is an L4 and L7 proxy that helps in ensuring security connections and network connectivity among the microservices, respectively. The Istio control plane allows users to manage all these Envoy proxies, such as directly defining and cascading security and network policies. (More on Istio architecture and its components will be explained soon in another blog.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uwQN6nvC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Istio-using-Envoy-proxy-to-secure-connection.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uwQN6nvC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Istio-using-Envoy-proxy-to-secure-connection.png" alt="Istio using Envoy proxy to secure connections between services" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fig B – Istio using Envoy proxy to secure connections between services across clusters and clouds&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Istio simplifies enforcing a ZTN environment for microservices across the cloud. Inspired by &lt;a href="https://www.gartner.com/smarterwithgartner/new-to-zero-trust-security-start-here"&gt;Gartner Zero Trust Network Access&lt;/a&gt;, we have outlined four pillars of zero trust network that can be implemented by Istio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U0AKnzDX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Four-pillars-of-zero-trust-network.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U0AKnzDX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://imesh.ai/blog/wp-content/uploads/2023/03/Four-pillars-of-zero-trust-network.png" alt="Four pillars of zero trust network" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Four pillars of zero trust network enforced by Istio service mesh&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Enforcing Authentication with Istio
&lt;/h3&gt;

&lt;p&gt;Security teams would be required to create authentication logic for each service to verify the identity of users (humans or machines) that sent requests. This is necessary to ensure the trustworthiness of the user.  &lt;/p&gt;

&lt;p&gt;In Istio, it can be done by configuring peer-to-peer and request authentication policies using &lt;code&gt;PeerAuthentication&lt;/code&gt; and &lt;code&gt;RequestAuthentication&lt;/code&gt; custom resources (CRDs):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Peer authentication policies involve authenticating service-to-service communication using mTLS. That is, certificates are issued for both the client and server to verify the identity of each other.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is a sample &lt;code&gt;PeerAuthentication&lt;/code&gt; resource that enforces strict mTLS authentication for all workloads in the &lt;code&gt;foo&lt;/code&gt; namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: security.istio.io/v1beta1  
kind: PeerAuthentication  
metadata:  
  name: default  
  namespace: foo  
spec:  
  mtls:  
    mode: STRICT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Request authentication policies involve the server ensuring whether the client is even allowed to make the request. Here, the client will attach JWT (JSON Web Token) to the request for server-side authentication.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is a sample &lt;code&gt;RequestAuthentication&lt;/code&gt; policy created in the &lt;code&gt;foo&lt;/code&gt; namespace. It specifies that incoming requests to the &lt;code&gt;my-app&lt;/code&gt; service must contain JWT that is issued, and verified using public keys by entities mentioned under &lt;code&gt;jwtRules&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: security.istio.io/v1beta1  
kind: RequestAuthenticationetadata:  
metadata:  
  name: jwt-example  
  namespace: foo  
spec:  
  selector:  
 matchLabels:  
  app: my-app  
  jwtRules:  
  – issuer: “https://issuer.example.com”  
 jwksUri: “https://issuer.example.com/keys”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both authentication policies are stored in Istio configuration storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Implementing authorization with Istio
&lt;/h3&gt;

&lt;p&gt;Authorization is verifying whether the authenticated user is allowed to access a server (access control) and perform the specific action. Continuous authorization prevents malicious users from accessing services, which ensures their safety and integrity.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;AuthorizationPolicy&lt;/code&gt; is another Istio CRD that provides access control for services deployed in the mesh. It helps in creating policies to deny, allow, and also perform custom actions against an inbound request. Istio allows setting multiple policies with different actions for granular access control to the workloads.  &lt;/p&gt;

&lt;p&gt;The following &lt;code&gt;AuthorizationPolicy&lt;/code&gt; denies POST requests from workloads in the &lt;code&gt;dev&lt;/code&gt; namespace to workloads in the &lt;code&gt;foo&lt;/code&gt; namespace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: security.istio.io/v1beta1  
kind: AuthorizationPolicy  
metadata:  
  name: httpbin  
  namespace: foo  
spec:  
  action: DENY  
  rules:  
  – from:  
    – source:  
      namespaces: [“dev”]  
    to:  
    – operation:  
      methods: [“POST”]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Multicluster and multicloud visibility with Istio
&lt;/h3&gt;

&lt;p&gt;Another important pillar of ZTN is network and service visibility. SREs and Ops teams would require real-time monitoring of traffic flowing between microservices across cloud and cluster boundaries. Having deep visibility into the network would help SREs quickly identify the root cause of anomalies, develop resolution, and restore the applications.&lt;/p&gt;

&lt;p&gt;Istio provides visibility into traffic flow and application health by collecting the following telemetry data from the mesh from the data and control plane. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Logs:&lt;/strong&gt; Istio collects all kinds of logs such as services logs, API logs, access logs, gateway logs, etc., which will help to understand the behavior of an application. Logs also help in faster troubleshooting and diagnosis of network incidents.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metrics:&lt;/strong&gt; They help to understand the real-time performance of services for identifying anomalies and fine-tuning them in the runtime. Istio provides many metrics apart from the 4 golden ones, which are error rates, traffic, latency, and saturation.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed tracing:&lt;/strong&gt; It is the tracing and visualizing of requests flowing through multiple services in a mesh. Distributed tracing helps understand interactions between microservices and provides a holistic view of service-to-service communication in the mesh.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  4. Network auditing with Istio
&lt;/h3&gt;

&lt;p&gt;Auditing is analyzing logs of a process over a period with the goal to optimize the overall process. Audit logs provide auditors with valuable insights into network activity, including details on each access, the methods used, traffic patterns, etc. This information is useful to understand the communication process in and out of the data center and public clouds.&lt;/p&gt;

&lt;p&gt;Istio provides information about who accessed (or requested), when, and onto what resources, which is important for auditors to investigate faulty situations, and then suggest steps to improve the overall performance of the network and security of cloud-native applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy Istio for a better security posture
&lt;/h2&gt;

&lt;p&gt;The challenges around securing networks and data in a microservices architecture are going to be increasingly complex. Attackers are always ahead in finding vulnerabilities and exploiting them before anyone in the SRE team gets time to notice.  &lt;/p&gt;

&lt;p&gt;Implementing a zero-trust network will provide visibility and secure Kubernetes clusters from internal or external threats. Istio service mesh can lead this endeavor from the front, with its ability to implement zero trust out of the box. IMESH helps enterprises to onboard and adopt Istio service mesh without any operation hassle. Check out our &lt;a href="https://www.imesh.ai/pricing.html."&gt;offerings&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;About IMESH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imesh.ai/"&gt;IMESH&lt;/a&gt; offers solutions to help you avoid errors during the experimentation of implementing Istio and fend off operational issues. IMESH provides a platform built on top of Istio and Envoy API gateway to help start with Istio from Day-1. IMESH Istio platform is hardened for production and is fit for multicloud and hybrid cloud applications. IMESH also provides consulting services and expertise to help you adopt Istio rapidly in your organization. &lt;/p&gt;

&lt;p&gt;IMESH also provides a strong visibility layer on top of Istio which provides Ops and SREs a multicluster view of services, dependencies, and network traffic. The visibility layer also provides details of logs, metrics, and traces to help Ops folks to troubleshoot any network issues faster.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://imesh.ai/blog/zero-trust-network-for-microservices-with-istio/"&gt;Zero Trust Network for Microservices with Istio&lt;/a&gt; appeared first on &lt;a href="https://imesh.ai/blog"&gt;IMESH&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>istio</category>
      <category>kubernetes</category>
      <category>microservices</category>
      <category>zerotrust</category>
    </item>
  </channel>
</rss>
