Browse Source

add tracingheader helper func

master
Savorboard 6 years ago
parent
commit
9d0a453a0c
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      src/DotNetCore.CAP/Infrastructure/Helper.cs

+ 18
- 1
src/DotNetCore.CAP/Infrastructure/Helper.cs View File

@@ -4,6 +4,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using DotNetCore.CAP.Diagnostics;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;


@@ -48,7 +49,7 @@ namespace DotNetCore.CAP.Infrastructure
public static long ToTimestamp(DateTime value) public static long ToTimestamp(DateTime value)
{ {
var elapsedTime = value - Epoch; var elapsedTime = value - Epoch;
return (long) elapsedTime.TotalSeconds;
return (long)elapsedTime.TotalSeconds;
} }




@@ -90,6 +91,12 @@ namespace DotNetCore.CAP.Infrastructure
return AddJsonProperty(json, "ExceptionMessage", jObject); return AddJsonProperty(json, "ExceptionMessage", jObject);
} }


public static string AddTracingHeaderProperty(string json, TracingHeaders headers)
{
var jObject = ToJObject(headers);
return AddJsonProperty(json, "TracingHeaders", jObject);
}

public static bool IsInnerIP(string ipAddress) public static bool IsInnerIP(string ipAddress)
{ {
bool isInnerIp; bool isInnerIp;
@@ -156,6 +163,16 @@ namespace DotNetCore.CAP.Infrastructure
}); });
} }


private static JObject ToJObject(TracingHeaders headers)
{
var jobj = new JObject();
foreach (var keyValuePair in headers)
{
jobj[keyValuePair.Key] = keyValuePair.Value;
}
return jobj;
}

private static string AddJsonProperty(string json, string propertyName, JObject propertyValue) private static string AddJsonProperty(string json, string propertyName, JObject propertyValue)
{ {
var jObj = JObject.Parse(json); var jObj = JObject.Parse(json);


Loading…
Cancel
Save