-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* gitattributes * Fix newlines
- Loading branch information
Showing
19 changed files
with
1,792 additions
and
1,789 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
*.sh text eol=lf | ||
* text=auto eol=lf | ||
|
||
*.bat text eol=crlf | ||
*.cmd text eol=crlf |
106 changes: 53 additions & 53 deletions
106
...microsoft/applicationinsights/agent/bootstrap/diagnostics/ApplicationMetadataFactory.java
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 |
---|---|---|
@@ -1,54 +1,54 @@ | ||
package com.microsoft.applicationinsights.agent.bootstrap.diagnostics; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
public class ApplicationMetadataFactory implements Iterable<DiagnosticsValueFinder> { | ||
|
||
private final DiagnosticsValueFinder[] finders = new DiagnosticsValueFinder[] { | ||
new AgentExtensionVersionFinder(), // 0 | ||
new InstrumentationKeyFinder(), // 1 | ||
new MachineNameFinder(), // 2 | ||
new PidFinder(), // 3 | ||
new SiteNameFinder(), // 4 | ||
new SubscriptionIdFinder(), // 5 | ||
new SdkVersionFinder(), // 6 | ||
}; | ||
|
||
|
||
ApplicationMetadataFactory() {} | ||
|
||
public DiagnosticsValueFinder getExtensionVersion() { | ||
return finders[0]; | ||
} | ||
|
||
public DiagnosticsValueFinder getInstrumentationKey() { | ||
return finders[1]; | ||
} | ||
|
||
public DiagnosticsValueFinder getMachineName() { | ||
return finders[2]; | ||
} | ||
|
||
public DiagnosticsValueFinder getPid() { | ||
return finders[3]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSiteName() { | ||
return finders[4]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSubscriptionId() { | ||
return finders[5]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSdkVersion() { | ||
return finders[6]; | ||
} | ||
|
||
@Override | ||
public Iterator<DiagnosticsValueFinder> iterator() { | ||
return Arrays.asList(finders).iterator(); | ||
} | ||
|
||
package com.microsoft.applicationinsights.agent.bootstrap.diagnostics; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
public class ApplicationMetadataFactory implements Iterable<DiagnosticsValueFinder> { | ||
|
||
private final DiagnosticsValueFinder[] finders = new DiagnosticsValueFinder[] { | ||
new AgentExtensionVersionFinder(), // 0 | ||
new InstrumentationKeyFinder(), // 1 | ||
new MachineNameFinder(), // 2 | ||
new PidFinder(), // 3 | ||
new SiteNameFinder(), // 4 | ||
new SubscriptionIdFinder(), // 5 | ||
new SdkVersionFinder(), // 6 | ||
}; | ||
|
||
|
||
ApplicationMetadataFactory() {} | ||
|
||
public DiagnosticsValueFinder getExtensionVersion() { | ||
return finders[0]; | ||
} | ||
|
||
public DiagnosticsValueFinder getInstrumentationKey() { | ||
return finders[1]; | ||
} | ||
|
||
public DiagnosticsValueFinder getMachineName() { | ||
return finders[2]; | ||
} | ||
|
||
public DiagnosticsValueFinder getPid() { | ||
return finders[3]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSiteName() { | ||
return finders[4]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSubscriptionId() { | ||
return finders[5]; | ||
} | ||
|
||
public DiagnosticsValueFinder getSdkVersion() { | ||
return finders[6]; | ||
} | ||
|
||
@Override | ||
public Iterator<DiagnosticsValueFinder> iterator() { | ||
return Arrays.asList(finders).iterator(); | ||
} | ||
|
||
} |
248 changes: 124 additions & 124 deletions
248
...n/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/etw/EtwAppender.java
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 |
---|---|---|
@@ -1,125 +1,125 @@ | ||
/* | ||
* ApplicationInsights-Java | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* | ||
* MIT License | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
* software and associated documentation files (the ""Software""), to deal in the Software | ||
* without restriction, including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
* persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw; | ||
|
||
import java.util.Map; | ||
|
||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.ApplicationMetadataFactory; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.DiagnosticsHelper; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaError; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaInfo; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaVerbose; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaWarn; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.model.IpaEtwEventBase; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.status.StatusFile; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.spi.ThrowableProxyUtil; | ||
import ch.qos.logback.core.AppenderBase; | ||
|
||
public class EtwAppender extends AppenderBase<ILoggingEvent> { | ||
private final EtwProvider etwProvider; | ||
private final IpaEtwEventBase proto; | ||
|
||
public EtwAppender() { | ||
ApplicationMetadataFactory metadata = DiagnosticsHelper.getMetadataFactory(); | ||
|
||
proto = new IpaInfo(); | ||
proto.setAppName(metadata.getSiteName().getValue()); | ||
proto.setExtensionVersion(metadata.getSdkVersion().getValue()); | ||
proto.setSubscriptionId(metadata.getSubscriptionId().getValue()); | ||
|
||
etwProvider = new EtwProvider(metadata.getSdkVersion().getValue()); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
IpaVerbose event = new IpaVerbose(proto); | ||
event.setMessageFormat("EtwProvider initialized sucessfully."); | ||
try { | ||
this.etwProvider.writeEvent(event); | ||
} catch (LinkageError | ApplicationInsightsEtwException e) { | ||
final String message = "EtwProvider failed to initialize."; | ||
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).error(message, e); | ||
addError(message, e); | ||
|
||
StatusFile.putValue("EtwProviderInitialized", "false"); | ||
StatusFile.putValue("EtwProviderError", e.getLocalizedMessage()); | ||
StatusFile.write(); | ||
|
||
return; // appender fails to start | ||
} | ||
|
||
StatusFile.putValueAndWrite("EtwProviderInitialized", "true"); | ||
super.start(); | ||
} | ||
|
||
@Override | ||
protected void append(ILoggingEvent logEvent) { | ||
String logger = logEvent.getLoggerName(); | ||
if (logger != null && logger.startsWith("com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.")) { | ||
addWarn("Skipping attempt to log to "+logger); | ||
return; | ||
} | ||
|
||
Level level = logEvent.getLevel(); | ||
IpaEtwEventBase event; | ||
// empty if no throwable | ||
switch (level.levelInt) { | ||
case Level.ERROR_INT: | ||
IpaError error = new IpaError(proto); | ||
error.setStacktrace(ThrowableProxyUtil.asString(logEvent.getThrowableProxy())); | ||
event = error; | ||
break; | ||
case Level.WARN_INT: | ||
IpaWarn warn = new IpaWarn(proto); | ||
warn.setStacktrace(ThrowableProxyUtil.asString(logEvent.getThrowableProxy())); | ||
event = warn; | ||
break; | ||
case Level.INFO_INT: | ||
event = new IpaInfo(proto); | ||
break; | ||
default: | ||
addWarn("Unsupported log level: " + level.levelStr); | ||
return; | ||
} | ||
|
||
Map<String, String> mdcPropertyMap = logEvent.getMDCPropertyMap(); | ||
if (!mdcPropertyMap.isEmpty()) { | ||
String operation = mdcPropertyMap.get(DiagnosticsHelper.MDC_PROP_OPERATION); | ||
if (operation != null && !operation.isEmpty()) { | ||
event.setOperation(operation); | ||
} | ||
} | ||
event.setLogger(logger); | ||
event.setMessageFormat(logEvent.getMessage()); | ||
event.setMessageArgs(logEvent.getArgumentArray()); | ||
try { | ||
etwProvider.writeEvent(event); | ||
} catch (ApplicationInsightsEtwException e) { | ||
addError("Exception from EtwProvider: " + e.getLocalizedMessage(), e); | ||
} | ||
} | ||
|
||
/* | ||
* ApplicationInsights-Java | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* | ||
* MIT License | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
* software and associated documentation files (the ""Software""), to deal in the Software | ||
* without restriction, including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
* persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw; | ||
|
||
import java.util.Map; | ||
|
||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.ApplicationMetadataFactory; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.DiagnosticsHelper; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaError; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaInfo; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaVerbose; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.IpaWarn; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.events.model.IpaEtwEventBase; | ||
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.status.StatusFile; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.spi.ThrowableProxyUtil; | ||
import ch.qos.logback.core.AppenderBase; | ||
|
||
public class EtwAppender extends AppenderBase<ILoggingEvent> { | ||
private final EtwProvider etwProvider; | ||
private final IpaEtwEventBase proto; | ||
|
||
public EtwAppender() { | ||
ApplicationMetadataFactory metadata = DiagnosticsHelper.getMetadataFactory(); | ||
|
||
proto = new IpaInfo(); | ||
proto.setAppName(metadata.getSiteName().getValue()); | ||
proto.setExtensionVersion(metadata.getSdkVersion().getValue()); | ||
proto.setSubscriptionId(metadata.getSubscriptionId().getValue()); | ||
|
||
etwProvider = new EtwProvider(metadata.getSdkVersion().getValue()); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
IpaVerbose event = new IpaVerbose(proto); | ||
event.setMessageFormat("EtwProvider initialized sucessfully."); | ||
try { | ||
this.etwProvider.writeEvent(event); | ||
} catch (LinkageError | ApplicationInsightsEtwException e) { | ||
final String message = "EtwProvider failed to initialize."; | ||
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).error(message, e); | ||
addError(message, e); | ||
|
||
StatusFile.putValue("EtwProviderInitialized", "false"); | ||
StatusFile.putValue("EtwProviderError", e.getLocalizedMessage()); | ||
StatusFile.write(); | ||
|
||
return; // appender fails to start | ||
} | ||
|
||
StatusFile.putValueAndWrite("EtwProviderInitialized", "true"); | ||
super.start(); | ||
} | ||
|
||
@Override | ||
protected void append(ILoggingEvent logEvent) { | ||
String logger = logEvent.getLoggerName(); | ||
if (logger != null && logger.startsWith("com.microsoft.applicationinsights.agent.bootstrap.diagnostics.etw.")) { | ||
addWarn("Skipping attempt to log to "+logger); | ||
return; | ||
} | ||
|
||
Level level = logEvent.getLevel(); | ||
IpaEtwEventBase event; | ||
// empty if no throwable | ||
switch (level.levelInt) { | ||
case Level.ERROR_INT: | ||
IpaError error = new IpaError(proto); | ||
error.setStacktrace(ThrowableProxyUtil.asString(logEvent.getThrowableProxy())); | ||
event = error; | ||
break; | ||
case Level.WARN_INT: | ||
IpaWarn warn = new IpaWarn(proto); | ||
warn.setStacktrace(ThrowableProxyUtil.asString(logEvent.getThrowableProxy())); | ||
event = warn; | ||
break; | ||
case Level.INFO_INT: | ||
event = new IpaInfo(proto); | ||
break; | ||
default: | ||
addWarn("Unsupported log level: " + level.levelStr); | ||
return; | ||
} | ||
|
||
Map<String, String> mdcPropertyMap = logEvent.getMDCPropertyMap(); | ||
if (!mdcPropertyMap.isEmpty()) { | ||
String operation = mdcPropertyMap.get(DiagnosticsHelper.MDC_PROP_OPERATION); | ||
if (operation != null && !operation.isEmpty()) { | ||
event.setOperation(operation); | ||
} | ||
} | ||
event.setLogger(logger); | ||
event.setMessageFormat(logEvent.getMessage()); | ||
event.setMessageArgs(logEvent.getArgumentArray()); | ||
try { | ||
etwProvider.writeEvent(event); | ||
} catch (ApplicationInsightsEtwException e) { | ||
addError("Exception from EtwProvider: " + e.getLocalizedMessage(), e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.