Skip to content

Commit

Permalink
Merge pull request #212 from xiaomi7732/dev/saars/use-connection-string
Browse files Browse the repository at this point in the history
Dev/saars/use connection string
  • Loading branch information
xiaomi7732 authored Feb 23, 2024
2 parents 6b72e8f + 2b066bf commit c3d6b3c
Show file tree
Hide file tree
Showing 22 changed files with 591 additions and 45 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public IEnumerable<WeatherForecast> 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:

```jsonc
{
...
"ApplicationInsights": {
"InstrumentationKey": "replace-with-your-instrumentation-key"
"ConnectionString": "replace-with-your-connection-string"
}
...
}
Expand Down
2 changes: 1 addition & 1 deletion ReleaseNote.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 6 additions & 6 deletions examples/EnableServiceProfilerCLR2_1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=<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 .
Expand Down
16 changes: 8 additions & 8 deletions examples/EnableServiceProfilerCLR2_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down
12 changes: 6 additions & 6 deletions examples/EnableServiceProfilerForContainerApp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
8 changes: 4 additions & 4 deletions examples/EnableServiceProfilerForContainerApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions examples/EnableServiceProfilerInVS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions examples/EnableServiceProfilerInVSCLR2_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading

0 comments on commit c3d6b3c

Please sign in to comment.