Skip to content

Commit

Permalink
Remove Microsoft.Diagnostics.Correlation dependency
Browse files Browse the repository at this point in the history
This is just a temporary measure for 1.0.0 release--Correlation lib is still in preview. Once Correlation is out of preview, we will have another release with integrated correlation support.
  • Loading branch information
karolz-ms committed Jan 11, 2017
1 parent 69cf148 commit 14c31cf
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Diagnostics.Correlation.Common;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
Expand All @@ -19,12 +18,6 @@ public class CorrelationTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
//add request id to every event
var ctx = ContextResolver.GetRequestContext<MyContext>();
if (ctx != null)
{
telemetry.Context.Operation.Id = ctx.CorrelationId;
}
}
}

Expand Down Expand Up @@ -60,11 +53,6 @@ static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
ContextResolver.SetRequestContext(new MyContext
{
CorrelationId = Guid.NewGuid().ToString(),
OtherId = i.ToString()
});
Trace.TraceWarning($"{DateTime.UtcNow:o} this is log message");
}
Task.Delay(10000).Wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"dependencies": {
"Microsoft.ApplicationInsights": "2.1.0",
"Microsoft.Diagnostics.Correlation.Common": "1.0.0-preview1",
"Microsoft.Diagnostics.EventFlow.Core": "1.0.0-*",
"Microsoft.Diagnostics.EventFlow.Inputs.Trace": "1.0.0-*",
"Microsoft.Diagnostics.EventFlow.Outputs.ApplicationInsights": "1.0.0-*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using System;
using System.Collections.Generic;
using Microsoft.Diagnostics.Correlation.Common;
using Microsoft.Diagnostics.EventFlow.Configuration;
using Microsoft.Diagnostics.EventFlow.Inputs;
using Microsoft.Diagnostics.EventFlow.Filters;
Expand Down Expand Up @@ -78,7 +77,6 @@ static void Main(string[] args)
name = "ImportantEvent";
}

ContextResolver.SetRequestContext(new {correlationId = eventSequenceNo});
BenchmarkEventSource.Log.ComplexMessage(
Guid.NewGuid(),
Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Diagnostics.Correlation.Common" version="1.0.0-preview1" targetFramework="net46" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0" targetFramework="net46" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0" targetFramework="net46" />
<package id="System.Linq" version="4.1.0" targetFramework="net46" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Text;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using Microsoft.Diagnostics.Correlation.Common;

namespace Microsoft.Diagnostics.EventFlow.Inputs
{
Expand All @@ -33,12 +32,6 @@ public static EventData ToEventData(this EventWrittenEventArgs eventSourceEvent,
eventData.AddPayloadProperty("EventId", eventSourceEvent.EventId, healthReporter, context);
eventData.AddPayloadProperty("EventName", eventSourceEvent.EventName, healthReporter, context);
eventData.AddPayloadProperty("ActivityID", ActivityPathString(eventSourceEvent.ActivityId), healthReporter, context);
var eventContext = ContextResolver.GetRequestContext<object>();
if (eventContext != null)
{
eventData.AddPayloadProperty("EventContext", eventContext, healthReporter, context);
}

try
{
if (eventSourceEvent.Message != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version": "1.0.0-*",

"dependencies": {
"Microsoft.Diagnostics.Correlation.Common": "1.0.0-preview1",
"dependencies": {
"Microsoft.Diagnostics.EventFlow.Core": { "target": "project" },
"NETStandard.Library": "1.6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Globalization;
using System.Text;
using Microsoft.Diagnostics.Correlation.Common;
using Microsoft.Extensions.Configuration;
using Microsoft.Diagnostics.EventFlow.Configuration;

Expand Down Expand Up @@ -215,12 +214,6 @@ private void SubmitEventData(string message, TraceEventType level, int? id = nul
eventPayload["RelatedActivityID"] = relatedActivityId;
}

var eventContext = ContextResolver.GetRequestContext<object>();
if (eventContext != null)
{
eventPayload["EventContext"] = eventContext;
}

this.subject.OnNext(eventEntry);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"dependencies": {
"Microsoft.Diagnostics.EventFlow.Core": {
"target": "project"
},
"Microsoft.Diagnostics.Correlation.Common" : "1.0.0-preview1"
}
},

"frameworks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.Diagnostics.Correlation.Common;
using Microsoft.Diagnostics.EventFlow.Configuration;
using Microsoft.Diagnostics.EventFlow.Metadata;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -67,13 +66,6 @@ public Task SendEventsAsync(IReadOnlyCollection<EventData> events, long transmis
{
foreach (var e in events)
{
//restore event context so ApplicationInsights TelemetryInitializer could access it
object eventContext;
if (e.TryGetPropertyValue("EventContext", out eventContext))
{
ContextResolver.SetRequestContext(eventContext);
}

if (cancellationToken.IsCancellationRequested)
{
return CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"dependencies": {
"Microsoft.ApplicationInsights": "2.1.0",
"Microsoft.Diagnostics.Correlation.Common": "1.0.0-preview1",
"Microsoft.Diagnostics.EventFlow.Core": { "target": "project" },
"NETStandard.Library": "1.6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Microsoft.Diagnostics.Correlation.Common;
using Microsoft.Diagnostics.EventFlow.Configuration;
using Microsoft.Extensions.Configuration;
using Moq;
Expand Down Expand Up @@ -89,25 +88,6 @@ public void TraceShouldSubmitTheData()
}
}

[Fact]
public void TraceShouldSubmitTheDataWithContext()
{
IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary<string, string>()
{
["type"] = "Trace",
["traceLevel"] = "All"
}).Build();
var healthReporterMock = new Mock<IHealthReporter>();
var subject = new Mock<IObserver<EventData>>();
using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
using (target.Subscribe(subject.Object))
{
ContextResolver.SetRequestContext(new MyContext("123"));
Trace.TraceInformation("Message for unit test");
subject.Verify(s => s.OnNext(It.Is<EventData>(data => checkContext(data, "123"))), Times.Exactly(1));
}
}

[Fact]
public void TraceShouldNotSubmitFilteredData()
{
Expand Down

0 comments on commit 14c31cf

Please sign in to comment.