Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Commit

Permalink
Change RDDSource for DiagnosticSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Liudmila Molkova committed May 3, 2017
1 parent 84bd166 commit 7e0a386
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="..\Shared.Tests\Implementation\DependencyCollectorDiagnosticListenerTests.Netstandard20.cs" Link="DependencyCollectorDiagnosticListenerTests.Netstandard20.cs" />
<Compile Include="..\Shared.Tests\Implementation\EnumerableAssert.cs" Link="EnumerableAssert.cs" />
<Compile Include="..\Shared.Tests\Implementation\MockCorrelationIdLookupHelper.cs" Link="MockCorrelationIdLookupHelper.cs" />
<Compile Include="..\..\TestFramework\Shared\SdkVersionHelper.cs" Link="SdkVersionHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>Copyright © Microsoft. All Rights Reserved.</Copyright>
Expand Down Expand Up @@ -29,6 +29,7 @@
<Compile Include="..\Shared\Implementation\HttpCoreDiagnosticSourceListener.cs" Link="HttpCoreDiagnosticSourceListener.cs" />
<Compile Include="..\Shared\Implementation\HttpHeadersUtilities.cs" Link="HttpHeadersUtilities.cs" />
<Compile Include="..\Shared\Implementation\PropertyFetcher.cs" Link="PropertyFetcher.cs" />
<Compile Include="..\Shared\Implementation\RDDSource.cs" Link="RDDSource.cs" />
<Compile Include="..\Shared\Implementation\HttpParsers\AzureBlobHttpParser.cs" Link="AzureBlobHttpParser.cs" />
<Compile Include="..\Shared\Implementation\HttpParsers\AzureIotHubHttpParser.cs" Link="AzureIotHubHttpParser.cs" />
<Compile Include="..\Shared\Implementation\HttpParsers\AzureQueueHttpParser.cs" Link="AzureQueueHttpParser.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Microsoft.ApplicationInsights.DependencyCollector
using Microsoft.ApplicationInsights.Common;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.TestFramework;
#if !NETCORE
using Microsoft.ApplicationInsights.Web.TestFramework;
#endif
Expand Down Expand Up @@ -203,6 +205,10 @@ public void OnResponseWithSuccessfulResponseEventWithMatchingRequestAndNoTargetI
Assert.AreEqual(RequestUrl, telemetry.Target);
Assert.AreEqual(HttpOkResultCode, telemetry.ResultCode);
Assert.AreEqual(true, telemetry.Success);

string expectedVersion =
SdkVersionHelper.GetExpectedSdkVersion(typeof(DependencyTrackingTelemetryModule), prefix: "rdddsc:");
Assert.AreEqual(expectedVersion, telemetry.Context.GetInternalContext().SdkVersion);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Microsoft.ApplicationInsights.DependencyCollector
using Microsoft.ApplicationInsights.Common;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.TestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

/// <summary>
Expand Down Expand Up @@ -72,6 +74,10 @@ public void OnActivityStopTracksTelemetry()
Assert.AreEqual(activity.ParentId, telemetry.Context.Operation.ParentId);
Assert.AreEqual(activity.Id, telemetry.Id);
Assert.AreEqual("v", telemetry.Context.Properties["k"]);

string expectedVersion =
SdkVersionHelper.GetExpectedSdkVersion(typeof(DependencyTrackingTelemetryModule), prefix: "rdddsc:");
Assert.AreEqual(expectedVersion, telemetry.Context.GetInternalContext().SdkVersion);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static void ValidateTelemetryPacketForOnRequestSend(DependencyTelemetry
{
Assert.AreEqual("GET " + url.AbsolutePath, remoteDependencyTelemetryActual.Name, true, "Resource name in the sent telemetry is wrong");
string expectedVersion =
SdkVersionHelper.GetExpectedSdkVersion(typeof(DependencyTrackingTelemetryModule), prefix: "rddfd:");
SdkVersionHelper.GetExpectedSdkVersion(typeof(DependencyTrackingTelemetryModule), prefix: "rdddsd:");
ValidateTelemetryPacket(remoteDependencyTelemetryActual, url, kind, success, valueMin, statusCode, expectedVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class DesktopDiagnosticSourceHttpProcessing : HttpProcessing
private readonly ObjectInstanceBasedOperationHolder telemetryTable;

internal DesktopDiagnosticSourceHttpProcessing(TelemetryConfiguration configuration, ObjectInstanceBasedOperationHolder telemetryTupleHolder, bool setCorrelationHeaders, ICollection<string> correlationDomainExclusionList, string appIdEndpoint)
: base(configuration, SdkVersionUtils.GetSdkVersion("rdd" + RddSource.FrameworkAndDiagnostic + ":"), null, setCorrelationHeaders, correlationDomainExclusionList, appIdEndpoint)
: base(configuration, SdkVersionUtils.GetSdkVersion("rdd" + RddSource.DiagnosticSourceDesktop + ":"), null, setCorrelationHeaders, correlationDomainExclusionList, appIdEndpoint)
{
if (telemetryTupleHolder == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public HttpCoreDiagnosticSourceListener(
ICorrelationIdLookupHelper correlationIdLookupHelper)
{
this.client = new TelemetryClient(configuration);
this.client.Context.GetInternalContext().SdkVersion = SdkVersionUtils.GetSdkVersion("rddd");
this.client.Context.GetInternalContext().SdkVersion = SdkVersionUtils.GetSdkVersion("rdd" + RddSource.DiagnosticSourceCore + ":");

this.configuration = configuration;
this.applicationInsightsUrlFilter = new ApplicationInsightsUrlFilter(configuration);
Expand Down
3 changes: 2 additions & 1 deletion Src/DependencyCollector/Shared/Implementation/RDDSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ internal class RddSource
{
internal static string Profiler = "p";
internal static string Framework = "f";
internal static string FrameworkAndDiagnostic = "fd";
internal static string DiagnosticSourceDesktop = "dsd";
internal static string DiagnosticSourceCore = "dsc";
}
}
19 changes: 14 additions & 5 deletions Src/TestFramework/Shared/SdkVersionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
namespace Microsoft.ApplicationInsights.TestFramework
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System;
#if NETCORE
using System.Collections.Generic;
#endif
using System.Linq;
using System.Reflection;

public static class SdkVersionHelper
{
public static string GetExpectedSdkVersion(Type assemblyType, string prefix)
{
string versonStr = Assembly.GetAssembly(assemblyType).GetCustomAttributes(false)
.OfType<AssemblyFileVersionAttribute>()
.First()
.Version;
string[] versionParts = new Version(versonStr).ToString().Split('.');
#if NETCORE
IEnumerable<Attribute> assemblyCustomAttributes = assemblyType.GetTypeInfo().Assembly.GetCustomAttributes();
#else
object[] assemblyCustomAttributes = assemblyType.Assembly.GetCustomAttributes(false);
#endif
string versionStr = assemblyCustomAttributes
.OfType<AssemblyFileVersionAttribute>()
.First()
.Version;
string[] versionParts = new Version(versionStr).ToString().Split('.');

var expected = prefix + string.Join(".", versionParts[0], versionParts[1], versionParts[2]) + "-" + versionParts[3];

Expand Down

0 comments on commit 7e0a386

Please sign in to comment.