GithubHelp home page GithubHelp logo

lombiq / orchard-azure-application-insights Goto Github PK

View Code? Open in Web Editor NEW
18.0 13.0 10.0 9.91 MB

Orchard Core and Orchard 1 module to enable easy integration of Azure Application Insights telemetry into Orchard. Useful for Azure-based cloud hosting.

License: BSD 3-Clause "New" or "Revised" License

C# 100.00%
orchard orchard-cms orchard-module application-insights hosting-suite azure-application-insights telemetry azure orchard-core hosting

orchard-azure-application-insights's Introduction

Lombiq Hosting - Azure Application Insights for Orchard Core

Lombiq.Hosting.Azure.ApplicationInsights NuGet Lombiq.Hosting.Azure.ApplicationInsights.Tests.UI NuGet

About

This Orchard Core module enables easy integration of Azure Application Insights telemetry into Orchard. Just install the module, configure the instrumentation key from a configuration source (like the appsettings.json file) as normally for AI, and use the AddOrchardCoreApplicationInsightsTelemetry() extension method in your Web project's Program.cs file and collected data will start appearing in the Azure Portal. Check out the module's demo here, and the Orchard Harvest 2023 conference talk about automated QA in Orchard Core here. Note that this module has an Orchard 1 version in the dev-orchard-1 branch.

What kind of data is collected from the telemetry and available for inspection in the Azure Portal?

  • All usual AI data, including e.g. server-side requests, client-side page views, exceptions and other log entries, dependency calls (like web requests and database queries).
  • Information on background task executions (as dependency operations).
  • All telemetry is enriched with Orchard-specific and general details like user ID, user name, shell (tenant) name, user agent, IP address.

And all of this can be configured in depth. Extended configuration for built-in AI features is also available, like being able to turn SQL query command text collection on or off.

We at Lombiq also used this module for the following projects:

Do you want to quickly try out this project and see it in action? Check it out in our Open-Source Orchard Core Extensions full Orchard Core solution and also see our other useful Orchard Core-related open-source projects!

Documentation

Setup and basic configuration

Configure the built-in AI options as detailed in the AI docs in an ASP.NET Core configuration source like the appsettings.json file like below (everything in the root "ApplicationInsights" section is just built-in AI configuration). Do note that contrary to the standard AI configuration all log entries will be sent to AI by default. If you want to restrict that to just warnings, for example, you also have to add a corresponding LogLevel as demonstrated.

{
  "ApplicationInsights": {
    "ConnectionString": "your connection string comes here"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      //...
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  },
  "OrchardCore": {
    //...
  }
}

Add the AI services to the service collection in your Web project's Program.cs file:

var builder = WebApplication.CreateBuilder(args);

var configuration = builder.Configuration;

builder.Services
    .AddOrchardCms(orchardCoreBuilder =>
    {
        orchardCoreBuilder.AddOrchardCoreApplicationInsightsTelemetry(configuration);
    });

Note that due to how the Application Insights .NET SDK works, telemetry can only be collected for the whole app at once; collecting telemetry separately for each tenant is not supported.

When using the full CMS approach of Orchard Core (i.e. not decoupled or headless) then the client-side tracking script will be automatically injected as a head script. Otherwise, you can create it with ITrackingScriptFactory.

Advanced configuration

The module has its own configuration for further options. These need to come from an ASP.NET Core configuration source as well but on the contrary to the basic settings for built-in AI options these need to be put under the OrchardCore section, into Lombiq_Hosting_Azure_ApplicationInsights:

{
  "ApplicationInsights": {
    "ConnectionString": "your connection string comes here"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      //...
    }
  },
  "OrchardCore": {
    "Lombiq_Hosting_Azure_ApplicationInsights": {
      "QuickPulseTelemetryModuleAuthenticationApiKey": "your API key here"
    }
  }
}

See the ApplicationInsightsOptions class for all options and details. We recommend configuring at least QuickPulseTelemetryModuleAuthenticationApiKey.

Note that while telemetry from background tasks is collected in form of dependency operations it'll be collected even if EnableDependencyTrackingTelemetryModule is false.

If you use the security defaults from Lombiq Helpful Libraries - Orchard Core Libraries - Security, then the security headers necessary to use Application Insight's client-side tracking will automatically be added.

Using collected data

All the collected data will be available in the Azure Portal as usual. Some custom properties will be added to all suitable telemetry with the "OrchardCore." prefix.

UI testing

The Lombiq.Hosting.Azure.ApplicationInsights.Tests.UI project contains UI test extension methods that you can call from your own test project. Check it out for details.

Contributing and support

Bug reports, feature requests, comments, questions, code contributions and love letters are warmly welcome. You can send them to us via GitHub issues and pull requests. Please adhere to our open-source guidelines while doing so.

This project is developed by Lombiq Technologies. Commercial-grade support is available through Lombiq.

orchard-azure-application-insights's People

Contributors

0liver avatar azaliusz avatar barthamark avatar demeszabolcs avatar dministro avatar domonkosgabor avatar i3undy avatar luko6 avatar mzole avatar piedone avatar porgabi avatar psichorex avatar sarahelsaig avatar wasnk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orchard-azure-application-insights's Issues

Add the ability to treat certain 4## responses as success based on request URL (NEST-499)

Browsers by default try to fetch the favicon at the /favicon.ico URL at beginning of opening a site/page, resulting in a 404 logged by AI. When the actual page is loaded, the favicon is correctly picked up based on what's defined in the corresponding head link tag. Let's ignore these initial 404 entries.

  • Add a new setting to ApplicationInsightsOptions that can be a regex.
  • Use this regex in a new ITelemetryProcessor implementation to match request URLs with a 4## response and treat them as success, instead of failure.
  • Use this in DotNest Tenants Core for the /favicon.ico and /_MediaTheme/Templates URLs.
  • Add this regex as an example to the Readme.

Jira issue

Add UI testing extension method (OSOE-74)

Similar to Data Tables, add a UI testing extension method that checks what the UI testing sample project's ApplicationInsightsTrackingShouldBePresent test does. Execute this from the OSOCE UI test project, and change the sample test to also do that, as an example of using external UI test methods.

Move the EnableApplicationInsightsOfflineOperation extension method from the Toolbox from this project, and use this from both test projects.

Publish the test project on NuGet and use it from the NuGet solution.

NuGet version

Any chance this will make it to NuGet at some point?

Or is it already on a feed somewhere, that I couldn't see?

Azure Application Insights menu not showing in settings?

@Piedone Hi there, forgive my ignorance - but I'm running 1.10.1 and have enabled your module to no effect. Am I expecting an 'Azure Application Insights' menu to be added to Dashboard > Settings Menu? Or do I have to perform some additional steps (for wouldn't that require:
Filters.Add(new TemplateFilterForPart<AzureApplicationInsightsTelemetrySettingsPart>("AzureApplicationInsightsTelemetrySettings", "Parts/AzureApplicationInsightsTelemetrySettings", "Azure Application Insights"));
..to be added to the handler)?
Thanks in advance, Liv

Filter out expected dependency failures (OSOE-695)

When a tenant is started, it probes the DB and storage (like Azure Blob storage). These can cause exceptions that are swallowed, but still show up as dependency failures (not logged exceptions) in Application Insights, polluting the telemetry. You can see these coming in under Live metrics, but later they'll also show up under Failures -> Dependencies.

Examples, but do check for more:

  • Coming from BlobContainerClient.Create when using Azure Blog Storage:

Azure.RequestFailedException: The specified container already exists. RequestId:03eeed50-101e-00a6-2268-f22078000000 Time:2023-09-29T00:02:34.7434509Z Status: 409 (The specified container already exists.) ErrorCode: ContainerAlreadyExists Content: ContainerAlreadyExistsThe specified container already exists. RequestId:03eeed50-101e-00a6-2268-f22078000000 Time:2023-09-29T00:02:34.7434509Z Headers: Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 x-ms-request-id: 03eeed50-101e-00a6-2268-f22078000000 x-ms-client-request-id: 973f8083-2a00-4eff-b1ed-6cbfe2145ec4 x-ms-version: 2023-01-03 x-ms-error-code: ContainerAlreadyExists Date: Fri, 29 Sep 2023 00:02:33 GMT Content-Length: 230 Content-Type: application/xml at Azure.Storage.Blobs.ContainerRestClient.CreateAsync(Nullable1 timeout, IDictionary2 metadata, Nullable1 access, String defaultEncryptionScope, Nullable1 preventEncryptionScopeOverride, CancellationToken cancellationToken) at Azure.Storage.Blobs.BlobContainerClient.CreateInternal(PublicAccessType publicAccessType, IDictionary`2 metadata, BlobContainerEncryptionScopeOptions encryptionScopeOptions, Boolean async, CancellationToken cancellationToken, String operationName)

I guess only when you have OrchardCore_Media_Azure__CreateContainer set as true. The same for the Data Protection container.

This is also separately logged as a 409 PUT request.

  • SQL:

Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'tenantprefix_Identifiers' in the database. at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite) at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in /_/Dapper/SqlMapper.cs:line 2858 at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 581 at YesSql.Sql.SchemaBuilder.Execute(IEnumerable1 statements) at YesSql.Sql.SchemaBuilder.CreateTable(String name, Action`1 table) ClientConnectionId:a32d37e6-5142-44aa-9b74-0898ec09d23e Error Number:2714,State:6,Class:16 ClientConnectionId before routing:6dd65d41-0a9b-431c-8237-2c847c2c9003 Routing Destination:dcedae88a438.tr40050.eastus1-a.worker.database.windows.net,11003

Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'Shells_Identifiers' in the database. at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite) at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in /_/Dapper/SqlMapper.cs:line 2858 at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 581 at YesSql.Sql.SchemaBuilder.Execute(IEnumerable1 statements) at YesSql.Sql.SchemaBuilder.CreateTable(String name, Action`1 table) ClientConnectionId:a32d37e6-5142-44aa-9b74-0898ec09d23e Error Number:2714,State:6,Class:16 ClientConnectionId before routing:6dd65d41-0a9b-431c-8237-2c847c2c9003 Routing Destination:dcedae88a438.tr40050.eastus1-a.worker.database.windows.net,11003

There are similar dependency failures during a tenant's setup too.

Filter out these so they don't reach Application Insights.

Related: OrchardCMS/OrchardCore#14314

Jira issue

File path too long for deployments

dcinzona created on May 4, 2015:
https://orchardazureappinsights.codeplex.com/workitem/5

The file paths generated at build when attempting to publish are longer than 248 / 260 characters. This makes it a pain to build and deploy the module.
Ideally, the module directory should be something like Lombiq.AppInsights and then all the files in the lib dir should be stored in the root or in folders with shorter names.

Add Microsoft.ApplicationInsights.Web

Adding Microsoft.ApplicationInsights.Web makes a lot of TelementryInitializers and Modules available, so worth thinking about including it (and of course initializers and modules both need to be hooked up manually in code, the same ones that would be added to ApplicationInsights.cofnig).

Missing data

I have the latest nuget package versions for all of the referenced Application Insights packages but I'm seeing a lot of missing data in app insights in the Azure portal.

Here are a few things that I'm noticing:

Here you can see that I have no operations listed:
image

Here you can see I have no stack trace:
image

This is on the Performance tab. You can see again there is no list of operations:
image

I'm hoping I just have something misconfigured but I'm definitely hoping to be able to see these details.

In addition, the Live Metrics Stream shows

Not available: your app is offline or using an older SDK

CORS error were reported

mr560889223 created on Sep 16, 2015:
https://orchardazureappinsights.codeplex.com/workitem/7

From Azure Portal, I can see there are failures reported as "The browser’s same-origin policy prevents us from getting the details of this exception.The exception occurred in a script loaded from an origin different than the web page.For cross- domain error reporting you can use crossorigin attribute together with appropriate CORS HTTP headers.For more information please see http://www.w3.org/TR/cors/.".

I looked at the source code and it seems that Azure.ApplicationInsights.TrackingScript.cshtml is referring to "//az416426.vo.msecnd.net/scripts/a/ai.0.js", which is hosted on a 3rd-party domain.

If this turns out to be the cause of the above CORS error, is there any chance that this file can be included in the module, or the path to the script can be configured in Orchard?

Add support for secure Live Metrics channel with AAD authentication instead of API key (OSOE-598)

The module currently supports using an API key for securing the Live Metrics control channel via the QuickPulseTelemetryModuleAuthenticationApiKey config. However, API keys are now deprecated in favor of Microsoft Entra ID authentication, and apps using them will stop ingesting Live Metrics data from 31.03.2026 (this was previously 30.09.2025). See the official docs.

So, let's implement configuration support AAD authentication while keeping the API key option available, but with a note on its deprecation, as well as with an [Obsolete] attribute. Add docs on the configuration, how you'd set up authentication.

Jira issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.