@@ -10,39 +10,68 @@ internal class LinuxContainerEventGenerator : LinuxEventGenerator
10
10
{
11
11
private readonly Action < string > _writeEvent ;
12
12
private readonly bool _consoleEnabled = true ;
13
+ private readonly IEnvironment _environment ;
14
+ private string _containerName ;
15
+ private string _stampName ;
16
+ private string _tenantId ;
13
17
14
- public LinuxContainerEventGenerator ( Action < string > writeEvent = null )
18
+ public LinuxContainerEventGenerator ( IEnvironment environment , Action < string > writeEvent = null )
15
19
{
16
20
_writeEvent = writeEvent ?? ConsoleWriter ;
17
-
21
+ _environment = environment ;
18
22
if ( Environment . GetEnvironmentVariable ( EnvironmentSettingNames . ConsoleLoggingDisabled ) == "1" )
19
23
{
20
24
_consoleEnabled = false ;
21
25
}
26
+ _containerName = _environment . GetEnvironmentVariable ( EnvironmentSettingNames . ContainerName ) ? . ToUpperInvariant ( ) ;
22
27
}
23
28
24
29
// Note: the strange escaping of backslashes in these expressions for string literals (e.g. '\\\\\"') is because
25
30
// of the current JSON serialization our log messages undergoe.
26
- public static string TraceEventRegex { get ; } = $ "{ ScriptConstants . LinuxLogEventStreamName } (?<Level>[0-6]),(?<SubscriptionId>[^,]*),(?<AppName>[^,]*),(?<FunctionName>[^,]*),(?<EventName>[^,]*),(?<Source>[^,]*),\\ \\ \" (?<Details>.*)\\ \\ \" ,\\ \\ \" (?<Summary>.*)\\ \\ \" ,(?<HostVersion>[^,]*),(?<EventTimestamp>[^,]+),(?<ExceptionType>[^,]*),\\ \\ \" (?<ExceptionMessage>.*)\\ \\ \" ,(?<FunctionInvocationId>[^,]*),(?<HostInstanceId>[^,]*),(?<ActivityId>[^,\" ]*)";
31
+ public static string TraceEventRegex { get ; } = $ "{ ScriptConstants . LinuxLogEventStreamName } (?<Level>[0-6]),(?<SubscriptionId>[^,]*),(?<AppName>[^,]*),(?<FunctionName>[^,]*),(?<EventName>[^,]*),(?<Source>[^,]*),\\ \\ \" (?<Details>.*)\\ \\ \" ,\\ \\ \" (?<Summary>.*)\\ \\ \" ,(?<HostVersion>[^,]*),(?<EventTimestamp>[^,]+),(?<ExceptionType>[^,]*),\\ \\ \" (?<ExceptionMessage>.*)\\ \\ \" ,(?<FunctionInvocationId>[^,]*),(?<HostInstanceId>[^,]*),(?<ActivityId>[^,\" ]*),(?<ContainerName>[^, \" ]*),(?<StampName>[^, \" ]*),(?<TenantId>[^, \" ]*) ";
27
32
28
- public static string MetricEventRegex { get ; } = $ "{ ScriptConstants . LinuxMetricEventStreamName } (?<SubscriptionId>[^,]*),(?<AppName>[^,]*),(?<FunctionName>[^,]*),(?<EventName>[^,]*),(?<Average>\\ d*),(?<Min>\\ d*),(?<Max>\\ d*),(?<Count>\\ d*),(?<HostVersion>[^,]*),(?<EventTimestamp>[^,]+),(?<Details >[^,\" ]*)";
33
+ public static string MetricEventRegex { get ; } = $ "{ ScriptConstants . LinuxMetricEventStreamName } (?<SubscriptionId>[^,]*),(?<AppName>[^,]*),(?<FunctionName>[^,]*),(?<EventName>[^,]*),(?<Average>\\ d*),(?<Min>\\ d*),(?<Max>\\ d*),(?<Count>\\ d*),(?<HostVersion>[^,]*),(?<EventTimestamp>[^,]+),\\ \\ \" (?<Data>.*) \\ \\ \" ,(?<ContainerName>[^, \" ]*),(?<StampName>[^, \" ]*),(?<TenantId >[^,\" ]*)";
29
34
30
35
public static string DetailsEventRegex { get ; } = $ "{ ScriptConstants . LinuxFunctionDetailsEventStreamName } (?<AppName>[^,]*),(?<FunctionName>[^,]*),\\ \\ \" (?<InputBindings>.*)\\ \\ \" ,\\ \\ \" (?<OutputBindings>.*)\\ \\ \" ,(?<ScriptType>[^,]*),(?<IsDisabled>[0|1])";
31
36
37
+ private string StampName
38
+ {
39
+ get
40
+ {
41
+ if ( string . IsNullOrEmpty ( _stampName ) )
42
+ {
43
+ _stampName = _environment . GetEnvironmentVariable ( EnvironmentSettingNames . WebSiteHomeStampName ) ? . ToLowerInvariant ( ) ;
44
+ }
45
+ return _stampName ;
46
+ }
47
+ }
48
+
49
+ private string TenantId
50
+ {
51
+ get
52
+ {
53
+ if ( string . IsNullOrEmpty ( _tenantId ) )
54
+ {
55
+ _tenantId = _environment . GetEnvironmentVariable ( EnvironmentSettingNames . WebSiteStampDeploymentId ) ? . ToLowerInvariant ( ) ;
56
+ }
57
+ return _tenantId ;
58
+ }
59
+ }
60
+
32
61
public override void LogFunctionTraceEvent ( LogLevel level , string subscriptionId , string appName , string functionName , string eventName , string source , string details , string summary , string exceptionType , string exceptionMessage , string functionInvocationId , string hostInstanceId , string activityId )
33
62
{
34
63
string eventTimestamp = DateTime . UtcNow . ToString ( EventTimestampFormat ) ;
35
64
string hostVersion = ScriptHost . Version ;
36
65
FunctionsSystemLogsEventSource . Instance . SetActivityId ( activityId ) ;
37
66
38
- _writeEvent ( $ "{ ScriptConstants . LinuxLogEventStreamName } { ( int ) ToEventLevel ( level ) } ,{ subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ source } ,{ NormalizeString ( details ) } ,{ NormalizeString ( summary ) } ,{ hostVersion } ,{ eventTimestamp } ,{ exceptionType } ,{ NormalizeString ( exceptionMessage ) } ,{ functionInvocationId } ,{ hostInstanceId } ,{ activityId } ") ;
67
+ _writeEvent ( $ "{ ScriptConstants . LinuxLogEventStreamName } { ( int ) ToEventLevel ( level ) } ,{ subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ source } ,{ NormalizeString ( details ) } ,{ NormalizeString ( summary ) } ,{ hostVersion } ,{ eventTimestamp } ,{ exceptionType } ,{ NormalizeString ( exceptionMessage ) } ,{ functionInvocationId } ,{ hostInstanceId } ,{ activityId } , { _containerName } , { StampName } , { TenantId } ") ;
39
68
}
40
69
41
70
public override void LogFunctionMetricEvent ( string subscriptionId , string appName , string functionName , string eventName , long average , long minimum , long maximum , long count , DateTime eventTimestamp , string data )
42
71
{
43
72
string hostVersion = ScriptHost . Version ;
44
73
45
- _writeEvent ( $ "{ ScriptConstants . LinuxMetricEventStreamName } { subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ average } ,{ minimum } ,{ maximum } ,{ count } ,{ hostVersion } ,{ eventTimestamp . ToString ( EventTimestampFormat ) } ,{ data } ") ;
74
+ _writeEvent ( $ "{ ScriptConstants . LinuxMetricEventStreamName } { subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ average } ,{ minimum } ,{ maximum } ,{ count } ,{ hostVersion } ,{ eventTimestamp . ToString ( EventTimestampFormat ) } ,{ NormalizeString ( data ) } , { _containerName } , { StampName } , { TenantId } ,,,, ") ;
46
75
}
47
76
48
77
public override void LogFunctionDetailsEvent ( string siteName , string functionName , string inputBindings , string outputBindings , string scriptType , bool isDisabled )
0 commit comments