<?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 Ravindu Guruge on Medium]]></title>
        <description><![CDATA[Stories by Ravindu Guruge on Medium]]></description>
        <link>https://medium.com/@ravinduguruge?source=rss-e01faa341ffc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ph8TvqKTql-FMNEc.jpg</url>
            <title>Stories by Ravindu Guruge on Medium</title>
            <link>https://medium.com/@ravinduguruge?source=rss-e01faa341ffc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:15:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravinduguruge/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[ How to Use Third-Party LLMs with Google Agent Development Kit (ADK): A Dark Joke Agent Tutorial]]></title>
            <link>https://ravinduguruge.medium.com/how-to-use-third-party-llms-with-google-agent-development-kit-adk-a-dark-joke-agent-tutorial-31241f42f1c4?source=rss-e01faa341ffc------2</link>
            <guid isPermaLink="false">https://medium.com/p/31241f42f1c4</guid>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[llm-agent]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Ravindu Guruge]]></dc:creator>
            <pubDate>Tue, 01 Jul 2025 12:04:19 GMT</pubDate>
            <atom:updated>2025-07-01T12:04:19.326Z</atom:updated>
            <content:encoded><![CDATA[<p>Google’s Agent Development Kit (ADK) provides a modular and extensible framework for building AI agents. But did you know you can integrate <em>third-party LLMs</em>, like OpenAI’s GPT-4o-mini, into your ADK agents effortlessly? In this post, I’ll show you how I built a simple yet entertaining <em>dark joke generator</em> using Google ADK + OpenAI, and discuss the <strong>built-in</strong> <strong>tool compatibility limitations</strong> when using non-Google LLMs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*A4-k_sI5kmrphjS4tJ_rpA.png" /></figure><h3>🗂️ Folder Structure: Keeping It Clean and Modular</h3><p>Let’s first examine the folder structure that supports the agent:</p><p>Project/<br>├── dark_joke/<br>│ ├── __init__.py<br>│ ├── .env <em>#</em> 🔐<em> Stores API keys</em><br>│ ├── .gitignore<br>│ └── agent.py <em>#</em> 🧠 <em>Core logic of our LLM agent</em><br>├── venv/ <em># Virtual environment</em><br>└── requirements.txt <em>#</em> 📦 <em>Dependency list</em></p><h3>🧠 Code Breakdown: agent.py</h3><p>Let’s break down what each part of the file does:</p><ol><li><strong>Importing ADK + LLM</strong></li></ol><pre>from google.adk.agents import Agent<br>from google.adk.models.lite_llm import LiteLlmpy</pre><p>LiteLlm is a lightweight wrapper that lets you plug external LLM providers (like OpenAI) into Google ADK with minimal fuss.</p><p>2. <strong>Loading the LLM</strong></p><pre>model = LiteLlm(model=&quot;openai/gpt-4o-mini&quot;)</pre><p>This initializes the GPT-4o-mini model from OpenAI. It automatically reads the OPENAI_API_KEY from .env — you don’t even need to explicitly call load_dotenv().</p><p><strong>3. Defining a Tool:</strong> dark_joke()</p><pre>def dark_joke() -&gt; dict:<br>    return {<br>        &quot;joke&quot;: &quot;Why don&#39;t graveyards ever get overcrowded? Because people are dying to get in.&quot;<br>    }</pre><p>This tool returns a joke. Tools like this can be registered with the agent so that the LLM can “call” them during a conversation.</p><p>4. <strong>Registering the Agent</strong></p><pre>root_agent = Agent(<br>    name=&quot;dark_jokes&quot;,<br>    model=model,<br>    description=&quot;An agent that tells dark jokes.&quot;,<br>    instruction=&quot;&quot;&quot;You are a dark jokes agent.<br>    Your task is to tell jokes with dark humor to the user.<br>    Please use only the following tool:<br>    - dark_joke&quot;&quot;&quot;,<br>    tools=[dark_joke],<br>)</pre><p>You explicitly tell the agent what tool(s) it’s allowed to use. This instruction layer ensures <strong>controlled interaction</strong>, especially when using third-party LLMs.</p><h3>🧰 Tool Calling with Third-Party LLMs: Know the Limitations</h3><p>Google ADK allows you to define tools as Python functions and expose them to the LLM through the agent’s instruction. This works fine when you define <strong>custom tools</strong> (like dark_joke()), but there’s a <strong>key limitation</strong> to be aware of:</p><p>❌ <strong>Third-party LLMs (like OpenAI or Anthropic) cannot use ADK’s built-in tools such as </strong><strong>google_search. They can only be used with Gemini 2 models.</strong></p><p>Apart from this limitation, built-in tools can only be used in root agents or single agents (cannot be used in sub agents). And also, only one built-in tool can be used with the root/single agent. Further, no other tools of any type can be used in the same agent which uses the built-in tool.</p><h4>✅ Workaround</h4><p>To use tools with third-party LLMs:</p><ul><li>Define <strong>custom Python functions</strong> as tools (like dark_joke() as demonstrated in my example).</li><li>Provide <strong>clear instructions</strong> in the Agent&#39;s instruction field.</li></ul><h3>🧬 Example .env File</h3><pre>OPENAI_API_KEY=&lt;your_openai_api_key_here&gt;</pre><p>This is automatically used by LiteLlm, no need for manual loading.<br>If you don’t have an OpenAi api-key already, use the following link to create one.</p><p><a href="https://platform.openai.com/api-keys">https://platform.openai.com/api-keys</a></p><p>You will also have to topup your account in order to use this API. Otherwise you can use any other third-party LLM like Anthropic if you already have the api-keys. But make sure you define the model correctly.</p><h3>requirements.txt</h3><pre>google-adk[database]<br>litellm<br>python-dotenv</pre><p>This consist of all the required packages for this project. We will be installing them in the virtual env.</p><h3>__init__.py</h3><pre>from . import agent</pre><p>When adk command is executed, this file will inform the adk controller where our agent resides.</p><h3>❗IMPORTANT❗</h3><p>If you are version controlling your project, make sure to add a .gitignore file of type “Python”. You can create one using <a href="https://www.toptal.com/developers/gitignore">this link</a> or with GitHub when creating a repo.</p><p>When you have all the above files and code in place, execute the following commands from the PROJECT_ROOT directory one after the other to initiate a Python virtual environment and install the required packages.</p><pre>python -m venv venv<br><br>#If using a Linux kernel<br>source ./venv/bin/activate<br><br>#If using Windows<br>source venv/Scripts/activate<br><br>pip install -r requirements.txt<br></pre><p>Once everything is installed, you are all set. Let’s run your agent with adk web. ADK web is the built-in developer UI (built using Angular) that is integrated with Agent Development Kit for easier agent development and debugging.</p><p>Navigate inside the dark_joke directory and execute the following command.</p><pre>adk web</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WU3uUUAuTCiG7n7dJWMF0Q.png" /></figure><h3>📔 Take Notes</h3><p>No matter how many times you request a joke, the agent will only return the same joke.</p><p>You probably will understand by now that this is caused due to the dark_joke() tool we are using. Since we have limited our agent to use the tool, it will not go beyond our command. If you want your gpt-40-mini model to be in-charge of telling jokes, you can modify the agent instructions as follows:</p><pre>root_agent = Agent(<br>    name=&quot;dark_jokes&quot;,<br>    model=model,<br>    description=&quot;An agent that tells dark jokes.&quot;,<br>    instruction=&quot;&quot;&quot;You are a dark jokes agent.<br>    Your task is to tell jokes with dark humor to the user.&quot;&quot;&quot;,<br>)</pre><h3>✅ What we learned</h3><p>This was a simple yet powerful demo of how to:</p><ul><li>How to use Third-party models with Google ADK via LiteLlm.</li><li>Keep your project <strong>clean and scalable</strong>.</li><li>Define <strong>tool-limited agents</strong> for safety and modularity.</li></ul><p>You can now move a step ahead and integrate sub-agents to this flow as well. I’ll leave it to you… 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31241f42f1c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Simple Pipeline in Azure Data Factory: Copying Data from an HTTP Server to Azure Data…]]></title>
            <link>https://ravinduguruge.medium.com/creating-a-simple-pipeline-in-azure-data-factory-copying-data-from-an-http-server-to-azure-data-21bc9e8c4589?source=rss-e01faa341ffc------2</link>
            <guid isPermaLink="false">https://medium.com/p/21bc9e8c4589</guid>
            <dc:creator><![CDATA[Ravindu Guruge]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 15:05:01 GMT</pubDate>
            <atom:updated>2025-02-28T15:05:01.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a Simple Pipeline in Azure Data Factory: Copying Data from an HTTP Server to Azure Data Lake</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mdb85JGY1mW3B25eA2i1vQ.jpeg" /></figure><p>In this blog post, we’ll walk through the process of creating a simple pipeline in Azure Data Factory to copy data from an external source (GitHub HTTP server in this case) to Azure Data Lake. This step-by-step guide will help you set up a dynamic data copying process, perfect for handling multiple files efficiently.</p><p>Ready? Let’s go! 😎</p><h3><strong>Setting Up the Environment</strong></h3><p>Before we dive into creating the pipeline, let’s set up our Azure environment:</p><ol><li>Create a resource group in Azure.</li><li>Set up a Storage account (This is your datalake):</li></ol><ul><li>Search for ‘Storage accounts’ in the global search.</li><li>I’ll be using LRS for redundancy (under Basics) since this is a demo project. You can choose otherwise depending on your preference.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OxBKCgGdnrQnxLVmuGM-uQ.png" /></figure><ul><li>Move on to the “Advanced” section and tick “Enable hierarchical namespace” so that you can create directory structures.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*N7XiqQh4HHYYGXgl9zYaPA.png" /></figure><ul><li>Click on ‘Review + create’.</li><li>Once the storage account is created, navigate inside and locate ‘Data Storage &gt; Containers’ on the left panel.</li><li>Create a container named ‘raw’ inside the data lake. This name can be anything. I’ve chosen ‘raw’ since we will be dealing with raw data in this container.</li></ul><p>3. Create a Data Factory:</p><ul><li>Search for ‘data factories’ in the global search.</li><li>Fill in the basic fields and create the data factory.</li><li>Go to the resource and launch Studio.</li></ul><h3>Creating the Pipeline</h3><p>Now that our environment is ready, let’s create the pipeline:</p><ol><li>In the Data Factory Studio, click on the Author tab.</li><li>Hover over the Pipelines tab, click on the three dots, and select “New Pipeline”.</li><li>Search for “Copy data” in the Activities panel and drag it to the canvas.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*jD7Esoccc_lXeF6rRLKtAA.png" /></figure><h3>Setting Up the Copy Data Activity</h3><p>The Copy Data activity will transfer data from our source (GitHub) to our sink (Azure Data Lake). We’ll use Linked Services to connect these external endpoints to our pipeline.</p><p>Remember, we have 2 files to copy from GitHub to our data lake. So having 2 copy data activities is not ideal. Hence, let’s make our copy data dynamic. Follow the steps below in order to do this:</p><h3>Configuring the Source</h3><ol><li>Create a Linked Service for the HTTP source:<br>There are 2 ways of creating a linked service. Either you can create it separately from the “Manage” interface or you can create it at the time you create a new dataset.<br>I will be showing you the 1st method now and the 2nd method when creating the sink.</li></ol><ul><li>Go to “Linked Services” in the “Manage” tab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*NBSijZNxHKzB8FdcOJRM2w.png" /></figure><ul><li>Click “New” and search for “HTTP”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*555nBxBfJFvv7fxyPdsGbg.png" /></figure><ul><li>Choose “DelimitedText” as the data format because we are dealing with CSV files here.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HvWgvCulOX3rUX-IXpo5ew.png" /></figure><ul><li>Configure the Base URL to point to your GitHub raw file.</li><li>Once everything is configured, the configs should look similar to the below screenshot.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*l2fZT_qy-vv1mg5ik0uXqg.png" /></figure><p><em>Please note that I have not paid much attention to the Authentication type since this is a demo project. But you can choose to protect it with a different authentication type if you wish.</em></p><p>If you want to see how I got the Base URL, please refer the GitHub repo [1] and the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kg30XtQK5sMVq8Ce3LIjQw.png" /></figure><p>Locate the file and click on “Raw” button shown in the screenshot. Then the http link can be obtained from the redirected page.</p><p>2. Set up the Source dataset:</p><ul><li>In the Copy Data activity, create a new Source dataset.</li><li>Select HTTP as the source type.</li><li>Choose the Linked Service you just created.</li><li>Leave the “Relative URL” blank for now.</li><li>Collapse the “Advanced” section and click on “Open this dataset” that will take you to the “Connection” tab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*AN9vv4CQCM42mo5rrGdlww.png" /></figure><ul><li>Click on the link “Add dynamic content” or press the key combination shown there.</li><li>Create a new “parameter” from the dialog that appears.</li><li>Once created, click on the parameter name so that it appears in the dynamic content box as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*89lIacCHqIuSJLjP1A91LQ.png" /></figure><h3>Configuring the Sink</h3><p>Go back to your pipeline, select the “Copy Data” activity and navigate to the Sink tab.</p><ol><li>Create a new Sink dataset:</li></ol><p><em>When you click on the “Sink dataset” dropdown, you will see the previous dataset you created for source. </em><strong><em>DO NOT SELECT IT!</em></strong></p><ul><li>Select “Azure Data Lake Storage Gen2” as the type.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*h4IFRG3w0cyoEL9WjFz2MA.png" /></figure><ul><li>Choose DelimitedText as the format.</li><li>Create a new Linked Service for your Data Lake.</li></ul><p>This time, we will create the linked service while we create the dataset.</p><ul><li>Select the “Linked service” dropdown and click on “New”.</li></ul><p>Your configs should look something similar to the following image. (Make sure you replace “storage account name” with the storage account you created):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*ZhjUmw-Vhooidawp5-BGOQ.png" /></figure><p>Once the linked service is created, you will have to enter the filepath to which the data from the http links will be copied.</p><blockquote><strong>Where do you think these files will be saved to?<br></strong>You are correct if your guess was the “raw” container we created inside the datalake at the beginning.</blockquote><p>Let’s proceed to configure the Sink properties.</p><ul><li>Click on browse and select “raw” (or any other name you gave for this container). Leave the directory and the filename blank because we will be dynamically naming them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*Tm3zbh35NKfiz3-93qZl8w.png" /></figure><blockquote>Wonder how you are able to see the container you created elsewhere? That is because you linked the entire datalake (in which you created this container) to the sink of the copy data activity through the linked service.</blockquote><p>2. Make the Sink dynamic</p><ul><li>Collapse “Advanced” section and click on “Open this dataset”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AlSqCma2-dhJ0LsxgWD-QQ.png" /></figure><ul><li>Create parameters for the directory and file name in the respective boxes similar to the one we created to handle the dynamic <em>Relative URL</em> in the source.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZfgO4Bfc_O2uocWiAZLHQ.png" /></figure><p>Below images show how the source and the sink will look now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*HmfOeNTIpLh03cGGQH6qww.png" /><figcaption>Source</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*1904LDFxe80Fb3ixmuJtZg.png" /><figcaption>Sink</figcaption></figure><h3>Adding Dynamic Functionality</h3><p>Now we are done with parameterizing the flow. But how can we assign values to these parameters?<br>To make our pipeline handle multiple files, we’ll use a Lookup activity and a ForEach loop.</p><ol><li>Before adding a Lookup:</li></ol><ul><li>Create a new container in your datalake just like you created “raw”</li><li>Create a new JSON file with your parameter configurations and upload it to the new container you just created (Or download the file [2] and upload it to the newly created container).</li></ul><blockquote>Make sure the parameter names correspond to the ones you’ve defined.</blockquote><p>Now go back to your canvas and continue configuring the Lookup.</p><p>2. Add a Lookup activity</p><ul><li>Drag and drop a Lookup activity and create a new dataset.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*_9LI0lM5znnYpmV3sPCAfQ.png" /></figure><ul><li>Select “Azure Data Lake Storage Gen2” as the type.</li><li>Make sure the format is <strong><em>json</em></strong> this time. Because the configs are in a json file.</li><li>Use the same linked service and the “storage account name” that was used for the Sink above.</li><li>File path for params can be selected as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*A3vBpixI7ppPO_P82wYh8g.png" /></figure><ul><li>The properties should look similar to the image below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*kdWk_sLLlm_3OtcAgK9-rg.png" /></figure><ul><li>Once you create it, make sure to go to the “Settings” tab of the Lookup and <strong>untick </strong>“First row only” because we need all the rows.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*C7FXbBdrMwSpII3JF93hmg.png" /></figure><p>Now we have the parameters and their values. But how can we iterate over the 2 files to dynamically copy them?<br>This can be done with the help of a “ForEach” activity.</p><p>3. Move the Copy Data activity inside the ForEach loop</p><blockquote>Just having a ForEach won’t help, “Copy Data” activity should loop inside the ForEach. Let’s do it.</blockquote><ul><li>Add a ForEach activity to the canvas.</li><li>Select the “Copy Data” activity and use “CTRL + X” to cut it from the canvas.</li><li>Then select the ForEach activity, click on the “Activities” Tab and then the edit button. A new canvas will open. (This canvas is actually inside the for loop)</li><li>Paste the “Copy Data” inside this canvas as shown here:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*7ggBLejW5RrAwnizLzQrXA.png" /></figure><ul><li>Get back to the main canvas and link the Lookup output to the ForEach input.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRcJIKApUNtr12V_fmVSkw.png" /></figure><p>We need to now pass the output from lookup to foreach.</p><ul><li>Select the ForEach activity and follow the configs in the below images:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*z8d8v2tqtUlORY5xsBNwNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*kpwHVO3tz6LnDMORRBLkNw.png" /></figure><ul><li>Select the “Lookup value array” option because we need the array of outputs.</li></ul><p>Since we have the values now, let’s pass them to the relevant parameters.</p><p>4. Configure dynamic content</p><p>In the Copy Data activity, use dynamic content to set the source and sink parameters based on the ForEach loop’s current item.</p><ul><li>Go inside the ForEach canvas and select the “Source” tab of the Copy Data activity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*U8LqdpQKRUZknsOKJU6c3Q.png" /></figure><ul><li>Click on “Add dynamic content” and select your ForEach loop.</li></ul><blockquote>This for each loop will now have the values retrieved from the Lookup.</blockquote><ul><li>Define accordingly as shown below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*JUdlH2_1LOwvbJ5OF_W3Fw.png" /></figure><blockquote>Note the last part has to be appended by you. (i.e the parameter name)</blockquote><ul><li>Do the same with the sink parameters.</li></ul><h3>Testing the Pipeline</h3><p>With everything set up, it’s time to test our pipeline:</p><ol><li>Click on “Debug” to run the pipeline.</li><li>If successful, you should see a success message.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsanZCyLd2LdT0BnzFxGsQ.png" /></figure><p>3. Check your “raw” container in the Data Lake to see the copied files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*f70v5OaLfEZmd31L7xmOQg.png" /></figure><h3>Conclusion</h3><p>Congratulations! 🥳🎊🍾</p><p>You’ve successfully created a dynamic pipeline in Azure Data Factory that can copy multiple files from an external source to Azure Data Lake. This setup provides a flexible and scalable solution for data ingestion, allowing you to easily add or modify source files without changing the pipeline structure.</p><h3>References</h3><p>[1] <a href="https://github.com/ragwap/Customer-Churn">https://github.com/ragwap/Customer-Churn</a></p><p>[2] <a href="https://github.com/ragwap/Customer-Churn/blob/main/params.json">https://github.com/ragwap/Customer-Churn/blob/main/params.json</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21bc9e8c4589" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WSO2 API Manager + Custom synapse handler + Jaeger OpenTracing]]></title>
            <link>https://ravinduguruge.medium.com/wso2-api-manager-v3-2-0-custom-synapse-handler-jaeger-opentracing-ef8c4b595db4?source=rss-e01faa341ffc------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef8c4b595db4</guid>
            <category><![CDATA[jaeger]]></category>
            <category><![CDATA[wso2-api-manager]]></category>
            <dc:creator><![CDATA[Ravindu Guruge]]></dc:creator>
            <pubDate>Sat, 10 Jul 2021 11:09:59 GMT</pubDate>
            <atom:updated>2021-07-11T03:29:59.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*Ag8m8KJ4U7I11H9XXbwwZw.jpeg" /></figure><p>Hi everyone!! 👋</p><p>In this medium blog, I will be walking you through how to properly have a Custom synapse handler in place with WSO2 APIM and Jaeger opentracing without obstructing the traces displayed in Jaeger agent.</p><p>Before starting off, let’s see what opentracing is and how it helps. This is a mechanism of monitoring transactions or workflow as it propagates through a distributed system. With WSO2 API Manager, we have the support to integrate opentracing tools such as Jaeger and Zipkin. We will be focusing on Jaeger in this blog.</p><p>Let’s hop in!!</p><h3>Jaeger</h3><p>I assume you are running a docker image or have downloaded a Jaeger pack to run Jaeger locally.</p><p>Don’t worry if not, follow either of the methods given below to get Jaeger up and running:</p><ol><li>Download a Jaeger pack:</li></ol><p>You can download the relevant Jaeger pack to your machine from this link [1].</p><p>Extract the pack, navigate in and run the jaeger-all-in-one executable.</p><p>2. Hosting a docker image:</p><p>Note that I’ll be using Jaeger version 1.22 in this case.</p><pre>docker run -d --name jaeger \</pre><pre>-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \</pre><pre>-p 5775:5775/udp \</pre><pre>-p 6831:6831/udp \</pre><pre>-p 6832:6832/udp \</pre><pre>-p 5778:5778 \</pre><pre>-p 16686:16686 \</pre><pre>-p 14268:14268 \</pre><pre>-p 14250:14250 \</pre><pre>-p 9411:9411 \</pre><pre>jaegertracing/all-in-one:1.22</pre><p>Since Jaeger is up and running now, we can continue to configure the APIM.</p><p>Configure APIM to enable Jaeger opentracing.</p><p>Navigate to &lt;APIM_HOME&gt;/repository/conf/deployment.toml and add the following config block.</p><pre>[apim.open_tracer]</pre><pre>remote_tracer.enable = true</pre><pre>remote_tracer.name = &quot;jaeger&quot;</pre><pre>remote_tracer.properties.hostname = &quot;localhost&quot;</pre><pre>remote_tracer.properties.port = &quot;6831&quot;</pre><p>Start/Restart the APIM server.</p><p>Now you can invoke an API through the APIM which will in return monitor the calls in Jaeger.</p><p>Navigate to Jaeger console via <a href="http://localhost:16686/search">http://localhost:16686/search</a></p><p>Select the service name from the Jaeger UI (It’s API Latency in my case).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMYz7UBOL7kqEiDBknZKdQ.png" /></figure><p>Great!! You did it. 👏</p><h3>How can we have a custom synapse handler now?</h3><p>What if you need to have a custom synapse handler in the API invocation flow? Of course you can have it, but will require some tweaks to get it work as expected. Just adding a synapse handler will remove the parent span and all the spans which were displayed as child spans before will be displayed as single spans with no parent afterwards.</p><p>No worries… let’s make it work!!!</p><p>Checkout the following Github repo:</p><blockquote><strong><em>Note:</em></strong> The repository contains the source and dependencies supported to WSO2 API Manager v3.1.0</blockquote><p><a href="https://github.com/ragwap/OpenTracing_CustomMediator">ragwap/OpenTracing_CustomMediator</a></p><p>This contains a mock synapse handler to guide you through the process. Let’s begin.</p><ul><li>Open the java project in an IDE.</li><li>Navigate to the java class Mock.java that resides in &lt;MOCK_PROJECT_HOME&gt;/src/main/java/com/test.</li><li>Note the 4 methods from the abstract class that you need to override (<em>handleRequestInFlow</em>, <em>handleRequestOutFlow</em>, <em>handleResponseInFlow</em>, <em>handleResponseOutFlow</em>)</li><li>Copy the entire implementation per method (Omit the print statements. Those are for testing purposes) and append it to the respective methods in your custom handler.</li><li>Also make sure to import the required packages to your handler referring to Mock.java. Do relevant modifications to the pom.xml (in your handler) if required.</li><li>Save and build your handler. (Open a terminal, navigate to where the pom.xml of your custom handler resides, and execute the following)</li></ul><pre>mvn clean install</pre><ul><li>After a successful build, copy the generated jar file from &lt;YOUR_CUSTOM_HANDLER_PROJECT&gt;/target</li><li>Remove the previous jar from &lt;APIM_HOME&gt;/repository/components/dropins and &lt;APIM_HOME&gt;/repository/components/lib folders. (Note: This step needs to be followed only if you had a previously built jar from the same synapse mediator)</li><li>Add the copied jar to &lt;APIM_HOME&gt;/repository/components/lib folder (it will automatically be added to the dropins folder)</li><li>Add the following to the top of deployment.toml file residing under &lt;APIM_HOME&gt;/repository/conf directory and save changes. (Replace <strong><em>com.test.Mock</em></strong><em> </em>with the class name you created as the handler)</li></ul><pre>enabled_global_handlers = [&quot;messageTracing&quot;]<br>[synapse_handlers]<br>messageTracing.name = &quot;messageTracing&quot;<br>messageTracing.class = &quot;com.test.Mock&quot;</pre><ul><li>Restart the APIM server together with Jaeger tracing.</li></ul><p>Now you can successfully trace API invocations without being disturbed by the Synapse handle amidst the flow.</p><p>Cheers!! 💥</p><p>[1] <a href="https://www.jaegertracing.io/download/">https://www.jaegertracing.io/download/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef8c4b595db4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>