Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ETW init failure #3571

Merged
merged 18 commits into from
Mar 6, 2024
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Version 3.5.1 GA (03/05/2024)

### Bug fixes:

* Fix ETW initialization failure for App Service Windows ([#3571](https://github.com/microsoft/ApplicationInsights-Java/pull/3571))

## Version 3.5.0 GA (02/29/2024)

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public static File buildDllLocalPath(@Nullable String versionDirectory) {
}

if (!dllPath.exists()) {
dllPath.mkdirs();
try {
dllPath.mkdirs();
} catch (SecurityException e) {
throw new IllegalStateException(
"Failed to create a folder AISDK/native for the native dll.", e);
}
}

if (!dllPath.exists() || !dllPath.canRead() || !dllPath.canWrite()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public EtwProvider(String sdkVersion) {
LOGGER.debug("EtwProvider initialized. Lib path={}", dllPath.getAbsolutePath());
} catch (Throwable t) {
try {
LOGGER.error("Error initializing EtwProvider", t);
LOGGER.debug("Error initializing EtwProvider", t);
heyams marked this conversation as resolved.
Show resolved Hide resolved
if (dllPath != null) {
dllPath.deleteOnExit();
}
Expand Down
10 changes: 5 additions & 5 deletions etw/native/src/main/cpp/etw_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TRACELOGGING_DEFINE_PROVIDER(
(0x1f0dc33f,0x30ae,0x5ff3,0x8b,0x01,0x8c,0xa9,0xb8,0x50,0x92,0x33));

/********cppWriteEvent(IpaEtwEventBase event)********/
JNIEXPORT void JNICALL Java_com_microsoft_applicationinsights_agent_bootstrap_diagnostics_etw_EtwProvider_cppWriteEvent
JNIEXPORT void JNICALL Java_com_microsoft_applicationinsights_agent_internal_diagnostics_etw_EtwProvider_cppWriteEvent
(JNIEnv * env, jobject jobj_javaThis, jobject jobj_event)
{
try
Expand Down Expand Up @@ -81,7 +81,7 @@ JNIEXPORT void JNICALL Java_com_microsoft_applicationinsights_agent_bootstrap_di

int getEventId(JNIEnv * env, jobject &jobj_event) throw(aijnierr_t) {
jclass cls = env->GetObjectClass(jobj_event);
jmethodID jmid = env->GetMethodID(cls, "id", "()Lcom/microsoft/applicationinsights/agent/bootstrap/diagnostics/etw/events/model/IpaEtwEventId;");
jmethodID jmid = env->GetMethodID(cls, "id", "()Lcom/microsoft/applicationinsights/agent/internal/diagnostics/etw/events/model/IpaEtwEventId;");
if (jmid == NULL) {
throw AIJNIERR_METHOD_NAME;
}
Expand Down Expand Up @@ -285,7 +285,7 @@ void handleGenericException(JNIEnv * env) noexcept {

jthrowable newJniException(JNIEnv * env, const char * message) noexcept {
jthrowable rval = NULL;
jclass excls = env->FindClass("com/microsoft/applicationinsights/agent/bootstrap/diagnostics/etw/ApplicationInsightsEtwException");
jclass excls = env->FindClass("com/microsoft/applicationinsights/agent/internal/diagnostics/etw/ApplicationInsightsEtwException");
if (excls == NULL) {
DBG("Could not find ApplicationInsightsEtwException");
javaThrowUnknownError(env, " - could not find ApplicationInsightsEtwException");
Expand Down Expand Up @@ -314,7 +314,7 @@ jthrowable newJniException(JNIEnv * env, const char * message, jthrowable cause)
}

jthrowable rval = NULL;
jclass excls = env->FindClass("com/microsoft/applicationinsights/agent/bootstrap/diagnostics/etw/ApplicationInsightsEtwException");
jclass excls = env->FindClass("com/microsoft/applicationinsights/agent/internal/diagnostics/etw/ApplicationInsightsEtwException");
if (excls == NULL) {
DBG("Could not find class ApplicationInsightsEtwException");
javaThrowUnknownError(env, " - could not find class ApplicationInsightsEtwException");
Expand Down Expand Up @@ -406,4 +406,4 @@ char * jstring2cstr(JNIEnv * env, jstring &jstr_input, char * cstr_output, aijni
DBG("rls jstr chars (%s): js=%p, cc=%p\n", jstrid2name(field_id).c_str(), &cc_str, &jstr_input);
env->ReleaseStringUTFChars(jstr_input, cc_str);
return cstr_output;
}
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion etw/native/src/main/headers/etw_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <windows.h>
#include <TraceLoggingProvider.h>
#include <string>
#include "com_microsoft_applicationinsights_agent_bootstrap_diagnostics_etw_EtwProvider.h"
#include "com_microsoft_applicationinsights_agent_internal_diagnostics_etw_EtwProvider.h"

TRACELOGGING_DECLARE_PROVIDER(provider_EtwHandle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public List<String> getUnexpectedEntries() throws IOException {
expectedEntries.add("rp-logger-config/");
expectedEntries.add("rp-logger-config/diagnostics\\.appender\\.xml");
expectedEntries.add("rp-logger-config/etw\\.appender\\.xml");
expectedEntries.add("applicationinsights-java-etw-provider-x86-64\\.dll");
expectedEntries.add("applicationinsights-java-etw-provider-x86\\.dll");
expectedEntries.add("inst/.*");
JarFile jarFile = new JarFile(AGENT_JAR);
List<String> unexpected = new ArrayList<>();
Expand Down