Git Product home page Git Product logo

medidata.zipkintracermodule's Introduction

Deprecated

This project is deprecated and no longer being maintained. Please use zipkin4net or other alternatives.

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 HTTP as the transport 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 ZipkinConfig class to configure the module and verify these values and modify them according to your service/environment.

  • Bypass - Controls whether the requests should be sent through the Zipkin module
    • false: Enables the ZipkinMiddleware/ZipkinMessageHandler
    • true: Disables the 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.
    • by default this looks at the incoming requests and uses the hostname from them. It's a Func<IOwinRequest, Uri> - customise this to your requirements.
  • 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 "/".
  • Create128BitTraceId - Create new traces using 128 bit (32 hex character) traceId
var config = new ZipkinConfig
{
	Bypass = request => request.Uri.AbsolutePath.StartsWith("/allowed"),
	Domain = request => new Uri("https://yourservice.com"), // or, you might like to derive a value from the request, like r => new Uri($"{r.Scheme}{Uri.SchemeDelimiter}{r.Host}"),
	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
		{
		    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.

Note: You will need the GetOwinContext extension method. If you host in IIS with System.Web, this can be found in Microsoft.Owin.Host.SystemWeb.

using Medidata.ZipkinTracer.Core.Handlers;

public class HomeController : AsyncController
{
    public async Task<ActionResult> Index()
    {
        var context = System.Web.HttpContext.Current.GetOwinContext();
		var config = new ZipkinConfig // you can use Dependency Injection to get the same config across your app.
		{
		    Domain = new Uri("https://yourservice.com"),
		    ZipkinBaseUri = new Uri("http://zipkin.xyz.net:9411"),
		    SpanProcessorBatchSize = 10,
		    SampleRate = 0.5    
		}
		var client = new ZipkinClient(config, 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

NOTE:This can only be used if you are NOT using ZipkinMessageHandler as described above "Client trace (Outbound request)". RecordBinary<T() needs to be called before EndClientTrace() is invoked.

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

var context = System.Web.HttpContext.Current.GetOwinContext();
var config = new ZipkinConfig // you can use Dependency Injection to get the same config across your app.
{
	Domain = new Uri("https://yourservice.com"),
	ZipkinBaseUri = new Uri("http://zipkin.xyz.net:9411"),
	SpanProcessorBatchSize = 10,
	SampleRate = 0.5    
}
var zipkinClient = new ZipkinClient(config, context);
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 = zipkinClient.StartClientTrace(new Uri(client.BaseAddress, requestUri), "GET");

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

    result = await client.GetAsync(requestUri);

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

	// end client trace
    zipkinClient.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.

Troubleshooting

Logs

Logging internal to the library is provided via the LibLog abstraction. Caveat: to get logs, you must have initialised your logging framework on application-start (console app example - a web-app might do this in OWIN Startup or Global.asax, or the inversion of control container initialisation).

Contributors

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

medidata.zipkintracermodule's People

Contributors

bvillanueva-mdsol avatar cabbott avatar edandersen avatar hakanson avatar jcarres-mdsol avatar kenyamat avatar klettier avatar lschreck-mdsol avatar petemounce avatar tkwan-mdsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

medidata.zipkintracermodule's Issues

gRPC support

Can I use the library to trace the gRPC microservices interaction ?

Separate nuget packages for Core logic and Middleware/s

This library needs to separate nuget packages for Core logic and Middleware/s to easily adapt to platforms and framework.

  • create a core nuget package
  • create a nuget package for owin middleware framework
  • create a nuget package for asp net 4 framework (ex. http module)
  • core nuget package should be compatible with dot net core (include dot net core middleware capability)

constructor parameters for ZipkinClient?

From the README.md, it looks like just IOwinContext

var client = new ZipkinClient(context);

but Medidata.ZipkinTracer.Core (v3.0.0) from NuGet (as of 26 July 2016), it takes 3 required and 1 optional parameters

public ZipkinClient(ILog logger, IZipkinConfig zipkinConfig, IOwinContext context, SpanCollector collector = null);

and ZipkinClient.cs takes 2 required and 1 optional parameters

public ZipkinClient(IZipkinConfig zipkinConfig, IOwinContext context, SpanCollector collector = null)

Assuming the current source is correct, it looks like both the README and NuGet need to be updated.

No Build/Package scripts

Hi guys,

Thanks for a useful project. I normally create scripts for build and package (see my github projects) and I am happy to do the same for you if happy.

I did not just create a PR, I do not like receiving just a PR without creating issue for my projects :)

Don't break on 128bit X-B3-TraceId by tossing high bits

Problem

The first step of transitioning to 128bit X-B3-TraceId is tolerantly reading 32 character long ids. Until a change is made, those propagating 128bit ids to Medidata.ZipkinTracerModule will have their traces restarted due to a parse failure.

Medidata.ZipkinTracerModule is one of the last libraries that need an update.

Proposal

Change the TraceProvider.parse to leniently parse an unsigned 64bit long from a lower-hex string. This could address 128bit (32 character) ids by throwing away the high bits (any characters left of 16 characters)

Test

When a 128bit id like X-B3-TraceId: 463ac35c9f6413ad48485a3953bb6124 is received, the lower 64 bits (right most 16 characters ex48485a3953bb6124) will become the trace id as opposed to having the trace restarted.

See also

twitter/finagle#553
openzipkin/brave#239

The example program should be updated

The current example uses methods of Zipkinclient, TraceProvider classes like StartServerTrace.
As discussed with Brent - "We can only use tracing for inbound calls using the OWIN middlewares and outbound calls using http client message handlers. Please don't use ZipkinClient methods directly."

Update to record timestamp and duration authoratively

Recent versions of zipkin have a duration query that only works when timestamp and duration are set authoritatively. This implies adding the fields to the Span type when reporting to zipkin. These should be set when originating a new span (ex. all root and client spans, but not set on spans continued via B3 headers).

This was noticed by @prbarl who found duration query not working in cassandra for this reason

See openzipkin/openzipkin.github.io#49 for more details.

IPv6 support

We currently support logging of only IPv4 addresses. Starting with Zipkin 1.4 endpoints can omit IPv4 (by setting Endpoint.ipv4 to 0), and optionally log Endpoint.ipv6 as the raw 16byte address.
https://github.com/openzipkin/zipkin-api/blob/master/thrift/zipkinCore.thrift#L276

In json, both are the string formatting http://zipkin.io/zipkin-api

ipv4:
string
The text representation of a IPv4 address associated with this endpoint. Ex. 192.168.99.100
ipv6:
string
The text representation of a IPv6 address associated with this endpoint. Ex. 2001:db8::c001

implement "b3 single" header format

Let's support at least reading "b3" header from a single string, most commonly traceid-spanid-1
It would also be nice to support optionally writing this, especially in message providers or others with constrained environments.

Expected behavior

As discussed on openzipkin/b3-propagation#21 and first implemented here: https://github.com/openzipkin/brave/blob/master/brave/src/main/java/brave/propagation/B3SingleFormat.java https://github.com/openzipkin/brave/blob/master/brave/src/test/java/brave/propagation/B3SingleFormatTest.java we should be able to parse "b3" and ideally also write it depending on config.

Actual behavior

right now, we read the historical "X-B3-" headers, which we should still support. However, if we see a header named "b3" we should read that instead.

Steps to reproduce the behavior

Turn on tracing and see if b3=80f198ee56343ba864fe8b2a57d3eff7-05e3ac9a4f6e3b90-1-e457b5a2e4d86bd1 results in the same context as:

X-B3-TraceId: 80f198ee56343ba864fe8b2a57d3eff7
X-B3-ParentSpanId: 05e3ac9a4f6e3b90
X-B3-SpanId: e457b5a2e4d86bd1
X-B3-Sampled: 1

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.