generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add extension to rm microsoft appinsights logprovider (#374)
* feat: add extension to rm microsoft appinsights logprovider * pr-fix: update w logging * pr-fix: update w docker logs * pr-fix: add appinsights instrumentation key to docker * Update docs/preview/03-Guidance/use-with-dotnet-and-functions.md Co-authored-by: Frederik Gheysels <frederik.gheysels@telenet.be> * Update src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs Co-authored-by: Frederik Gheysels <frederik.gheysels@telenet.be> * Update docs/preview/03-Guidance/use-with-dotnet-and-functions.md Co-authored-by: Frederik Gheysels <frederik.gheysels@telenet.be> Co-authored-by: Frederik Gheysels <frederik.gheysels@telenet.be>
- Loading branch information
1 parent
96cb7eb
commit 63929c5
Showing
17 changed files
with
661 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
parameters: | ||
dockerProjectName: '' | ||
httpPort: '' | ||
|
||
steps: | ||
- bash: | | ||
if [ -z "$PROJECT_NAME" ]; then | ||
echo "##vso[task.logissue type=error;]Missing template parameter \"dockerProjectName\"" | ||
echo "##vso[task.complete result=Failed;]" | ||
fi | ||
if [ -z "$HTTP_PORT" ]; then | ||
echo "##vso[task.logissue type=error;]Missing template parameter \"httpPort\"" | ||
echo "##vso[task.complete result=Failed;]" | ||
fi | ||
env: | ||
PROJECT_NAME: ${{ parameters.dockerProjectName }} | ||
HTTP_PORT: ${{ parameters.httpPort }} | ||
- task: UseDotNet@2 | ||
displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' | ||
inputs: | ||
packageType: 'sdk' | ||
version: '$(DotNet.Sdk.Version)' | ||
- task: Docker@1 | ||
displayName: 'Build Docker image from ${{ parameters.dockerProjectName }}' | ||
inputs: | ||
dockerFile: src/${{ parameters.dockerProjectName }}/Dockerfile | ||
imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' | ||
useDefaultContext: false | ||
buildContext: src | ||
- task: Docker@1 | ||
displayName: 'Run new project Docker image from ${{ parameters.dockerProjectName }}' | ||
inputs: | ||
command: 'Run an image' | ||
imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' | ||
containerName: '${{ parameters.dockerProjectName }}' | ||
ports: '${{ parameters.httpPort }}:80' | ||
envVars: | | ||
APPINSIGHTS_INSTRUMENTATIONKEY=$(ApplicationInsights.InstrumentationKey) | ||
- template: test/run-integration-tests.yml@templates | ||
parameters: | ||
dotnetSdkVersion: '$(DotNet.Sdk.Version)' | ||
projectName: '$(Project).Tests.Integration' | ||
category: 'Docker' | ||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: | | ||
docker logs ${{ parameters.dockerProjectName }} | ||
failOnStderr: true | ||
displayName: Show ${{ parameters.dockerProjectName }} logs | ||
condition: always() |
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,2 @@ | ||
variables: | ||
AzureFunctions.HttpPort: 5000 |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md |
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
59 changes: 59 additions & 0 deletions
59
...vability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.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,59 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ApplicationInsights.Query; | ||
using Microsoft.Azure.ApplicationInsights.Query.Models; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights | ||
{ | ||
[Collection("Docker")] | ||
[Trait("Category", "Docker")] | ||
public class AzureFunctionsDockerTests : ApplicationInsightsSinkTests | ||
{ | ||
private static readonly HttpClient HttpClient = new HttpClient(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AzureFunctionsDockerTests" /> class. | ||
/// </summary> | ||
public AzureFunctionsDockerTests(ITestOutputHelper outputWriter) | ||
: base(outputWriter) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task LogRequest_WithRequestsOperationName_SinksToApplicationInsights() | ||
{ | ||
// Arrange | ||
int httpPort = Configuration.GetValue<int>("AzureFunctions:HttpPort"); | ||
string? requestUri = $"http://localhost:{httpPort}/api/order"; | ||
Logger.LogInformation("GET -> {URI}", requestUri); | ||
|
||
using (HttpResponseMessage response = await HttpClient.GetAsync(requestUri)) | ||
{ | ||
Logger.LogInformation("{StatusCode} <- {URI}", response.StatusCode, requestUri); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
|
||
using (ApplicationInsightsDataClient client = CreateApplicationInsightsClient()) | ||
{ | ||
await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () => | ||
{ | ||
EventsResults<EventsRequestResult> results = await client.Events.GetRequestEventsAsync(ApplicationId, PastHalfHourTimeSpan); | ||
Assert.NotEmpty(results.Value); | ||
AssertX.Any(results.Value, result => | ||
{ | ||
Assert.Contains("order", result.Request.Url); | ||
Assert.Equal("200", result.Request.ResultCode); | ||
Assert.True(Guid.TryParse(result.Request.Id, out Guid _)); | ||
Assert.Equal(HttpMethod.Get.Method + " /api/order", result.Operation.Name); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.