diff --git a/README.md b/README.md index f06cbfb..7b4e539 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ public IEnumerable Get() } ``` -* Setup the instrumentation key for debugging +* Setup the connection string for debugging In [appsettings.Development.json](examples/QuickStart3_0/appsettings.Development.json), add the following configuration: @@ -95,7 +95,7 @@ In [appsettings.Development.json](examples/QuickStart3_0/appsettings.Development { ... "ApplicationInsights": { - "InstrumentationKey": "replace-with-your-instrumentation-key" + "ConnectionString": "replace-with-your-connection-string" } ... } diff --git a/ReleaseNote.md b/ReleaseNote.md index dad68a8..e1901dc 100644 --- a/ReleaseNote.md +++ b/ReleaseNote.md @@ -71,7 +71,7 @@ Profiling the application and the services and monitoring the performance by usi * Enable button in Profiler Configuration pane does not work -**If you host your app using App Services Linux, you do not need to enable Profiler again in the Performance pane in App Insights portal. Including NuGet package in project and setting App Insights iKey in App Settings are sufficient to enable Profiler** +**If you host your app using App Services Linux, you do not need to enable Profiler again in the Performance pane in App Insights portal. Including NuGet package in project and setting App Insights Connection String in App Settings are sufficient to enable Profiler** If you follow the [App Insights Profiler for Windows](https://docs.microsoft.com/azure/application-insights/app-insights-profiler) enablement workflow to click **Enable** in the Configure Profiler pane, you will receive an error as the button will try to install the Windows version of profiler agent on Linux environment. We are working on resolving this issue in the enablement experience. diff --git a/examples/EnableServiceProfilerCLR2_1/Dockerfile b/examples/EnableServiceProfilerCLR2_1/Dockerfile index fe80f42..9dc6075 100644 --- a/examples/EnableServiceProfilerCLR2_1/Dockerfile +++ b/examples/EnableServiceProfilerCLR2_1/Dockerfile @@ -13,15 +13,15 @@ RUN dotnet publish -c Release -o out # Build runtime image FROM microsoft/dotnet:2.1-aspnetcore-runtime -# Create an argument to allow docker builder to passing in application insights key. -# For example: docker build . --build-arg APPINSIGHTS_KEY=YOUR_APPLICATIONINSIGHTS_INSTRUMENTATION_KEY -ARG APPINSIGHTS_KEY +# Create an argument to allow docker builder to passing in application insights connection string. +# For example: docker build . --build-arg APPINSIGHTS_CONN= +ARG APPINSIGHTS_CONN # Making sure the argument is set. Fail the build of the container otherwise. -RUN test -n "$APPINSIGHTS_KEY" +RUN test -n "$APPINSIGHTS_CONN" # Light up Application Insights and Service Profiler -ENV APPINSIGHTS_INSTRUMENTATIONKEY $APPINSIGHTS_KEY -ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES Microsoft.ApplicationInsights.Profiler.AspNetCore +ENV APPLICATIONINSIGHTS_CONNECTION_STRING=$APPINSIGHTS_CONN +ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.AspNetCore WORKDIR /app COPY --from=build-env /app/out . diff --git a/examples/EnableServiceProfilerCLR2_1/README.md b/examples/EnableServiceProfilerCLR2_1/README.md index bb4dc34..36f577a 100644 --- a/examples/EnableServiceProfilerCLR2_1/README.md +++ b/examples/EnableServiceProfilerCLR2_1/README.md @@ -51,23 +51,23 @@ To enable Service Profiler, NuGet package needs to be installed and proper envir # Adding a reference to hosting startup package RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 1.1.7-* ... -# Light up Application Insights for Kubernetes -ENV APPINSIGHTS_INSTRUMENTATIONKEY YOUR_APPLICATION_INSIGHTS_KEY -ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES Microsoft.ApplicationInsights.Profiler.AspNetCore +# Light up Application Insights Profiler +ENV APPLICATIONINSIGHTS_CONNECTION_STRING=YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING +ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.AspNetCore ... ``` * The first line adds the reference to the NuGet package of Service Profiler before the build of the project happens. -* The second line sets the instrumentation key to Application Insights so that the application knows where to send the trace to. +* The second line sets the connection string to Application Insights so that the application knows where to send the trace to. * The third line sets the boot strapper for Service Profiler. *To make your build context as small as possible add a [.dockerignore](.dockerignore) file to your project folder.* -Reference the full [Dockerfile](./Dockerfile), you will notice it is a bit different. The major change is that **YOUR_APPLICATION_INSIGHTS_KEY** has been pulled out to become an argument - the main consideration is for the code security. +Reference the full [Dockerfile](./Dockerfile), you will notice it is a bit different. The major change is that **YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING** has been pulled out to become an argument - the main consideration is for the code security. ## Create an Application Insights resource -Follow the [Create an Application Insights resource](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource). Note down the [instrumentation key](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource#copy-the-instrumentation-key). +Follow the [Create an Application Insights resource](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource). Note down the [connection string](https://learn.microsoft.com/en-us/azure/azure-monitor/app/migrate-from-instrumentation-keys-to-connection-strings#migrate-from-application-insights-instrumentation-keys-to-connection-strings). ## Optionally set the log level to Information for Service Profiler @@ -85,11 +85,11 @@ Just like in [appsettings.json](./appsettings.json). ## Build and run the Docker image ```shell -docker build -t appinsights-profiler-example --build-arg APPINSIGHTS_KEY=YOUR_APPLICATION_INSIGHTS_KEY . +docker build -t appinsights-profiler-example --build-arg APPINSIGHTS_CONN=YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING . docker run -p 8080:80 --name appinsights-profiler-example appinsights-profiler-example ``` -Note, replace **YOUR_APPLICATION_INSIGHTS_KEY** with the real instrumentation key from the previous step. +Note, replace **YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING** with the real connection string from the previous step. Once the container starts to run, the Service Profiler will kick in for 2 minutes. diff --git a/examples/EnableServiceProfilerForContainerApp/Dockerfile b/examples/EnableServiceProfilerForContainerApp/Dockerfile index 47f5a3a..424ff34 100644 --- a/examples/EnableServiceProfilerForContainerApp/Dockerfile +++ b/examples/EnableServiceProfilerForContainerApp/Dockerfile @@ -13,15 +13,15 @@ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:3.1 -# Create an argument to allow docker builder to passing in application insights key. -# For example: docker build . --build-arg APPINSIGHTS_KEY=YOUR_APPLICATIONINSIGHTS_INSTRUMENTATION_KEY -ARG APPINSIGHTS_KEY +# Create an argument to allow docker builder to passing in application insights conneection string. +# For example: docker build . --build-arg APPINSIGHTS_CONN=YOUR_APPLICATIONINSIGHTS_CONNECTION_STRING +ARG APPINSIGHTS_CONN # Making sure the argument is set. Fail the build of the container otherwise. -RUN test -n "$APPINSIGHTS_KEY" +RUN test -n "$APPINSIGHTS_CONN" # Light up Application Insights and Service Profiler -ENV APPINSIGHTS_INSTRUMENTATIONKEY $APPINSIGHTS_KEY -ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES Microsoft.ApplicationInsights.Profiler.AspNetCore +ENV APPLICATIONINSIGHTS_CONNECTION_STRING=$APPINSIGHTS_CONN +ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.AspNetCore WORKDIR /app COPY --from=build-env /app/out . diff --git a/examples/EnableServiceProfilerForContainerApp/README.md b/examples/EnableServiceProfilerForContainerApp/README.md index bd9dff2..795d633 100644 --- a/examples/EnableServiceProfilerForContainerApp/README.md +++ b/examples/EnableServiceProfilerForContainerApp/README.md @@ -36,14 +36,14 @@ _Tips: find the official images for [sdk](https://hub.docker.com/_/microsoft-dot To enable Service Profiler, NuGet package needs to be installed and proper environment variables need to be set. One way to reach the goal is adding the following lines to your [Dockerfile](./Dockerfile). In this file: * It adds the reference to the NuGet package of Service Profiler before the build of the project happens. -* It sets the instrumentation key to Application Insights so that the application knows where to send the trace to. +* It sets the connection string to Application Insights so that the application knows where to send the trace to. * It uses the hosting startup assembly for the entry point of Service Profiler. *To make your build context as small as possible add a [.dockerignore](./.dockerignore) file to your project folder.* ## Create an Application Insights resource -Follow the [Create an Application Insights resource](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource). Note down the [instrumentation key](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource#copy-the-instrumentation-key). +Follow the [Create an Application Insights resource](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource). Note down the [instrumentation connection string](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-create-new-resource#copy-the-instrumentation-key). ## Optionally set the log level to Information for Service Profiler @@ -61,11 +61,11 @@ Just like in [appsettings.json](./appsettings.json). ## Build and run the Docker image ```shell -docker build -t enable-sp-example --build-arg APPINSIGHTS_KEY=YOUR_APPLICATION_INSIGHTS_KEY . +docker build -t enable-sp-example --build-arg APPINSIGHTS_CONN="YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING" . docker run -p 8080:80 --name enable-sp enable-sp-example ``` -Note, replace **YOUR_APPLICATION_INSIGHTS_KEY** with the real instrumentation key from the previous step. +Note, replace **YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING** with the real connection string from the previous step. Once the container starts to run, the Service Profiler will kick in for 2 minutes. diff --git a/examples/EnableServiceProfilerForContainerAppNet6/Readme.md b/examples/EnableServiceProfilerForContainerAppNet6/Readme.md index 61229ce..325e479 100644 --- a/examples/EnableServiceProfilerForContainerAppNet6/Readme.md +++ b/examples/EnableServiceProfilerForContainerAppNet6/Readme.md @@ -15,7 +15,7 @@ In this article, you'll learn the various ways you can: ## Pre-requisites -- [An Application Insights resource](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource). Make note of the instrumentation key. +- [An Application Insights resource](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource). Make note of the connection string. - [.NET 6 SDK](https://dot.net) for creating projects and local build. - [Docker Desktop](https://www.docker.com/products/docker-desktop/) to build docker images. diff --git a/examples/EnableServiceProfilerInVS/README.md b/examples/EnableServiceProfilerInVS/README.md index 5ee2fd2..99ec2f0 100644 --- a/examples/EnableServiceProfilerInVS/README.md +++ b/examples/EnableServiceProfilerInVS/README.md @@ -82,13 +82,13 @@ Follow the wizard to configure the App Service: ``` ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.AspNetCore -APPINSIGHTS_INSTRUMENTATIONKEY=0f1b2415-9a4f-4da1-9d26-replacewithyourown +APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=08055218-1dcc-your-own;IngestionEndpoint=someurls-from-application-insights-resource" ``` It will looks like this: ![Set Environment Variables](./.media/SetEnvInPortal.png) -**Note**: The setting of the Application Insights instrumentation key should be optional. However, we have a bug in Service Profiler that requires it to be available for now. +**Note**: The setting of the Application Insights connection string should be optional. However, we have a bug in Service Profiler that requires it to be available for now. Restart your app, the Service Profiler will be turned on and gathering trace for 2 minutes. Try to generate some traffic to your app during that period. If everything is hooked up correctly, you will start to see the traces after 5 to 10 minutes just like when you see the traces in the debug session. diff --git a/examples/EnableServiceProfilerInVSCLR2_1/README.md b/examples/EnableServiceProfilerInVSCLR2_1/README.md index cdbf70f..82b7f03 100644 --- a/examples/EnableServiceProfilerInVSCLR2_1/README.md +++ b/examples/EnableServiceProfilerInVSCLR2_1/README.md @@ -97,14 +97,14 @@ Follow the wizard to configure the App Service: ## Add Settings for the App Service in the Azure Portal ```shell -APPINSIGHTS_INSTRUMENTATIONKEY=0f1b2415-9a4f-4da1-9d26-replacewithyourown +APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=08055218-1dcc-48b1-8a67-f449406001c7;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/" ``` It will looks like this: ![Set Environment Variables](./.media/SetEnvInPortal.png) -**Note**: The setting of the Application Insights instrumentation key should be optional. However, we have a bug in Service Profiler that requires it to be available for now. +**Note**: The setting of the Application Insights connection string should be optional. However, we have a bug in Service Profiler that requires it to be available for now. Restart your app, the Service Profiler will be turned on and gathering trace for 2 minutes. Try to generate some traffic to your app during that period. If everything is hooked up correctly, you will start to see the traces after 5 to 10 minutes just like when you see the traces in the debug session. diff --git a/examples/EnableServiceProfilerNet8/.gitignore b/examples/EnableServiceProfilerNet8/.gitignore new file mode 100644 index 0000000..4e8e734 --- /dev/null +++ b/examples/EnableServiceProfilerNet8/.gitignore @@ -0,0 +1,487 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from `dotnet new gitignore` + +# dotenv files +.env + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +.idea + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp + +# Solution file +EnableServiceProfilerNet8.sln \ No newline at end of file diff --git a/examples/EnableServiceProfilerNet8/EnableServiceProfilerNet8.csproj b/examples/EnableServiceProfilerNet8/EnableServiceProfilerNet8.csproj new file mode 100644 index 0000000..614259f --- /dev/null +++ b/examples/EnableServiceProfilerNet8/EnableServiceProfilerNet8.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/examples/EnableServiceProfilerNet8/Program.cs b/examples/EnableServiceProfilerNet8/Program.cs new file mode 100644 index 0000000..58f60c4 --- /dev/null +++ b/examples/EnableServiceProfilerNet8/Program.cs @@ -0,0 +1,16 @@ +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddApplicationInsightsTelemetry(); // Register Application Insights +builder.Services.AddServiceProfiler(opt =>{ + // Customize by code, for example: + opt.Duration = TimeSpan.FromSeconds(30); // Profile for 30 seconds than the default of 2 minutes. +}); // Register Profiler + +var app = builder.Build(); + +app.MapGet("/", async () => { + await Task.Delay(500); + return "Hello Profiler"; +}); + +app.Run(); diff --git a/examples/EnableServiceProfilerNet8/Readme.md b/examples/EnableServiceProfilerNet8/Readme.md new file mode 100644 index 0000000..4e02728 --- /dev/null +++ b/examples/EnableServiceProfilerNet8/Readme.md @@ -0,0 +1,7 @@ +# Enable Profiler for WebAPI in .NET 8 + +This folder contains a live example of Profiler running in .NET 8 Minimal WebAPI. + +Enabling the profiler in .NET 8 does not require any changes in the steps. Please refer to [the readme for .NET 6](../EnableServiceProfilerForContainerAppNet6/Readme.md) for instructions. + +If you are building a **Worker**, please refer to [this readme](../ServiceProfilerInWorkerNet6/) for further guidance. \ No newline at end of file diff --git a/examples/EnableServiceProfilerNet8/appsettings.Development.json b/examples/EnableServiceProfilerNet8/appsettings.Development.json new file mode 100644 index 0000000..4a9944f --- /dev/null +++ b/examples/EnableServiceProfilerNet8/appsettings.Development.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ApplicationInsights": + { + "ConnectionString": "Your-ConnectionString" + } +} diff --git a/examples/EnableServiceProfilerNet8/appsettings.json b/examples/EnableServiceProfilerNet8/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/examples/EnableServiceProfilerNet8/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/examples/EnableServiceProfilerNet8/query.http b/examples/EnableServiceProfilerNet8/query.http new file mode 100644 index 0000000..5cd65cf --- /dev/null +++ b/examples/EnableServiceProfilerNet8/query.http @@ -0,0 +1,2 @@ +# Use this file with VSCode Rest client extension +GET http://localhost:5234/ diff --git a/examples/HostingStartupCLR3/Dockerfile b/examples/HostingStartupCLR3/Dockerfile index 4df82da..9f45bda 100644 --- a/examples/HostingStartupCLR3/Dockerfile +++ b/examples/HostingStartupCLR3/Dockerfile @@ -17,8 +17,8 @@ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 -# Setup environment variable for application insights instrumentation key -ENV APPINSIGHTS_INSTRUMENTATIONKEY=#YOUR-APPINSIGHTS_INSTRUMENTATIONKEY# +# Setup environment variable for application insights connection string +ENV APPLICATIONINSIGHTS_CONNECTION_STRING="YOUR-APPLICATIONINSIGHTS_CONNECTION_STRING" # Setup environment variable for hosting startup assembly ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.HostingStartup30 diff --git a/examples/HostingStartupCLR3/Readme.md b/examples/HostingStartupCLR3/Readme.md index b45def6..d8d9af3 100644 --- a/examples/HostingStartupCLR3/Readme.md +++ b/examples/HostingStartupCLR3/Readme.md @@ -5,7 +5,7 @@ ## Pre-requisition * Basic knowledge of how to [Dockerize an ASP.NET Core application](https://docs.docker.com/engine/examples/dotnetcore/). -* A valid application insights instrumentation key. +* A valid application insights connection string. ## The Plan @@ -60,8 +60,8 @@ That should give us a good **build image**. Refer to [Dockerfile](./Dockerfile) * Then, we will need to setup 2 environment variables in the **runtime image**: ```dockerfile -# Setup environment variable for application insights instrumentation key -ENV APPINSIGHTS_INSTRUMENTATIONKEY=your-instrumentation-key +# Setup environment variable for application insights connection string +ENV APPLICATIONINSIGHTS_CONNECTION_STRING=your-applicationinsights-connection-string # Setup environment variable for hosting startup assembly ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.HostingStartup30 ``` @@ -119,8 +119,8 @@ After all tweaks, the image is ready to be built. Again, refer to [Dockerfile](. [Deploy the images built to Azure App Service](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-docker) and it will run already. What special about running it in Azure is that it enables us to overwrite the environment variables. This is very useful in sense of: 1. Overwrite for the environment variables set in the docker file - * You could set _APPINSIGHTS_INSTRUMENTATIONKEY_ in app settings and the application will honor it; - * I would setup 2 application insights resource. One for development only, one for production. The production instrumentation key will only be protected and set only in the Azure App service settings. + * You could set _APPLICATIONINSIGHTS_CONNECTION_STRING_ in app settings and the application will honor it; + * I would setup 2 application insights resource. One for development only, one for production. The production connection string will only be protected and set only in the Azure App service settings. * You could set _ASPNETCORE_HOSTINGSTARTUPASSEMBLIES_ to decide whether to light up Application Insights Profiler or not. diff --git a/examples/QuickStart3_0/Readme.md b/examples/QuickStart3_0/Readme.md index b16b44e..1091589 100644 --- a/examples/QuickStart3_0/Readme.md +++ b/examples/QuickStart3_0/Readme.md @@ -7,7 +7,7 @@ Then, in the second part, we will containerized it to a Linux container. ## Prerequisites 1. [.NET Core **SDK** 3.0.100](https://dotnet.microsoft.com/download). -1. [An instrumentation key](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource) associated with a valid application insights resource in Azure. +1. [A connection string](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource) associated with a valid application insights resource in Azure. ## Get started @@ -69,7 +69,7 @@ public IEnumerable Get() } ``` -### Setup the instrumentation key for debugging +### Setup the connection string for debugging In [appsettings.Development.json](./appsettings.Development.json), add the following configuration: @@ -77,7 +77,7 @@ In [appsettings.Development.json](./appsettings.Development.json), add the follo { ... "ApplicationInsights": { - "InstrumentationKey": "replace-with-your-instrumentation-key" + "ConnectionString": "replace-with-your-connection-string" } ... } diff --git a/examples/QuickStart3_0/Readme2.md b/examples/QuickStart3_0/Readme2.md index 36d201f..3928cbb 100644 --- a/examples/QuickStart3_0/Readme2.md +++ b/examples/QuickStart3_0/Readme2.md @@ -26,7 +26,7 @@ Since we already have a working project, just follow the [dockerfile example](ht 1. Set the environment variable to provide instrumentation for release build of the application: ```dockerfile - ENV APPINSIGHTS_INSTRUMENTATIONKEY YOUR_APPLICATION_INSIGHTS_KEY + ENV APPLICATIONINSIGHTS_CONNECTION_STRING="YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING" ``` 1. Update the entry point toward the end of the file to pick up the proper assembly. diff --git a/examples/QuickStart3_0/appsettings.Development.json b/examples/QuickStart3_0/appsettings.Development.json index cb5e36a..0aef4b1 100644 --- a/examples/QuickStart3_0/appsettings.Development.json +++ b/examples/QuickStart3_0/appsettings.Development.json @@ -1,6 +1,6 @@ { "ApplicationInsights": { - "InstrumentationKey": "your-instrumentation-key" + "ConnectionString": "your-connection-string" }, "Logging": { "LogLevel": { diff --git a/examples/QuickStart3_0/dockerfile b/examples/QuickStart3_0/dockerfile index b091d0a..ccf892a 100644 --- a/examples/QuickStart3_0/dockerfile +++ b/examples/QuickStart3_0/dockerfile @@ -11,7 +11,7 @@ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 -ENV APPINSIGHTS_INSTRUMENTATIONKEY ***your-instrumentation-key*** +ENV APPLICATIONINSIGHTS_CONNECTION_STRING="***your-application-insights-connection-string***" WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "QuickStart3_0.dll"] \ No newline at end of file