Giter Site home page Giter Site logo

yonglehou / medidata.zipkintracermodule Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mdsol/medidata.zipkintracermodule

0.0 1.0 0.0 2.22 MB

Zipkin Request Tracing for .Net Apps

License: MIT License

C# 97.11% Thrift 2.77% Batchfile 0.12%

medidata.zipkintracermodule's Introduction

Medidata.ZipkinTracerModule

A .NET implementation of the Zipkin Tracer client.

Overview

This nuget package implements the zipkin tracer client for .net applications.

Medidata.ZipkinTracer.Core : core library for generating zipkin spans from ids sent through from CrossApplicationTracer and sending it to the zipkin collector using thrift protocol. For more information and implementations in other languages, please check Openzipkin.

Enable/Disable zipkin tracing

Zipkin will record traces if IsSampled HTTP header is true.
This will happen if :

  • a) the caller of the app has set the IsSampled HTTP header value to true.
  • OR
  • b) the url request is not in the ExcludedPathList of ZipkinConfig , and using the SampleRate, it will determine whether or not to trace this request. SampleRate is the approximate percentage of traces being recorded in zipkin.

Configurations

Please use ZipkinConig class to configure the module and verify these values and modify them according to your service/environment.

  • Enable - true: enable ZipkinMiddleware/ZipkinMessageHandler, false: disable ZipkinMiddleware/ZipkinMessageHandler.
  • ZipkinBaseUri - is the zipkin scribe/collector server URI with port to send the Spans
  • Domain - is a valid public facing base url for your app instance. Zipkin will use to label the trace.
  • SpanProcessorBatchSize - how many Spans should be sent to the zipkin scribe/collector in one go.
  • SampleRate - 1 decimal point float value between 0 and 1. This value will determine randomly if the current request will be traced or not.
  • NotToBeDisplayedDomainList(optional) - It will be used when logging host name by excluding these strings in service name attribute e.g. domain: ".xyz.com", host: "abc.xyz.com" will be logged as "abc" only
  • ExcludedPathList(optional) - Path list that is not needed for tracing. Each item must start with "/".
var config = new ZipkinConfig
{
	Enable = true,
	Domain = new Uri("https://yourservice.com"),
	ZipkinBaseUri = new Uri("http://zipkin.xyz.net:9411"),
	SpanProcessorBatchSize = 10,
	SampleRate = 0.5,
	NotToBeDisplayedDomainList = new[] { ".xyz.com", ".myApplication.net" },
	ExcludedPathList = new[] { "/check_uri", "/status" }
}

Tracing

Server trace (Inbound request)

Server Trace relies on OWIN Middleware. Please create OWIN Startup class then call UseZipkin().

using Medidata.ZipkinTracer.Core;
using Medidata.ZipkinTracer.Core.Middlewares;

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
		app.UseZipkin(new ZipkinConfig
		{
		    Enable = true,
		    Domain = new Uri("https://yourservice.com"),
			ZipkinBaseUri = new Uri("http://zipkin.xyz.net:9411"),
			SpanProcessorBatchSize = 10,
		    SampleRate = 0.5    
		};
    }
}

Client trace (Outbound request)

Client Trace relies on HttpMessageHandler for HttpClient. Please pass a ZipkinMessageHandler instance into HttpClient.

using Medidata.ZipkinTracer.Core.Handlers;

public class HomeController : AsyncController
{
	private ILog logger = LogManager.GetLogger("HomeController");

    public async Task<ActionResult> Index()
    {
        var context = System.Web.HttpContext.Current.GetOwinContext();
		var client = new ZipkinClient(logger, context);

        using (var httpClient = new HttpClient(new ZipkinMessageHandler(client))))
        {
            var response = await httpClient.GetAsync("http://www.google.com");
            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();
            }
        }

        return View();
    }
}

Recording arbitrary events and additional information

Additional annotations can be recorded by using the ZipkinClient's Record() and RecordBinary<T>() methods:

var zipkinClient = (ITracerClient)HttpContext.Current.Items["zipkinClient"];
var url = "https://abc.xyz.com:8000";
var requestUri = "/object/1";
HttpResponseMessage result;
using (var client = new HttpClient())
{
    client.BaseAddress = new Uri(url);

	// start client trace
    var span = tracerClient.StartClientTrace(new Uri(client.BaseAddress, requestUri), "GET");

    tracerClient.Record(span, "A description which will gets recorded with a timestamp.");

    result = await client.GetAsync(requestUri);

    // Record the total memory used after the call
    tracerClient.RecordBinary(span, "client.memory", GC.GetTotalMemory(false));

	// end client trace
    tracerClient.EndClientTrace(span);	
}
...

In case of the ZipkinClient.Record() method, the second parameter(value) can be omitted during the call, in that case the caller member name (method, property etc.) will get recorded.

Recording a local component

With the RecordLocalComponent() method of the client a local component (or information) can be recorded for the current trace. This will result an additional binary annotation with the 'lc' key (LOCAL_COMPONENT) and a custom value.

Contributors

ZipkinTracer is (c) Medidata Solutions Worldwide and owned by its major contributors:

medidata.zipkintracermodule's People

Contributors

tkwan-mdsol avatar kenyamat avatar bvillanueva-mdsol avatar lschreck-mdsol avatar edandersen avatar jcarres-mdsol avatar

Watchers

 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.