1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the MIT License. See LICENSE in the project root for license information.
3
3
4
4
using System . Net ;
5
5
using System . Net . Http . Headers ;
6
6
using System . Text ;
7
7
using Azure . Functions . Cli . Arm . Models ;
8
8
using Azure . Functions . Cli . Common ;
9
+ using Azure . Functions . Cli . Extensions ;
9
10
using Azure . Functions . Cli . Helpers ;
10
11
using Colors . Net ;
11
12
using Fclp ;
@@ -16,7 +17,8 @@ namespace Azure.Functions.Cli.Actions.AzureActions
16
17
[ Action ( Name = "logstream" , Context = Context . Azure , SubContext = Context . FunctionApp , HelpText = "Show interactive streaming logs for an Azure-hosted Function App" ) ]
17
18
internal class LogStreamAction : BaseFunctionAppAction
18
19
{
19
- private const string ApplicationInsightsIKeySetting = "APPINSIGHTS_INSTRUMENTATIONKEY" ;
20
+ private const string ApplicationInsightsInstrumentationKeySetting = "APPINSIGHTS_INSTRUMENTATIONKEY" ;
21
+ private const string ApplicationInsightsConnectionStringSetting = "APPLICATIONINSIGHTS_CONNECTION_STRING" ;
20
22
private const string LiveMetricsUriTemplate = "https://portal.azure.com/#blade/AppInsightsExtension/QuickPulseBladeV2/ComponentId/{0}/ResourceId/{1}" ;
21
23
22
24
public bool UseBrowser { get ; set ; }
@@ -44,9 +46,9 @@ public override async Task RunAsync()
44
46
return ;
45
47
}
46
48
47
- if ( functionApp . IsLinux && functionApp . IsDynamic )
49
+ if ( functionApp . IsFlex || ( functionApp . IsLinux && functionApp . IsDynamic ) )
48
50
{
49
- throw new CliException ( "Log stream is not currently supported in Linux Consumption Apps. " +
51
+ throw new CliException ( "Log stream is not currently supported in Linux Consumption and Flex Apps. " +
50
52
"Please use --browser to open Azure Application Insights Live Stream in the Azure portal." ) ;
51
53
}
52
54
@@ -92,20 +94,31 @@ public override async Task RunAsync()
92
94
93
95
public async Task OpenLiveStreamInBrowser ( Site functionApp , IEnumerable < ArmSubscription > allSubscriptions )
94
96
{
95
- if ( ! functionApp . AzureAppSettings . ContainsKey ( ApplicationInsightsIKeySetting ) )
97
+ string instrumentationKey ;
98
+
99
+ // First, check for a connection string. If it's not available, default to using the Instrumentation Key.
100
+ if ( functionApp . AzureAppSettings . TryGetValue ( ApplicationInsightsConnectionStringSetting , out var connectionString ) )
101
+ {
102
+ instrumentationKey = connectionString . GetValueFromDelimitedString ( "InstrumentationKey" ) ;
103
+ }
104
+ else if ( functionApp . AzureAppSettings . TryGetValue ( ApplicationInsightsInstrumentationKeySetting , out var key ) )
105
+ {
106
+ ColoredConsole . WriteLine ( WarningColor ( "Support for instrumentation key ingestion has ended. Switch to connection strings to access new features." ) ) ;
107
+ instrumentationKey = key ;
108
+ }
109
+ else
96
110
{
97
- throw new CliException ( $ "Missing { ApplicationInsightsIKeySetting } App Setting. " +
111
+ throw new CliException ( $ "Missing { ApplicationInsightsConnectionStringSetting } App Setting. " +
98
112
$ "Please make sure you have Application Insights configured with your function app.") ;
99
113
}
100
114
101
- var iKey = functionApp . AzureAppSettings [ ApplicationInsightsIKeySetting ] ;
102
- if ( string . IsNullOrEmpty ( iKey ) )
115
+ if ( string . IsNullOrWhiteSpace ( instrumentationKey ) )
103
116
{
104
117
throw new CliException ( "Invalid Instrumentation Key found. Please make sure that the Application Insights is configured correctly." ) ;
105
118
}
106
119
107
120
ColoredConsole . WriteLine ( "Retrieving Application Insights information..." ) ;
108
- var appId = await AzureHelper . GetApplicationInsightIDFromIKey ( iKey , AccessToken , ManagementURL , allSubs : allSubscriptions ) ;
121
+ var appId = await AzureHelper . GetApplicationInsightIDFromIKey ( instrumentationKey , AccessToken , ManagementURL , allSubs : allSubscriptions ) ;
109
122
var armResourceId = AzureHelper . ParseResourceId ( appId ) ;
110
123
var componentId = $@ "{{""Name"":""{ armResourceId . Name } "",""SubscriptionId"":""{ armResourceId . Subscription } "",""ResourceGroup"":""{ armResourceId . ResourceGroup } ""}}";
111
124
0 commit comments