<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fatemeh Ahmadi on Medium]]></title>
        <description><![CDATA[Stories by Fatemeh Ahmadi on Medium]]></description>
        <link>https://medium.com/@fahmadi?source=rss-4296d2145ecc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*V3xC7hlWBdqfXKHyxAucag.jpeg</url>
            <title>Stories by Fatemeh Ahmadi on Medium</title>
            <link>https://medium.com/@fahmadi?source=rss-4296d2145ecc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:33:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fahmadi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tracing Express services with Zipkin and OpenTelemetry]]></title>
            <link>https://medium.com/@fahmadi/tracing-express-services-with-zipkin-and-opentelemetry-9a3b3026d13b?source=rss-4296d2145ecc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a3b3026d13b</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[zipkin]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Fatemeh Ahmadi]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 16:17:17 GMT</pubDate>
            <atom:updated>2020-03-28T16:17:17.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*ZgGg_5ElmkpS28Jg.png" /></figure><p>Today I decided to share one of the challenges I have faced and the solution that I have found to solve it.</p><h3>What is the problem?</h3><p>In a project, I was a Nodejs developer in a team. In the backend of the project, we have some services that work together in a microservice architecture. These services write in Nodejs programming language.</p><p>The problem arose when we recognized that some requests to a microservice could have taken longer than the usual time and we get the response with delay.</p><p>So we want to know where the application spent most of its time and we do not have an idea about what occurs in the backend and why these requests get a longer time and what service or module creates this problem.</p><p>In the last few years, the microservice architecture pattern has become mainstream. The pattern solves many problems of the monolithic architecture design but has some drawbacks, one of the biggest being how hard it is to debug the system as a whole.</p><p>In a microservice architecture, tracing is extremely challenging because requests will span multiple services, each executing one or more processes, across multiple servers</p><h4>Distributed Tracing help to Microservices Architecture !</h4><p>One of the best tools you can have in your belt when you are dealing with microservices is<a href="https://opentracing.io/docs/overview/what-is-tracing/"> distributed tracing</a>. Distributed tracing lets you know what is happening in your system and which parts are involved, even in production.</p><p>So this is a time that Zipkin can help you to trace your request.</p><h4>What is Zipkin?</h4><p><a href="https://zipkin.apache.org/"><strong>Zipkin</strong></a><strong> </strong>is an<a href="https://github.com/openzipkin/zipkin"> open-source</a><a href="https://opentracing.io/docs/overview/what-is-tracing/"> distributed tracing system</a><strong> </strong>based on<a href="https://research.google.com/pubs/pub36356.html"> Google Dapper</a> and initially developed by Twitter, is a Java-based distributed tracing application that helps gather timing data for every request propagated between independent services. It has a simple management console where we can find a visualization of the time statistics generated by subsequent services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*TaZBPB7pZeOkVBM5DzLBZg.png" /><figcaption>zipkin flow</figcaption></figure><p>The component in an instrumented app that sends data to Zipkin is called a Reporter. Reporters send trace data via one of several transports to Zipkin collectors, which persist trace data to storage. Later, storage is queried by the API to provide data to the UI.</p><h3>First solution</h3><p>So I decided to instrument my application by adding tracing to common pieces in the code. As my project was very huge I create a simple project and build a couple of<a href="https://expressjs.com/"> Express</a> microservices and use<a href="https://github.com/openzipkin/zipkin-js"> Zipkin-js</a> to trace them. based on this<a href="https://medium.com/trabe/tracing-express-services-with-zipkin-js-6e5c5680467e"> article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*p6Nk2Z3RZPIlFJk0" /></figure><p>After I build this and use the tracker in it everything is ok but tracer in my project did not work properly. Zipkin-js or display UI does not show the correct span and generate span in Zipkin-js is hard because we don’t have full control over it. Furthermore, I think Zipkin’s document is not complete.</p><p>So I was very frustrated and wanted to solve this problem. After research on it, my CTO suggested to me to use <a href="https://github.com/open-telemetry/opentelemetry-js">OpenTelemtry</a> library for the client of the tracer processes. It helped me further control on generate span. So I had to setup OpenTelemtry so that it can send traces to Zipkin. In other words, Zipkinn is in its place in the backend. OpenTelemtry comes as a client-side and uses Zipkin’s protocol so it can speak with Zipkin and send a trace to it.</p><p><strong>So my problem changed as follow:</strong></p><p>I have a couple of<a href="https://expressjs.com/"> Express</a> microservices ( hello-service-1 &amp; hello-service-2 ), Zipkin stay in the backend server and OpenTelemtry is in the client. I want to call hello-service-1 from sample client. In hello-service-1 call hello-service-2 and set trace for this request. it’s clear! you think we have 2 services for example login and purchase. Each user must log in first and then be allowed to do purchase actions. So in this example, we have 2 services: <em>login</em> and <em>purchase</em>. purchase service call login service to check user access. In this example, purchase as hello-service-1 and login as hello-service-2.</p><p>So we want to trace a request when it starts from purchase and goes to login. We want to find out exactly where this request has spent more time.</p><h3>Setup Project:</h3><p>A solution that I find is to use <a href="https://www.npmjs.com/package/express-http-context">express-http-context </a>module to change request context such that I can set parent of a request.</p><p>tracer.js :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce2f21cf7090ddce3e1d026ba35b8d82/href">https://medium.com/media/ce2f21cf7090ddce3e1d026ba35b8d82/href</a></iframe><p>with createSpan and endSpan now I can easily use this function in everywhere I want to trace and create or end span</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ef7385b665c1587e254f78e635cc954/href">https://medium.com/media/6ef7385b665c1587e254f78e635cc954/href</a></iframe><p>We are going to use got as our HTTP client to make the request. To get got working with Zipkin we need to instrument it. I instrumented it manually:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/048a810504e202352b302c87db3b39d2/href">https://medium.com/media/048a810504e202352b302c87db3b39d2/href</a></iframe><p>Usage with express as a middleware:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39fe81c96e4f98dc1351234242d370dd/href">https://medium.com/media/39fe81c96e4f98dc1351234242d370dd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/048a810504e202352b302c87db3b39d2/href">https://medium.com/media/048a810504e202352b302c87db3b39d2/href</a></iframe><p>Now, if we get both services up and make a request to localhost:8081 we can see a trace like this in our zipkin-ui:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPLY23yd0N200ccmz1NcRQ.png" /></figure><p>we can now understand what is happening in our services just by looking at the trace. Pretty neat, right? :)</p><p>a github repo with the full example can be found <a href="https://github.com/Fahmadi/tracing-helper-library/tree/master/tracing-helper">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a3b3026d13b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>