Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OperationDetails object bag to DependencyTelemtry for Initializers #788

Merged
merged 20 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
59c6d9e
Ignore vswhere folder
michaelwstark Apr 9, 2018
54e72fc
Add OperationDetails to Dependency Data
michaelwstark Apr 9, 2018
6981764
Add OperationDetails to Dependency Data
michaelwstark Apr 9, 2018
0252be7
Merge branch 'develop' of https://github.com/michaelwstark/Applicatio…
michaelwstark Apr 26, 2018
1d4d1c0
Merge branch 'develop' of https://github.com/Microsoft/ApplicationIns…
michaelwstark Apr 26, 2018
d742c76
Fix DependencyTelemetry DeepClone
michaelwstark Apr 26, 2018
7325e87
Merge remote-tracking branch 'upstream/master' into develop
michaelwstark Apr 27, 2018
cf9da47
Replace OperationDetail Property with Public Getter and Hidden Setter
michaelwstark Apr 27, 2018
dae9c1b
Update changelog.
michaelwstark Apr 27, 2018
e4d343f
Avoid initializing dictionary on TryGetOperationDetail
michaelwstark Apr 27, 2018
25ae08e
Switch Lazy<T> to LazyInitializer pattern for OperationDetails
michaelwstark Apr 27, 2018
2328d86
Specifically state that data contained within the operation detail fi…
michaelwstark Apr 27, 2018
4c462be
Merge remote-tracking branch 'upstream/develop' into develop
May 1, 2018
15568c7
Fix indenting change.
May 1, 2018
9ef7ac4
Merge remote-tracking branch 'upstream/develop' into develop
michaelwstark May 1, 2018
4458457
Clear OperationDetails After Track() Call
michaelwstark May 1, 2018
e54e779
Align Formatting in CHANGELOG.md
michaelwstark May 1, 2018
6f49a23
Update CHANGELOG.md with consolidated issue reference
michaelwstark May 2, 2018
c2294c3
Merge remote-tracking branch 'upstream/develop' into develop
michaelwstark May 2, 2018
e4d6237
Merge branch 'develop' into develop
TimothyMothra May 8, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ AppPackages/

# Others
sql/
[Vv]swhere/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

This changelog will be used to generate documentation on [release notes page](http://azure.microsoft.com/en-us/documentation/articles/app-insights-release-notes-dotnet/).

## Version 2.6.0
- [Fix: changed namespace SamplingPercentageEstimatorSettings](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/727)
- [Extend the Beta period for Metrics Pre-Aggregation features shipped in 2.6.0-beta3.](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/785)
## Version 2.7.0-beta1
- [New: Added TryGetOperationDetail to DependencyTelemetry to facilitate advanced ITelemetryInitializer scenarios. Allows ITelemetryInitializer implementations to specify fields that would otherwise not be sent automatically to the backend.] (https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/900)


## Version 2.6.0
- [Fix: changed namespace SamplingPercentageEstimatorSettings](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/727)
- [Extend the Beta period for Metrics Pre-Aggregation features shipped in 2.6.0-beta3.](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/785)

## Version 2.6.0-beta4
- [New: Enable ExceptionTelemetry.SetParsedStack for .Net Standard](https://github.com/Microsoft/ApplicationInsights-dotnet/issues/763)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.TryGetOperationDetail(string key, out object detail) -> bool
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.SetOperationDetail(string key, object detail) -> void
Microsoft.ApplicationInsights.DataContracts.PageViewTelemetry.Id.get -> string
Microsoft.ApplicationInsights.DataContracts.PageViewTelemetry.Id.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ApplicationIdProvider.get -> Microsoft.ApplicationInsights.Extensibility.IApplicationIdProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.TryGetOperationDetail(string key, out object detail) -> bool
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.SetOperationDetail(string key, object detail) -> void
Microsoft.ApplicationInsights.DataContracts.PageViewTelemetry.Id.get -> string
Microsoft.ApplicationInsights.DataContracts.PageViewTelemetry.Id.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ApplicationIdProvider.get -> Microsoft.ApplicationInsights.Extensibility.IApplicationIdProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.TryGetOperationDetail(string key, out object detail) -> bool
Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry.SetOperationDetail(string key, object detail) -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ApplicationIdProvider.get -> Microsoft.ApplicationInsights.Extensibility.IApplicationIdProvider
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ApplicationIdProvider.set -> void
Microsoft.ApplicationInsights.Extensibility.IApplicationIdProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ public void DependencyTelemetryHasCorrectValueOfSamplingPercentageAfterSerializa
Assert.AreEqual(10, item.sampleRate);
}

[TestMethod]
public void DependencyTelemetrySetGetOperationDetail()
{
const string key = "foo";
const string detail = "bar";

var telemetry = this.CreateRemoteDependencyTelemetry("mycommand");
telemetry.SetOperationDetail(key, detail);
Assert.IsTrue(telemetry.TryGetOperationDetail(key, out object retrievedValue));
Assert.IsNotNull(retrievedValue);
Assert.AreEqual(detail, retrievedValue.ToString());

// Clear and verify the detail is no longer present
telemetry.ClearOperationDetails();
Assert.IsFalse(telemetry.TryGetOperationDetail(key, out retrievedValue));
}

[TestMethod]
public void DependencyTelemetryGetUnsetOperationDetail()
{
const string key = "foo";

var telemetry = this.CreateRemoteDependencyTelemetry("mycommand");
Assert.IsFalse(telemetry.TryGetOperationDetail(key, out object retrievedValue));
Assert.IsNull(retrievedValue);

// should not throw
telemetry.ClearOperationDetails();
}

#if !NETCOREAPP1_1
[TestMethod]
public void DependencyTelemetryDeepCloneCopiesAllProperties()
Expand All @@ -185,7 +215,7 @@ public void DependencyTelemetryDeepCloneCopiesAllProperties()
private DependencyTelemetry CreateRemoteDependencyTelemetry()
{
DependencyTelemetry item = new DependencyTelemetry
{
{
Timestamp = DateTimeOffset.Now,
Sequence = "4:2",
Name = "MyWebServer.cloudapp.net",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace Microsoft.ApplicationInsights.DataContracts
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.Extensibility.Implementation.External;

using static System.Threading.LazyInitializer;

/// <summary>
/// The class that represents information about the collected dependency.
/// <a href="https://go.microsoft.com/fwlink/?linkid=839889">Learn more.</a>
Expand All @@ -19,6 +23,7 @@ public sealed class DependencyTelemetry : OperationTelemetry, ITelemetry, ISuppo

internal readonly RemoteDependencyData InternalData;
private readonly TelemetryContext context;
private IDictionary<string, object> operationDetails;

private double? samplingPercentage;

Expand Down Expand Up @@ -93,6 +98,12 @@ private DependencyTelemetry(DependencyTelemetry source)
this.Timestamp = source.Timestamp;
this.samplingPercentage = source.samplingPercentage;
this.successFieldSet = source.successFieldSet;

// Only clone the details if the source has had details initialized
if (source.operationDetails != null)
{
this.operationDetails = new ConcurrentDictionary<string, object>(source.operationDetails);
}
}

/// <summary>
Expand Down Expand Up @@ -272,6 +283,11 @@ public string DependencyKind
set { this.samplingPercentage = value; }
}

/// <summary>
/// Gets the dependency operation details, if any.
/// </summary>
private IDictionary<string, object> OperationDetails => EnsureInitialized(ref this.operationDetails, () => new ConcurrentDictionary<string, object>());

/// <summary>
/// Deeply clones a <see cref="DependencyTelemetry"/> object.
/// </summary>
Expand All @@ -281,6 +297,38 @@ public override ITelemetry DeepClone()
return new DependencyTelemetry(this);
}

/// <summary>
/// In specific collectors, objects are added to the dependency telemetry which may be useful
/// to enhance DependencyTelemetry telemetry by <see cref="ITelemetryInitializer" /> implementations.
/// Objects retrieved here are not automatically serialized and sent to the backend.
/// </summary>
/// <param name="key">The key of the value to get.</param>
/// <param name="detail">When this method returns, contains the object that has the specified key, or the default value of the type if the operation failed.</param>
/// <returns>true if the key was found; otherwise, false.</returns>
public bool TryGetOperationDetail(string key, out object detail)
{
// Avoid initializing the dictionary if it has not been initialized
if (this.operationDetails == null)
{
detail = null;
return false;
}

return this.OperationDetails.TryGetValue(key, out detail);
}

/// <summary>
/// Sets the operation detail specific against the key specified. Objects set through this method
/// are not automatically serialized and sent to the backend.
/// </summary>
/// <param name="key">The key to store the detail against.</param>
/// <param name="detail">Detailed information collected by the tracked operation.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetOperationDetail(string key, object detail)
{
this.OperationDetails[key] = detail;
}

/// <summary>
/// Sanitizes the properties based on constraints.
/// </summary>
Expand All @@ -294,5 +342,19 @@ void ITelemetry.Sanitize()
this.Data = this.Data.SanitizeData();
this.Properties.SanitizeProperties();
}

/// <summary>
/// Clears any stored operational data for the dependency operation, if any.
/// </summary>
internal void ClearOperationDetails()
{
// Avoid initializing the dictionary if it has not been initialized
if (this.operationDetails == null)
{
return;
}

this.OperationDetails.Clear();
}
}
}
2 changes: 2 additions & 0 deletions src/Microsoft.ApplicationInsights/TelemetryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ public void TrackDependency(DependencyTelemetry telemetry)
}

this.Track(telemetry);

telemetry.ClearOperationDetails();
}

/// <summary>
Expand Down