Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- [Log4Net includes Message for ExceptionTelemetry](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1315)
- [NLog includes Message for ExceptionTelemetry](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1315)

## Version 2.12.0-beta4
- [Fix depednency tracking for Microsoft.Azure.EventHubs SDK 4.1.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1317)

## Version 2.12.0-beta3
- [Standard Metric extractor for Dependency) add Dependency.ResultCode dimension.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1233)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,126 @@ public void EventHubsSuccessfulSendIsHandled()
}
}

[TestMethod]
public void EventHubsSuccessfulReceiveIsHandled()
{
using (var listener = new DiagnosticListener("Microsoft.Azure.EventHubs"))
using (var module = new DependencyTrackingTelemetryModule())
{
module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.EventHubs");
module.Initialize(this.configuration);

Activity sendActivity = null;
Activity parentActivity = new Activity("parent").AddBaggage("k1", "v1").Start();
parentActivity.TraceStateString = "state=some";
var telemetry = this.TrackOperation<DependencyTelemetry>(
listener,
"Microsoft.Azure.EventHubs.Receive",
TaskStatus.RanToCompletion,
null,
() => sendActivity = Activity.Current);

Assert.IsNotNull(telemetry);
Assert.AreEqual("Receive", telemetry.Name);
Assert.AreEqual(RemoteDependencyConstants.AzureEventHubs, telemetry.Type);
Assert.AreEqual("sb://eventhubname.servicebus.windows.net/ | ehname", telemetry.Target);
Assert.IsTrue(telemetry.Success.Value);

Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.ParentSpanId.ToHexString()}.", telemetry.Context.Operation.ParentId);
Assert.AreEqual(sendActivity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.SpanId.ToHexString()}.", telemetry.Id);

Assert.AreEqual("v1", telemetry.Properties["k1"]);
Assert.AreEqual("eventhubname.servicebus.windows.net", telemetry.Properties["peer.hostname"]);
Assert.AreEqual("ehname", telemetry.Properties["eh.event_hub_name"]);
Assert.AreEqual("SomePartitionKeyHere", telemetry.Properties["eh.partition_key"]);
Assert.AreEqual("EventHubClient1(ehname)", telemetry.Properties["eh.client_id"]);

Assert.IsTrue(telemetry.Properties.TryGetValue("tracestate", out var tracestate));
Assert.AreEqual("state=some", tracestate);
}
}

[TestMethod]
public void EventHubsSuccessfulReceiveShortNameIsHandled()
{
using (var listener = new DiagnosticListener("Microsoft.Azure.EventHubs"))
using (var module = new DependencyTrackingTelemetryModule())
{
module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.EventHubs");
module.Initialize(this.configuration);

Activity sendActivity = null;
Activity parentActivity = new Activity("parent").AddBaggage("k1", "v1").Start();
parentActivity.TraceStateString = "state=some";
var telemetry = this.TrackOperation<DependencyTelemetry>(
listener,
"Receive",
TaskStatus.RanToCompletion,
null,
() => sendActivity = Activity.Current);

Assert.IsNotNull(telemetry);
Assert.AreEqual("Receive", telemetry.Name);
Assert.AreEqual(RemoteDependencyConstants.AzureEventHubs, telemetry.Type);
Assert.AreEqual("sb://eventhubname.servicebus.windows.net/ | ehname", telemetry.Target);
Assert.IsTrue(telemetry.Success.Value);

Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.ParentSpanId.ToHexString()}.", telemetry.Context.Operation.ParentId);
Assert.AreEqual(sendActivity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.SpanId.ToHexString()}.", telemetry.Id);

Assert.AreEqual("v1", telemetry.Properties["k1"]);
Assert.AreEqual("eventhubname.servicebus.windows.net", telemetry.Properties["peer.hostname"]);
Assert.AreEqual("ehname", telemetry.Properties["eh.event_hub_name"]);
Assert.AreEqual("SomePartitionKeyHere", telemetry.Properties["eh.partition_key"]);
Assert.AreEqual("EventHubClient1(ehname)", telemetry.Properties["eh.client_id"]);

Assert.IsTrue(telemetry.Properties.TryGetValue("tracestate", out var tracestate));
Assert.AreEqual("state=some", tracestate);
}
}

[TestMethod]
public void EventHubsSuccessfulSendShortNameIsHandled()
{
using (var listener = new DiagnosticListener("Microsoft.Azure.EventHubs"))
using (var module = new DependencyTrackingTelemetryModule())
{
module.IncludeDiagnosticSourceActivities.Add("Microsoft.Azure.EventHubs");
module.Initialize(this.configuration);

Activity sendActivity = null;
Activity parentActivity = new Activity("parent").AddBaggage("k1", "v1").Start();
parentActivity.TraceStateString = "state=some";
var telemetry = this.TrackOperation<DependencyTelemetry>(
listener,
"Send",
TaskStatus.RanToCompletion,
null,
() => sendActivity = Activity.Current);

Assert.IsNotNull(telemetry);
Assert.AreEqual("Send", telemetry.Name);
Assert.AreEqual(RemoteDependencyConstants.AzureEventHubs, telemetry.Type);
Assert.AreEqual("sb://eventhubname.servicebus.windows.net/ | ehname", telemetry.Target);
Assert.IsTrue(telemetry.Success.Value);

Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.ParentSpanId.ToHexString()}.", telemetry.Context.Operation.ParentId);
Assert.AreEqual(sendActivity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
Assert.AreEqual($"|{sendActivity.TraceId.ToHexString()}.{sendActivity.SpanId.ToHexString()}.", telemetry.Id);

Assert.AreEqual("v1", telemetry.Properties["k1"]);
Assert.AreEqual("eventhubname.servicebus.windows.net", telemetry.Properties["peer.hostname"]);
Assert.AreEqual("ehname", telemetry.Properties["eh.event_hub_name"]);
Assert.AreEqual("SomePartitionKeyHere", telemetry.Properties["eh.partition_key"]);
Assert.AreEqual("EventHubClient1(ehname)", telemetry.Properties["eh.client_id"]);

Assert.IsTrue(telemetry.Properties.TryGetValue("tracestate", out var tracestate));
Assert.AreEqual("state=some", tracestate);
}
}

[TestMethod]
public void EventHubsSuccessfulSendIsHandledW3COff()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
{
case "Microsoft.Azure.EventHubs.Send.Start":
case "Microsoft.Azure.EventHubs.Receive.Start":
case "Send.Start":
case "Receive.Start":
break;
case "Microsoft.Azure.EventHubs.Send.Stop":
case "Microsoft.Azure.EventHubs.Receive.Stop":
case "Send.Stop":
case "Receive.Stop":
this.OnDependency(evnt.Key, evnt.Value, currentActivity);
break;
}
Expand Down