PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

Markdown | 128 lines | 81 code | 47 blank | 0 comment | 0 complexity | 9677bc25f2f4343035375940f0b74f77 MD5 | raw file
  1. <properties
  2. pageTitle="Separate Application Insights resources for dev, test and production"
  3. description="Monitor the performance and usage of your application at different stages of development"
  4. services="application-insights"
  5. documentationCenter=""
  6. authors="alancameronwills"
  7. manager="douge"/>
  8. <tags
  9. ms.service="application-insights"
  10. ms.workload="tbd"
  11. ms.tgt_pltfrm="ibiza"
  12. ms.devlang="na"
  13. ms.topic="article"
  16. # Separating Application Insights resources
  17. Should the telemetry from different components and versions of your application be sent to different Application Insights resources, or combined into one? This article looks at best practices and the necessary techniques.
  18. First, let's understand the question.
  19. The data received from your application is stored and processed by Application Insights in a Microsoft Azure *resource*. Each resource is identified by an *instrumentation key* (iKey). In your app, the key is provided to the Application Insights SDK so that it can send the data it collects to the right resource. The key can be provided either in code or in ApplicationInsights.config. By changing the key in the SDK, you can direct data to different resources.
  20. In a simple case, when you create the code for a new application, you also create a new resource in Application Insights. In Visual Studio, the *new project* dialog will do this for you.
  21. If it's a high-volume website, it might be deployed on more than one server instance.
  22. In more complex scenarios, you have a system that is made up of multiple components - for example, a web site and a back-end processor.
  23. ## When to use separate iKeys
  24. Here are some general guidelines:
  25. * Where you have an independently deployable application unit that runs on a set of server instances that can be scaled up/down independently of other components, then you would usually map that to a single resource - that is, it will have a single instrumentation key (iKey).
  26. * By contrast, reasons for using separate iKeys include:
  27. - Easily read separate metrics from separate components.
  28. - Keep lower-volume telemetry separate from high-volume, so that throttling, quotas and sampling on one stream don't affect the other.
  29. - Separate alerts, export, and work item configurations.
  30. - Spread [limits]( such as telemetry quota, throttling, and web test count.
  31. - Code under development and test should send to a separate iKey than the production stamp.
  32. A lot of Application Insights portal experiences are designed with these guidelines in mind. For example, the servers view segments on server instance, making the assumption that telemetry about one logical component can come from several server instances.
  33. ## Single iKey
  34. Where you send telemetry from multiple components to a single iKey:
  35. * Add a property to all the telemetry that allows you to segment and filter on the component identity. This happens automatically with server role instances, but in other cases you can use a [telemetry initializer]( to add the property.
  36. * Update the Application Insights SDKs in the different components at the same time. Telemetry for one iKey should originate with the same version of the SDK.
  37. ## Separate iKeys
  38. Where you have multiple iKeys for different application components:
  39. * Create a [dashboard]( for a view of the key telemetry from your logical application, combined from the different application components. Dashboards can be shared, so a single logical system view can be used by different teams.
  40. * Organize [resource groups]( at team level. Access permissions are assigned by resource group, and these include permissions to set up alerts.
  41. * Use [Azure Resource Manager templates and Powershell]( to help manage artifacts such as alert rules and web tests.
  42. ## Separate iKeys for Dev/Test and Production
  43. To make it easier to change the key automatically when your app is released, set the iKey in code, instead of in ApplicationInsights.config.
  44. ### <a name="dynamic-ikey"></a> Dynamic instrumentation key
  45. Set the key in an initialization method, such as global.aspx.cs in an ASP.NET service:
  46. *C#*
  47. protected void Application_Start()
  48. {
  49. Microsoft.ApplicationInsights.Extensibility.
  50. TelemetryConfiguration.Active.InstrumentationKey =
  51. // - for example -
  52. WebConfigurationManager.AppSettings["ikey"];
  53. ...
  54. In this example, the ikeys for the different resources are placed in different versions of the web configuration file. Swapping the web configuration file - which you can do as part of the release script - will swap the target resource.
  55. ### Web pages
  56. The iKey is also used in your app's web pages, in the [script that you got from the quick start blade]( Instead of coding it literally into the script, generate it from the server state. For example, in an ASP.NET app:
  57. *JavaScript in Razor*
  58. <script type="text/javascript">
  59. // Standard Application Insights web page script:
  60. var appInsights = window.appInsights || function(config){ ...
  61. // Modify this part:
  62. }({instrumentationKey:
  63. // Generate from server property:
  64. @Microsoft.ApplicationInsights.Extensibility.
  65. TelemetryConfiguration.Active.InstrumentationKey"
  66. }) // ...
  67. ## Creating an additional Application Insights resource
  68. If you decide to separate telemetry for different application components, or for different stamps (dev/test/production) of the same component, then you'll have to create a new Application Insights resource.
  69. In the [](, add an Application Insights resource:
  70. ![Click New, Application Insights](./media/app-insights-separate-resources/01-new.png)
  71. * **Application type** affects what you see on the overview blade and the properties available in [metric explorer]( If you don't see your type of app, choose one of the web types for web pages.
  72. * **Resource group** is a convenience for managing properties like [access control]( You could use separate resource groups for development, test, and production.
  73. * **Subscription** is your payment account in Azure.
  74. * **Location** is where we keep your data. Currently it can't be changed.
  75. * **Add to dashboard** puts a quick-access tile for your resource on your Azure Home page.
  76. Creating the resource takes a few seconds. You'll see an alert when it's done.
  77. (You can write a [PowerShell script]( to create a resource automatically.)
  78. ## Getting the instrumentation key
  79. The instrumentation key identifies the resource that you created.
  80. ![Click Essentials, click the Instrumentation Key, CTRL+C](./media/app-insights-separate-resources/02-props.png)
  81. You'll need the instrumentation keys of all the resources to which your app will send data.