GithubHelp home page GithubHelp logo

distributed-tracing-app-loganalytics's Introduction

Distributed tracing Using Functions and Log Analytics

This document represents a proof of concept. All the "packages" transit needs to be traceable. A producer generates data that is stored in a storage account. The storage account has a queue container. The queue container triggers a function that pushes the content to API Management. The API Management then posts the data to a backend Rest API server and writes the operations logs to an Azure Event Hubs. A function is triggered by the Azure Event Hubs' event and posts the log data to Azure Log Analytics as a custom log. From Azure Log Analytics, it is possible to query the traces, using Kusto Query Language.

Requirements:

  • The message posted to the Rest API needs to be easily traceble end to end.
  • The architecture must be cost-effective
  • The achitecture needs to scale fast if needed

simple_view

Function to process Queue

The Function consumes queue data adds a custom currelation ID and then posts to Azure API Management.

https://github.com/thiagofborn/queueTriggerToSendPost

Function to read from Azure Event Hubs

The Function reads from Azure Event Hubs and sends the information formated to a specific Azure Log Analytics's workspace customized.

https://github.com/thiagofborn/eventHubsTriggerLogAnalytics

The Azure API Management custom Policy

The "REST_API_BACKEND", is runnimg on Azure as Web APP.

<policies>
    <inbound>
        <set-variable name="message-id" value="@(Guid.NewGuid())" />
        <set-backend-service base-url="https://REST_API_BACKEND.azurewebsites.net" />
    </inbound>
    <backend>
        <forward-request follow-redirects="true" />
    </backend>
    <outbound>
        <log-to-eventhub logger-id="apimcustomlogseh">@{
          var statusLine = string.Format("HTTP/1.1 {0} {1}\r\n",
                                              context.Response.StatusCode,
                                              context.Response.StatusReason);

          var body = context.Response.Body?.As<string>(true);
          if (body != null && body.Length > 1024)
          {
              body = body.Substring(0, 1024);
          }

          var headers = context.Request.Headers
                               .Where(h => h.Key == "CustomCorrelationId")
                               .Select(h => string.Format("{0}: {1}", h.Key, String.Join(", ", h.Value)));

          var CustcurrelantionId = (headers.Any()) ? string.Join(string.Empty, headers) : string.Empty;

          return string.Join(",", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name, CustcurrelantionId);
     }</log-to-eventhub>
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Backend Server Rest API

To keep simple, I used an Azure Web APP written in .Net Core to run a Rest API application. To be convenient during the Azure API Management integration, I used OpenAPI definitions on the application.

https://github.com/thiagofborn/restapimocktests

Query the CustomCurrelationId on Azure Log Analytics

Via Azure portal go to the workspace created for the custom log, then use the query UI interface.

tracing_CL

distributed-tracing-app-loganalytics's People

Contributors

thborn avatar thiagofborn avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.