-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added console event generator for kudu (#85)
- Loading branch information
1 parent
992596e
commit 6d1af0e
Showing
2 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using System; | ||
using System.Diagnostics.Tracing; | ||
using System.IO; | ||
using Kudu.Core.Settings; | ||
|
||
namespace Kudu.Core.Tracing | ||
{ | ||
class ConsoleEventGenerator : IKuduEventGenerator | ||
{ | ||
private readonly Action<string> _writeEvent; | ||
private readonly bool _consoleEnabled = true; | ||
|
||
public ConsoleEventGenerator() | ||
{ | ||
_writeEvent = ConsoleWriter; | ||
} | ||
|
||
public void ProjectDeployed(string siteName, string projectType, string result, string error, long deploymentDurationInMilliseconds, string siteMode, string scmType, string vsProjectId) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
projectType = projectType, | ||
result = result, | ||
error = error, | ||
deploymentDurationInMilliseconds = deploymentDurationInMilliseconds, | ||
siteMode = siteMode, | ||
scmType = scmType, | ||
vsProjectId = vsProjectId | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void WebJobStarted(string siteName, string jobName, string scriptExtension, string jobType, string siteMode, string error, string trigger) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
jobName = jobName, | ||
scriptExtension = scriptExtension, | ||
jobType = jobType, | ||
siteMode = siteMode, | ||
error = error, | ||
trigger = trigger | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void KuduException(string siteName, string method, string path, string result, string Message, string exception) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
level = (int)EventLevel.Warning, | ||
siteName = siteName, | ||
method = method, | ||
path = path, | ||
result = result, | ||
Message = Message, | ||
exception = exception | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void DeprecatedApiUsed(string siteName, string route, string userAgent, string method, string path) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
level = (int)EventLevel.Warning, | ||
siteName = siteName, | ||
route = route, | ||
userAgent = userAgent, | ||
method = method, | ||
path = path | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void KuduSiteExtensionEvent(string siteName, string method, string path, string result, string deploymentDurationInMilliseconds, string Message) | ||
{ | ||
long duration = 0; | ||
long.TryParse(deploymentDurationInMilliseconds, out duration); | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
method = method, | ||
path = path, | ||
result = result, | ||
deploymentDurationInMilliseconds = duration, | ||
Message = Message | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void WebJobEvent(string siteName, string jobName, string Message, string jobType, string error) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
jobName = jobName, | ||
Message = Message, | ||
jobType = jobType, | ||
error = error | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void GenericEvent(string siteName, string Message, string requestId, string scmType, string siteMode, string buildVersion) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
Message = Message, | ||
requestId = requestId, | ||
scmType = scmType, | ||
siteMode = siteMode, | ||
buildVersion = buildVersion | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void ApiEvent(string siteName, string Message, string address, string verb, string requestId, int statusCode, long latencyInMilliseconds, string userAgent) | ||
{ | ||
KuduEvent kuduEvent = new KuduEvent | ||
{ | ||
siteName = siteName, | ||
Message = Message, | ||
address = address, | ||
verb = verb, | ||
requestId = requestId, | ||
statusCode = statusCode, | ||
latencyInMilliseconds = latencyInMilliseconds, | ||
userAgent = userAgent | ||
}; | ||
|
||
LogKuduTraceEvent(kuduEvent); | ||
} | ||
|
||
public void LogKuduTraceEvent(KuduEvent kuduEvent) | ||
{ | ||
_writeEvent($"{Constants.LinuxLogEventStreamName} {kuduEvent.ToString()},{Environment.StampName},{Environment.TenantId},{Environment.ContainerName}"); | ||
} | ||
|
||
private void ConsoleWriter(string evt) | ||
{ | ||
if (_consoleEnabled) | ||
{ | ||
Console.WriteLine(evt); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters