using Newtonsoft.Json.Linq;
private static HttpClient httpClient = new HttpClient();
private static UriBuilder uriBuilder = new UriBuilder();
public static async void Main()
JArray jsonArray = new JArray();
JObject container = new JObject();
JObject jCommon = new JObject();
JObject jAttributes = new JObject();
JProperty jServiceName = new JProperty("service.name", "Test Service A");
JProperty jOperationName = new JProperty("host", "host123.test.com");
jAttributes.Add(jServiceName);
jAttributes.Add(jOperationName);
jCommon.Add(new JProperty("attributes", jAttributes));
JArray jSpans = new JArray();
JObject jSpan = new JObject();
JProperty jTraceId = new JProperty("trace.id", "12345");
JProperty jId = new JProperty("id", "ABC");
JObject jAttributesSpan = new JObject();
JProperty jParentId = new JProperty("parent.id", "34578");
jAttributesSpan.Add(jParentId);
JProperty jName = new JProperty("name", "Get BalanceandMovements (GET)");
jAttributesSpan.Add(jName);
JProperty jDurationMs = new JProperty("duration.ms", 12.53);
jAttributesSpan.Add(jDurationMs);
jSpan.Add(new JProperty("attributes", jAttributesSpan));
container.Add(new JProperty("common", jCommon));
container.Add(new JProperty("spans", jSpans));
jsonArray.Add(container);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://trace-api.newrelic.com/trace/v1");
client.DefaultRequestHeaders.Add("Api-Key", "NRII-LKj0ijWK93wEv9RdqnZXbhHukCG8k7rC");
client.DefaultRequestHeaders.Add("Data-Format", "newrelic");
client.DefaultRequestHeaders.Add("Data-Format-Version", "1");
var s = JsonConvert.ToString(jsonArray.ToString().Replace("\n", string.Empty));
Console.WriteLine("json arrray: " + s);
System.Net.Http.StringContent stringContent = new System.Net.Http.StringContent(s);
Console.WriteLine("json arrray: " + stringContent.ReadAsStringAsync().Result);
using (HttpResponseMessage response = client.PostAsync("", stringContent).Result)
using (var content = response)
Console.WriteLine(content);