Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sample trace within a single Connexion system:

...

Accessing and Setting Trace Information

Trace information can be inspected and appended to in your custom devices (or the custom code device) and is accessible on the IMessageContext object.

Code Block
languagejava
// * Warning: Contrived example
using System;
using System.Threading;
using Connexion.Core;
using System.Threading.Tasks;

namespace Connexion.Device
{
  public partial class CustomDevice : BaseCustomDevice
  {	
	public override async Task ProcessMessageAsync(IMessageContext context, CancellationToken token)
    {
      // the trace information is exposed via the context.MessageExtension property
      foreach(var trace in context.MessageExtension.GetMessageTrace())
      {
        // the trace object has a Uri property and Utc property
        Console.WriteLine($"Uri: {trace.Uri}, Utc Stamp {trace.Utc}");
      }
      
      // add your own trace information
      if(Uri.TryCreate("cxn://mydevice/operation", UriKind.RelativeOrAbsolute, out var uri))
        context.MessageExtension.AddTrace(uri);
      
      // if you are sending to an external resource, use the following overload to signify
      // an outbound external endpoint
      if(Uri.TryCreate("myservice://ingestionPath/", UriKind.RelativeOrAbsolute, out var uriOutbound))
        context.MessageExtension.AddTrace(uriOutbound, TraceInfoFlag.Out);
    } 
  }
}