Simple extensions on top of the OpenTracing APIs.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
nuget
src/Library
.gitignore
LICENSE
README.md

README.md

NuGet

OpenTracing-Extensions

Simple extensions on top of the OpenTracing APIs.

Notable pieces...

ISpanBuilder.WithTagsFromAnonymousType

This name is verbose, don't be surprised if it changes slightly :)

Allows setting tags from an anonymous type. E.g. setting arguments from a method easily.

Before and After

void MyMethod(string a, int b, ulong c, bool d)
{
  using (GlobalTracer.Instance
    .BuildSpan("operationName")
-   .WithTag(nameof(a), a)
-   .WithTag(nameof(b), b)
-   .WithTag(nameof(c), c)
-   .WithTag(nameof(d), d)
+   // Automatically captures the parameter names due to how anonymous types work :-)
+   .WithTagsFromAnonymousType(new { a, b, c, d })
    .StartActive())
  {
  }
}

ISpan.LogMemberInfo

And its related ISpan.LogWithMemberInfo and ISpanBuilder.WithCallerMemberNameTag

I'm not sure LogMemberInfo is actually useful aside from the other two methods, it might be removed

Log the member name (and even line number) easily.

Before and After

void MyMethod()
{
  using (var scope = GlobalTracer.Instance
    .BuildSpan("operationName")
-    // Hopefully doesn't get refactored to another method :-S
-    .SetTag("fromMethod", nameof(MyMethod))
+    .WithCallerMemberNameTag(tagName: "fromMethod")
    .StartActive())
  {
    scope.Span
-      .Log(
+      .LogWithMemberInfo(
        // [nit] - Dictionary is not as efficient as an Array of KeyValuePair's, but it is a nicer syntax :)
        fields: new Dictionary<string, object>(3)
        {
-         ["memberName"] = nameof(MyMethod),
-         ["memberLineNumber"] = /* This actually isn't possible */,
          ["someKey"] = true
        });
  }
}

ISpan.Log(string key, object value)

And its related overloads

Allows logging a single KeyValuePair to the ISpan, without having the noise of initializing an array in your log code.

Before and After

ISpan span;
-span.Log(
-  new []
-  {
-    new KeyValuePair<string, object>("myField", "myValue"),
-  });
+span.Log("myField", "myValue");