-
Notifications
You must be signed in to change notification settings - Fork 356
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
[AppInsights] fixing SB result-reporting #2015
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ISdkVersionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Reflection; | ||
|
||
namespace Microsoft.Azure.WebJobs.Logging.ApplicationInsights | ||
{ | ||
public interface ISdkVersionProvider | ||
{ | ||
string GetSdkVersion(); | ||
} | ||
internal class WebJobsSdkVersionProvider : ISdkVersionProvider | ||
{ | ||
private readonly string sdkVersion = "webjobs: " + GetAssemblyFileVersion(typeof(JobHost).Assembly); | ||
public string GetSdkVersion() | ||
{ | ||
return sdkVersion; | ||
} | ||
internal static string GetAssemblyFileVersion(Assembly assembly) | ||
{ | ||
AssemblyFileVersionAttribute fileVersionAttr = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>(); | ||
return fileVersionAttr?.Version ?? LoggingConstants.Unknown; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ public class ServiceBusRequestAndDependencyCollectionTests : IDisposable | |
private const string _mockApplicationInsightsKey = "some_key"; | ||
private readonly string _endpoint; | ||
private readonly string _connectionString; | ||
private RandomNameResolver _resolver; | ||
private readonly TestTelemetryChannel _channel = new TestTelemetryChannel(); | ||
private static readonly AutoResetEvent _functionWaitHandle = new AutoResetEvent(false); | ||
|
||
|
@@ -46,16 +45,19 @@ public ServiceBusRequestAndDependencyCollectionTests() | |
_endpoint = connStringBuilder.Endpoint; | ||
} | ||
|
||
[Fact] | ||
public async Task ServiceBusDepenedenciesAndRequestAreTracked() | ||
[Theory] | ||
[InlineData("message", true)] | ||
[InlineData("throw", false)] | ||
public async Task ServiceBusDepenedenciesAndRequestAreTracked(string message, bool success) | ||
{ | ||
using (var host = ConfigureHost()) | ||
{ | ||
await host.StartAsync(); | ||
await host.GetJobHost() | ||
.CallAsync(typeof(ServiceBusRequestAndDependencyCollectionTests).GetMethod(nameof(ServiceBusOut)), new { input = "message" }); | ||
|
||
await host.GetJobHost() | ||
.CallAsync(typeof(ServiceBusRequestAndDependencyCollectionTests).GetMethod(nameof(ServiceBusOut)), new { input = message }); | ||
_functionWaitHandle.WaitOne(); | ||
|
||
await Task.Delay(1000); | ||
|
||
await host.StopAsync(); | ||
|
@@ -65,18 +67,25 @@ await host.GetJobHost() | |
List<DependencyTelemetry> dependencies = _channel.Telemetries.OfType<DependencyTelemetry>().ToList(); | ||
|
||
Assert.Equal(2, requests.Count); | ||
Assert.Single(dependencies); | ||
|
||
Assert.Single(requests.Where(r => r.Context.Operation.ParentId == dependencies.Single().Id)); | ||
var sbTriggerRequest = requests.Single(r => r.Context.Operation.ParentId == dependencies.Single().Id); | ||
// One dependency for the 'Send' from ServiceBusOut | ||
// One dependency for the 'Complete' call in ServiceBusTrigger | ||
Assert.Equal(2, dependencies.Count); | ||
var sbOutDependency = dependencies.Single(d => d.Name == "Send"); | ||
Assert.Single(dependencies, d => d.Name == "Complete"); | ||
|
||
var sbTriggerRequest = requests.Single(r => r.Name == nameof(ServiceBusTrigger)); | ||
var manualCallRequest = requests.Single(r => r.Name == nameof(ServiceBusOut)); | ||
var sbOutDependency = dependencies.Single(); | ||
|
||
string operationId = manualCallRequest.Context.Operation.Id; | ||
Assert.Equal(operationId, sbTriggerRequest.Context.Operation.Id); | ||
|
||
ValidateServiceBusDependency(sbOutDependency, _endpoint, _queueName, "Send", nameof(ServiceBusOut), operationId, manualCallRequest.Id); | ||
ValidateServiceBusRequest(sbTriggerRequest, _endpoint, _queueName, nameof(ServiceBusTrigger), operationId, sbOutDependency.Id); | ||
ValidateServiceBusRequest(sbTriggerRequest, success, _endpoint, _queueName, nameof(ServiceBusTrigger), operationId, sbOutDependency.Id); | ||
|
||
// Make sure that the trigger traces are correlated | ||
var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(t => t.Context.Operation.Id == operationId); | ||
Assert.Equal(success ? 5 : 7, traces.Count()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -99,11 +108,20 @@ public async Task ServiceBusRequestWithoutParent() | |
List<DependencyTelemetry> dependencies = _channel.Telemetries.OfType<DependencyTelemetry>().ToList(); | ||
|
||
Assert.Single(requests); | ||
Assert.Empty(dependencies); | ||
|
||
Assert.NotNull(requests.Single().Context.Operation.Id); | ||
// The call to Complete the message registers as a dependency | ||
Assert.Single(dependencies); | ||
Assert.Equal("Complete", dependencies.Single().Name); | ||
|
||
var request = requests.Single(); | ||
|
||
Assert.NotNull(request.Context.Operation.Id); | ||
|
||
ValidateServiceBusRequest(requests.Single(), _endpoint, _queueName, nameof(ServiceBusTrigger), null, null); | ||
ValidateServiceBusRequest(request, true, _endpoint, _queueName, nameof(ServiceBusTrigger), null, null); | ||
|
||
// Make sure that the trigger traces are correlated | ||
var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(t => t.Context.Operation.Id == request.Context.Operation.Id); | ||
Assert.Equal(4, traces.Count()); | ||
} | ||
|
||
[NoAutomaticTrigger] | ||
|
@@ -115,16 +133,31 @@ public static void ServiceBusOut( | |
message = input; | ||
} | ||
|
||
public static void ServiceBusTrigger( | ||
public static async Task ServiceBusTrigger( | ||
[ServiceBusTrigger(_queueName)] string message, | ||
MessageReceiver messageReceiver, | ||
string lockToken, | ||
TextWriter logger) | ||
{ | ||
logger.WriteLine($"C# script processed queue message: '{message}'"); | ||
_functionWaitHandle.Set(); | ||
try | ||
{ | ||
logger.WriteLine($"C# script processed queue message: '{message}'"); | ||
|
||
if (message == "throw") | ||
{ | ||
throw new InvalidOperationException("boom!"); | ||
} | ||
} | ||
finally | ||
{ | ||
await messageReceiver.CompleteAsync(lockToken); | ||
_functionWaitHandle.Set(); | ||
} | ||
} | ||
|
||
private void ValidateServiceBusRequest( | ||
RequestTelemetry request, | ||
bool success, | ||
string endpoint, | ||
string queueName, | ||
string operationName, | ||
|
@@ -139,7 +172,10 @@ private void ValidateServiceBusRequest( | |
Assert.True(double.TryParse(request.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration)); | ||
Assert.True(request.Duration.TotalMilliseconds >= functionDuration); | ||
|
||
TelemetryValidationHelpers.ValidateRequest(request, operationName, operationId, parentId, LogCategories.Results); | ||
Assert.DoesNotContain(request.Properties, p => p.Key == LogConstants.HttpMethodKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you validate it in the |
||
|
||
TelemetryValidationHelpers.ValidateRequest(request, operationName, operationId, parentId, LogCategories.Results, | ||
success ? LogLevel.Information : LogLevel.Error, success); | ||
} | ||
|
||
private void ValidateServiceBusDependency( | ||
|
@@ -161,13 +197,16 @@ private void ValidateServiceBusDependency( | |
|
||
public IHost ConfigureHost() | ||
{ | ||
_resolver = new RandomNameResolver(); | ||
|
||
IHost host = new HostBuilder() | ||
.ConfigureDefaultTestHost<ServiceBusRequestAndDependencyCollectionTests>(b => | ||
{ | ||
b.AddAzureStorage(); | ||
b.AddServiceBus(); | ||
b.AddServiceBus(o => | ||
{ | ||
// We'll complete these ourselves as we don't | ||
// want failures constantly retrying. | ||
o.MessageHandlerOptions.AutoComplete = false; | ||
}); | ||
}) | ||
.ConfigureLogging(b => | ||
{ | ||
|
@@ -208,4 +247,4 @@ private async Task<int> CleanUpEntity() | |
return count; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI -- this part where we check the SucceededKey is the major change. It will be needed for Http as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can prevent it from being set on properties at the first place. It's set in the AppInsightsLogger. but now it's needed because of microsoft/ApplicationInsights-dotnet-server#1038 anyway