Merge branch 'main' into tilee/testRedfieldDiagnosticSource

This commit is contained in:
Timothy Mothra 2022-09-06 14:39:58 -07:00 коммит произвёл GitHub
Родитель a6d8334808 19a3ecf77b
Коммит c13e82fbf2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
23 изменённых файлов: 127 добавлений и 22 удалений

3
.github/CONTRIBUTING.md поставляемый
Просмотреть файл

@ -25,7 +25,8 @@ To successfully build the sources on your machine, make sure you've installed th
- .NET Framework 4.6.1
- .NET Framework 4.6.2
- .NET Framework 4.7.2
- .NET Framework 4.8
- .NET Framework 4.8.0
- .NET Framework 4.8.1
- .NET Core 3.1
- .NET 6
- .NET 7

12
.github/dependabot.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

4
.github/workflows/build-and-test-BASE.yml поставляемый
Просмотреть файл

@ -24,13 +24,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
framework: [net452, net462, net472, net480, netcoreapp3.1, net6.0, net7.0]
framework: [net452, net462, net472, net480, net481, netcoreapp3.1, net6.0, net7.0]
include:
- os: ubuntu-latest
args: "--filter TestCategory!=WindowsOnly"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

Просмотреть файл

@ -24,10 +24,10 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest]
framework: [net452, net462, net472, net480, netcoreapp3.1, net6.0, net7.0]
framework: [net452, net462, net472, net480, net481, netcoreapp3.1, net6.0, net7.0]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

Просмотреть файл

@ -24,13 +24,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
framework: [net452, net462, net472, net480, netcoreapp3.1, net6.0, net7.0]
framework: [net452, net462, net472, net480, net481, netcoreapp3.1, net6.0, net7.0]
include:
- os: ubuntu-latest
args: "--filter TestCategory!=WindowsOnly"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

4
.github/workflows/build-and-test-WEB.yml поставляемый
Просмотреть файл

@ -24,10 +24,10 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest]
framework: [net452, net462, net472, net480, netcoreapp3.1, net6.0, net7.0]
framework: [net452, net462, net472, net480, net481, netcoreapp3.1, net6.0, net7.0]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

2
.github/workflows/nightly.yml поставляемый
Просмотреть файл

@ -22,7 +22,7 @@ jobs:
solution: [./ProjectsForSigning.sln]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}

2
.github/workflows/redfield-sanity-check.yml поставляемый
Просмотреть файл

@ -30,7 +30,7 @@ jobs:
args: "--filter TestCategory!=WindowsOnly"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

2
.github/workflows/sanity.yml поставляемый
Просмотреть файл

@ -29,7 +29,7 @@ jobs:
./WEB/Src/Microsoft.ApplicationInsights.Web.sln]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v2

2
.github/workflows/stale.yml поставляемый
Просмотреть файл

@ -12,7 +12,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4.0.0
- uses: actions/stale@v5.1.1
id: stale
with:
stale-issue-message: 'This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.'

4
.gitignore поставляемый
Просмотреть файл

@ -65,6 +65,10 @@ ipch/
*.vsp
*.vspx
# Visual Studio live unit testing config
*.lutconfig
*.lutignore
# Guidance Automation Toolkit
*.gpState

Просмотреть файл

@ -19,7 +19,7 @@
- net6.0 (EoL Nov 2024)
- net7.0 (GA Nov 2022)
-->
<TargetFrameworks>net462;net472;net480;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net480;net481;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) != 'Windows_NT'">netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

Просмотреть файл

@ -265,6 +265,30 @@
Assert.AreEqual(nextException.Message, testExceptionTelemetry.ExceptionDetailsInfoList.First().Message);
}
[TestMethod]
public void ExceptionPropertySetterPreservesContext()
{
// ARRANGE
Exception constructorException = new Exception("ConstructorException");
var testExceptionTelemetry = new ExceptionTelemetry(constructorException);
const string expectedAccountId = "AccountId";
testExceptionTelemetry.Context.User.AccountId = expectedAccountId;
const string expectedAuthenticatedUserId = "AuthUserId";
testExceptionTelemetry.Context.User.AuthenticatedUserId = expectedAuthenticatedUserId;
const string expectedUserAgent = "ExceptionComponent";
testExceptionTelemetry.Context.User.UserAgent = expectedUserAgent;
// ACT
Exception nextException = new Exception("NextException");
testExceptionTelemetry.Exception = nextException;
// ASSERT
Assert.AreEqual(expectedAccountId, testExceptionTelemetry.Context.User.AccountId);
Assert.AreEqual(expectedAuthenticatedUserId, testExceptionTelemetry.Context.User.AuthenticatedUserId);
Assert.AreEqual(expectedUserAgent, testExceptionTelemetry.Context.User.UserAgent);
}
#pragma warning disable 618
[TestMethod]
public void HandledAtReturnsUnhandledByDefault()

Просмотреть файл

@ -1150,7 +1150,11 @@
}
[TestMethod]
#if NET7_0_OR_GREATER
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Failed to parse configuration value. Property: 'IntegerProperty' Reason: The input string '123a' was not in a correct format.")]
#else
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Failed to parse configuration value. Property: 'IntegerProperty' Reason: Input string was not in a correct format.")]
#endif
public void LoadPropertiesThrowsExceptionWithPropertyName()
{
// parsing this integer will throw "System.FormatException: Input string was not in a correct format."
@ -1167,7 +1171,11 @@
}
[TestMethod]
#if NET7_0_OR_GREATER
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Failed to parse configuration value. Property: 'IntegerProperty' Reason: The input string '123a' was not in a correct format.")]
#else
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Failed to parse configuration value. Property: 'IntegerProperty' Reason: Input string was not in a correct format.")]
#endif
public void LoadProperties_TelemetryClientThrowsException()
{
string testConfig = Configuration(

Просмотреть файл

@ -27,10 +27,24 @@ namespace Microsoft.ApplicationInsights.TestFramework
listener.EnableEvents(eventSource, EventLevel.Verbose, (EventKeywords)AllKeywords);
try
{
var guid = Guid.NewGuid();
EventSource.SetCurrentThreadActivityId(guid);
object[] eventArguments = GenerateEventArguments(eventMethod);
eventMethod.Invoke(eventSource, eventArguments);
EventWrittenEventArgs actualEvent = listener.Messages.First();
EventWrittenEventArgs actualEvent = listener.Messages.FirstOrDefault(x => x.ActivityId == guid);
if (actualEvent == null)
{
throw new Exception("Listener failed to collect event.");
}
else if (actualEvent.EventId == 0)
{
// an error occurred
throw new Exception(actualEvent.Message);
}
VerifyEventId(eventMethod, actualEvent);
VerifyEventLevel(eventMethod, actualEvent);
VerifyEventMessage(eventMethod, actualEvent, eventArguments);

Просмотреть файл

@ -449,7 +449,15 @@
this.Data = new ExceptionInfo(exceptions.Select(ex => new ExceptionDetailsInfo(ex)), this.SeverityLevel,
this.ProblemId, this.Properties, this.Metrics);
this.context = new TelemetryContext(this.Data.Properties);
if (this.context == null)
{
this.context = new TelemetryContext(this.Data.Properties);
}
else
{
this.context = this.context.DeepClone(this.Data.Properties);
}
}
catch (Exception ex)
{

Просмотреть файл

@ -1,8 +1,10 @@
# Changelog
## VNext
- Update endpoint redirect header name for QuickPulse module to v2
- AzureSdkDiagnosticListener modified to use sdkversion prefix "rdddsaz" instead of "dotnet".
- [ILogger logs with LogLevel.None severity are now ignored by ApplicationInsightsLogger](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2667). Fixes ([#2666](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2666))
- [Fix ExceptionTelemetry clears all Context when updating Exception property](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2086)
## Version 2.21.0
- no changes since beta.

Просмотреть файл

@ -76,9 +76,9 @@
<!-- https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version -->
<LangVersion>preview</LangVersion>
<IsNetFramework Condition="'$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'net46' Or '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' ">True</IsNetFramework>
<IsNetFramework Condition="'$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'net46' Or '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' Or '$(TargetFramework)' == 'net481' ">True</IsNetFramework>
<IsNetCore Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">True</IsNetCore>
<IsNetStandard20 Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">True</IsNetStandard20>
<IsNetStandard20 Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' Or '$(TargetFramework)' == 'net481' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">True</IsNetStandard20>
<!-- .NET 6 introduces implicit global usings.
This causes build errors in our multi-target projects.

Просмотреть файл

@ -65,7 +65,7 @@ namespace Microsoft.Extensions.Logging.ApplicationInsights
/// </returns>
public bool IsEnabled(LogLevel logLevel)
{
return this.telemetryClient.IsEnabled();
return logLevel != LogLevel.None && this.telemetryClient.IsEnabled();
}
/// <summary>

Просмотреть файл

@ -96,6 +96,7 @@ namespace Microsoft.ApplicationInsights
testLogger.LogTrace("Trace");
testLogger.LogWarning("Warning");
testLogger.LogDebug("Debug");
testLogger.Log(LogLevel.None, "None");
Assert.AreEqual(7, itemsReceived.Count);
@ -125,6 +126,37 @@ namespace Microsoft.ApplicationInsights
Assert.AreEqual("Debug", (itemsReceived[6] as TraceTelemetry).Message);
}
/// <summary>
/// Ensures that <see cref="ApplicationInsightsLogger"/> is invoked when user logs using <see cref="ILogger"/>.
/// </summary>
[TestMethod]
[TestCategory("ILogger")]
public void ApplicationInsightsLoggerIsNotInvokedWhenUsingILoggerAndTelemetryIsDisabled()
{
List<ITelemetry> itemsReceived = new List<ITelemetry>();
IServiceProvider serviceProvider = ILoggerIntegrationTests.SetupApplicationInsightsLoggerIntegration((telemetryItem, telemetryProcessor) =>
{
itemsReceived.Add(telemetryItem);
}, configuration =>
{
configuration.DisableTelemetry = true;
});
ILogger<ILoggerIntegrationTests> testLogger = serviceProvider.GetRequiredService<ILogger<ILoggerIntegrationTests>>();
testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
testLogger.LogInformation(new EventId(100, "TestEvent"), "TestingEvent");
testLogger.LogCritical("Critical");
testLogger.LogTrace("Trace");
testLogger.LogWarning("Warning");
testLogger.LogDebug("Debug");
testLogger.Log(LogLevel.None, "None");
Assert.AreEqual(0, itemsReceived.Count);
}
/// <summary>
/// Ensures that the <see cref="ApplicationInsightsLoggerOptions.TrackExceptionsAsExceptionTelemetry"/> switch is honored
/// and exceptions are logged as trace messages when value is true.

Просмотреть файл

@ -1,7 +1,6 @@
//-----------------------------------------------------------------------------------
// <copyright file='CustomTelemetryChannel.cs' company='Microsoft Corporation'>
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
//-----------------------------------------------------------------------------------

Просмотреть файл

@ -64,7 +64,7 @@
/// Service endpoint redirect.
/// </summary>
/// <remarks>Contains a URI of the service endpoint we must permanently use <b>for the particular resource</b>.</remarks>
internal const string XMsQpsServiceEndpointRedirectHeaderName = "x-ms-qps-service-endpoint-redirect";
internal const string XMsQpsServiceEndpointRedirectHeaderName = "x-ms-qps-service-endpoint-redirect-v2";
/// <summary>
/// The following authentication headers must be received and submitted back to the service with no modification.

Просмотреть файл

@ -117,6 +117,7 @@ Define the prefixes for the SDK.
|-----------|:------:|-------------------------------------|
| Redfield<sup>1</sup> | ad_ | Telemetry from Redfield AppServices attach, using the **default** configuration |
| Redfield<sup>1</sup> | ar_ | Telemetry from Redfield AppServices attach, using the **recommended** configuration |
| Redfield<sup>1</sup> | al_ | Telemetry from Redfield Linux AppServices attach, using the **recommended** configuration |
| Redfield<sup>1</sup> | csd_ | Telemetry from Redfield CloudServices attach, using the **default** configuration |
| Redfield<sup>1</sup> | csr_ | Telemetry from Redfield CloudServices attach, using the **recommended** configuration |
| Redfield<sup>1</sup> | ud_ | Telemetry from Redfield unknown environment attach, using the **default** configuration |