Skip to content

TracingInterceptorOptions

ndrwrbgs edited this page Jan 10, 2019 · 2 revisions

Func<object, string> FormatArgumentForTag

If non-null, this is called for each argument passed to the method (e.g. a and b on ISomething.Add above), and the result is set as a tag on the span for the method call. The key for the tag will be the parameter name.

Example

ISomething something = new FakeSomething().WrapInterfaceWithTracingAdapter<ISomething>(
  formatArgumentForTag: obj => "number " + obj,
  /* ... */);
something.Add(1, 2);

The span produced will be 'FakeSomething.Add' with tags { ["a"] = "number 1", ["b"] = "number 2" }

Func<object, string> FormatResultForTag

If non-null, this is called for the return value of the method, and the result is set as a tag on the span for the method call. The key for the tag will be result, until/unless the OpenTracing Semantic Conventions spec provides a standard for this.

Example

ISomething something = new FakeSomething().WrapInterfaceWithTracingAdapter<ISomething>(
  formatResultForTag: (Task<int> intTask) => "value: " + intTask.Result,
  /* ... */);
something.Add(1, 2);

The span produced will be 'FakeSomething.Add' with tag { ["result"] = "value: 3" }

bool WrapInterfaces

If this is true, and the return value for a method on the interface is also an interface, that return value will be wrapped with tracing as well.

Example 1

// Note that this example is for demonstrative purposes, as actually right now System.* namespaces are explicitly excluded from this, specifically because of this scenario here
IEnumerable sample = /* ... */;
IEnumerable tracedSample = sample.WrapInterfaceWithTracingAdapter<ISomething>(
  wrapInterfaces: true,
  /* ... */);

IEnumerator enumerator = tracedSample.GetEnumerator(); // Starts/Finishes an IEnumerable.GetEnumerator span
enumerator.MoveNext(); // Starts/Finishes an IEnumerator.MoveNext span

Example 2

Show the difference versus RecursivelyWrapInterfaces

interface ICount
{
  int Count { get; }
  ICount MePlusOne();
}

ICount sample = /* ... */;
IEnumerable tracedSample = sample.WrapInterfaceWithTracingAdapter<ICount>(
  wrapInterfaces: true,
  recursivelyWrapInterfaces: false,
  /* ... */);

tracedSample
  .MePlusOne() // Starts/Finishes an ICount.MePlusOne span
  .MePlusOne() // No tracing
  .MePlusOne();// No tracing

bool RecursivelyWrapInterfaces

Please see WrapInterfaces first.

This is akin to WrapInterfaces, except that instead of 1-level down it will wrap results for as long as methods are returning interfaces.

Example

interface ICount
{
  int Count { get; }
  ICount MePlusOne();
}

ICount sample = /* ... */;
IEnumerable tracedSample = sample.WrapInterfaceWithTracingAdapter<ICount>(
  wrapInterfaces: true,
  recursivelyWrapInterfaces: true,
  /* ... */);

tracedSample
  .MePlusOne() // Starts/Finishes an ICount.MePlusOne span
  .MePlusOne() // Starts/Finishes an ICount.MePlusOne span
  .MePlusOne();// Starts/Finishes an ICount.MePlusOne span

bool IncludeClassNames

If true, the concrete implementation's class name is prepended to the OperationName for the span. E.g. FakeSomething.Add. If false, only the method names are used for the OperationName. E.g. Add