hook up otel to appinsights
This commit is contained in:
Родитель
ae5cbb6f16
Коммит
00447f7738
|
@ -102,7 +102,7 @@ jobs:
|
|||
az deployment group create -n ghaction${{ github.sha }} `
|
||||
--resource-group ${{secrets.AZURE_RESOURCE_GROUP_NAME}} `
|
||||
--template-file deploy/Services/api.deployment.json `
|
||||
--parameters acrPassword=$ACR_PASSWORD acrLogin=${{secrets.ACR_NAME}} acrLoginServer=$ACR_LOGIN_SERVER imageTag=${{ github.sha }} administratorLogin=${{secrets.PODCASTDB_USER_LOGIN}} administratorLoginPassword=${{secrets.PODCASTDB_USER_PASSWORD}} storageAccountName=${{ secrets.STORAGE_NAME }} serverName=${{secrets.PODCASTDB_SERVER_NAME}} kubernetesEnvName=${{secrets.KUBERNETES_ENV_NAME}} workspaceName=${{secrets.WORKSPACE_NAME}}
|
||||
--parameters acrPassword=$ACR_PASSWORD acrLogin=${{secrets.ACR_NAME}} acrLoginServer=$ACR_LOGIN_SERVER imageTag=${{ github.sha }} administratorLogin=${{secrets.PODCASTDB_USER_LOGIN}} administratorLoginPassword=${{secrets.PODCASTDB_USER_PASSWORD}} storageAccountName=${{ secrets.STORAGE_NAME }} serverName=${{secrets.PODCASTDB_SERVER_NAME}} kubernetesEnvName=${{secrets.KUBERNETES_ENV_NAME}} workspaceName=${{secrets.WORKSPACE_NAME}} appInsightsInstrumentationKey=${{secrets.APPINSIGHTS_INSTRUMENTATION_KEY}}
|
||||
|
||||
if( $LASTEXITCODE -ne 0 ) { exit -1 }
|
||||
|
||||
|
|
|
@ -49,6 +49,9 @@
|
|||
},
|
||||
"administratorLoginPassword": {
|
||||
"type": "secureString"
|
||||
},
|
||||
"appInsightsInstrumentationKey": {
|
||||
"type": "securestring"
|
||||
}
|
||||
},
|
||||
"functions": [],
|
||||
|
@ -61,7 +64,8 @@
|
|||
"podcastUpdaterImage": "[format('{0}/podcastupdaterworker:{1}', parameters('acrLoginServer'), parameters('imageTag'))]",
|
||||
"podcastIngestionWorkerImage": "[format('{0}/podcastingestionworker:{1}', parameters('acrLoginServer'), parameters('imageTag'))]",
|
||||
"imagesStorage": "[format('https://{0}.blob.core.windows.net/covers/', parameters('storageAccountName'))]",
|
||||
"deployIngestion": false
|
||||
"deployIngestion": false,
|
||||
"azureMonitorConnectionString": "[format('InstrumentationKey={0};IngestionEndpoint=https://canadacentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://canadacentral.livediagnostics.monitor.azure.com/', parameters('appInsightsInstrumentationKey'))]"
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
|
@ -193,6 +197,10 @@
|
|||
{
|
||||
"name": "acr-password",
|
||||
"value": "[parameters('acrPassword')]"
|
||||
},
|
||||
{
|
||||
"name": "azuremonitor",
|
||||
"value": "[variables('azureMonitorConnectionString')]"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -226,6 +234,10 @@
|
|||
"name": "ConnectionStrings__PodcastDb",
|
||||
"secretRef": "podcastdb"
|
||||
},
|
||||
{
|
||||
"name": "ConnectionString_AzureMonitor",
|
||||
"secretRef": "azuremonitor"
|
||||
},
|
||||
{
|
||||
"name": "Features__FeedIngestion",
|
||||
"value": "[format('{0}', variables('deployIngestion'))]"
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.4" />
|
||||
<PackageReference Include="Azure.Storage.Queues" Version="12.11.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -22,6 +23,13 @@
|
|||
<PackageReference Include="Microsoft.NET.Build.Containers" Version="0.2.7" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0-*" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.4.0-beta.2" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.4.0-beta.2" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.8" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.8" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.3" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.8" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="Asp.Versioning.Http" Version="6.1.0" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.4.3" />
|
||||
|
|
|
@ -10,6 +10,12 @@ using System.Threading.RateLimiting;
|
|||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Podcast.Infrastructure.Http;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Resources;
|
||||
using Azure.Monitor.OpenTelemetry.Exporter;
|
||||
using System.Reflection;
|
||||
using OpenTelemetry.Metrics;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
@ -27,7 +33,8 @@ builder.Services.AddAuthorization();
|
|||
|
||||
// OpenAPI and versioning-related services
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.Configure<SwaggerGeneratorOptions>(opts => {
|
||||
builder.Services.Configure<SwaggerGeneratorOptions>(opts =>
|
||||
{
|
||||
opts.InferSecuritySchemes = true;
|
||||
});
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
@ -52,12 +59,48 @@ builder.Services.AddRateLimiter(options => options.AddFixedWindowLimiter("feeds"
|
|||
options.Window = TimeSpan.FromSeconds(2);
|
||||
options.AutoReplenishment = false;
|
||||
}));
|
||||
|
||||
var serviceName = typeof(Program).Assembly.FullName;
|
||||
var serviceVersion = typeof(Program).GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
|
||||
var serviceResource =
|
||||
ResourceBuilder
|
||||
.CreateDefault()
|
||||
.AddService(serviceName: serviceName, serviceVersion: serviceVersion);
|
||||
|
||||
builder.Services.AddOpenTelemetryTracing(b =>
|
||||
b.AddSource("dotnet-podcasts")
|
||||
.SetResourceBuilder(serviceResource)
|
||||
//.AddJaegerExporter(o =>
|
||||
//{
|
||||
// o.Endpoint = builder.Configuration["Jaeger"]["Endpoint"];
|
||||
//})
|
||||
.AddAzureMonitorTraceExporter(o =>
|
||||
{
|
||||
o.ConnectionString = builder.Configuration.GetConnectionString("AzureMonitor");
|
||||
})
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddEntityFrameworkCoreInstrumentation()
|
||||
);
|
||||
|
||||
builder.Services.AddOpenTelemetryMetrics(metrics =>
|
||||
{
|
||||
metrics
|
||||
.SetResourceBuilder(serviceResource)
|
||||
.AddPrometheusExporter()
|
||||
.AddAzureMonitorMetricExporter(o =>
|
||||
{
|
||||
o.ConnectionString = builder.Configuration.GetConnectionString("AzureMonitor");
|
||||
});
|
||||
});
|
||||
builder.Services.AddOutputCache();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
await EnsureDbAsync(app.Services);
|
||||
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||
|
||||
// Register required middlewares
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
|
|
Загрузка…
Ссылка в новой задаче