Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [11.1.0

- Adds hikari logs to opentelemetry

## [11.0.5]

- Adds all logs to telemetry which were logged with `io/supertokens/output/Logging.java`
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ java {
}
}

version = "11.0.5"
version = "11.1.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"8.0"
"8.1"
]
}
3 changes: 3 additions & 0 deletions src/main/java/io/supertokens/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.telemetry.TelemetryProvider;
import io.supertokens.telemetry.WebRequestTelemetryHandler;
import io.supertokens.version.Version;
import io.supertokens.webserver.Webserver;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -170,6 +171,8 @@ private void init() throws IOException, StorageQueryException {
Logging.info(this, TenantIdentifier.BASE_TENANT, "Completed config.yaml loading.", true);

TelemetryProvider.initialize(this);
WebRequestTelemetryHandler.INSTANCE.initializeOtelProvider(
TelemetryProvider.getInstance(this)); //life would be much easier with DI..

// loading storage layer
try {
Expand Down
55 changes: 47 additions & 8 deletions src/main/java/io/supertokens/dashboard/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.StorageUtils;
import io.supertokens.pluginInterface.dashboard.DashboardSessionInfo;
import io.supertokens.pluginInterface.dashboard.DashboardStorage;
import io.supertokens.pluginInterface.dashboard.DashboardUser;
import io.supertokens.pluginInterface.dashboard.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.dashboard.exceptions.DuplicateUserIdException;
Expand All @@ -34,16 +35,15 @@
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.telemetry.WebRequestTelemetryHandler;
import io.supertokens.utils.Utils;
import jakarta.annotation.Nullable;
import org.jetbrains.annotations.TestOnly;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.regex.Pattern;

public class Dashboard {
Expand Down Expand Up @@ -84,18 +84,57 @@ public static DashboardUser signUpDashboardUser(AppIdentifier appIdentifier, Sto
}
}

String hashedPassword = PasswordHashing.getInstance(main).createHashWithSalt(appIdentifier, password);
String hashedPassword = null;
try {
hashedPassword = WebRequestTelemetryHandler.INSTANCE.wrapInSpan(TenantIdentifier.BASE_TENANT,
"Hashing dashboard password",
Map.of("email", email), () ->
{
try {
return PasswordHashing.getInstance(main).createHashWithSalt(appIdentifier, password);
} catch (TenantOrAppNotFoundException e) {
throw new RuntimeException(e);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof TenantOrAppNotFoundException) {
throw (TenantOrAppNotFoundException) e.getCause();
}
throw e;
}
while (true) {

String userId = Utils.getUUID();
long timeJoined = System.currentTimeMillis();

try {
DashboardUser user = new DashboardUser(userId, email, hashedPassword, timeJoined);
StorageUtils.getDashboardStorage(storage).createNewDashboardUser(appIdentifier, user);
DashboardStorage dashboardStorage = StorageUtils.getDashboardStorage(storage);
WebRequestTelemetryHandler.INSTANCE.wrapInSpan(TenantIdentifier.BASE_TENANT,
"Creating user in dashboard storage",
Map.of("email", email), () -> {
try {
dashboardStorage.createNewDashboardUser(appIdentifier, user);
} catch (StorageQueryException | DuplicateUserIdException | DuplicateEmailException |
TenantOrAppNotFoundException e) {
throw new RuntimeException(e);
}
return null;
});

return user;
} catch (DuplicateUserIdException ignored) {
// we retry with a new userId (while loop)
} catch (RuntimeException runtimeException) {
if (runtimeException.getCause() instanceof DuplicateUserIdException) {
// we retry with a new userId (while loop)
} else if (runtimeException.getCause() instanceof StorageQueryException) {
throw (StorageQueryException) runtimeException.getCause();
} else if (runtimeException.getCause() instanceof DuplicateEmailException) {
throw (DuplicateEmailException) runtimeException.getCause();
} else if (runtimeException.getCause() instanceof TenantOrAppNotFoundException) {
throw (TenantOrAppNotFoundException) runtimeException.getCause();
} else {
throw runtimeException;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import io.supertokens.pluginInterface.oauth.OAuthStorage;
import io.supertokens.pluginInterface.oauth.exception.DuplicateOAuthLogoutChallengeException;
import io.supertokens.pluginInterface.oauth.exception.OAuthClientNotFoundException;
import io.supertokens.pluginInterface.opentelemetry.OtelProvider;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.PasswordlessImportUser;
Expand Down Expand Up @@ -202,7 +203,7 @@ public void assertThatConfigFromSameUserPoolIsNotConflicting(JsonObject otherCon
}

@Override
public void initFileLogging(String infoLogPath, String errorLogPath) {
public void initFileLogging(String infoLogPath, String errorLogPath, OtelProvider otelProvider) {
// no op
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/supertokens/output/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Logging(Main main) {
Storage storage = StorageLayer.getBaseStorage(main);
if (storage != null) {
storage.initFileLogging(Config.getBaseConfig(main).getInfoLogPath(main),
Config.getBaseConfig(main).getErrorLogPath(main));
Config.getBaseConfig(main).getErrorLogPath(main), TelemetryProvider.getInstance(main));
}
try {
// we wait here for a bit so that the loggers can be properly initialised..
Expand Down Expand Up @@ -114,7 +114,7 @@ public static void debug(Main main, TenantIdentifier tenantIdentifier, String ms
if (getInstance(main) != null) {
String formattedMsg = getFormattedMessage(tenantIdentifier, msg);
getInstance(main).infoLogger.debug(formattedMsg);
TelemetryProvider.createLogEvent(main, tenantIdentifier, formattedMsg, "debug");
TelemetryProvider.getInstance(main).createLogEvent(tenantIdentifier, formattedMsg, "debug");
}
} catch (NullPointerException e) {
// sometimes logger.debug throws a null pointer exception...
Expand Down Expand Up @@ -166,7 +166,7 @@ public static void info(Main main, TenantIdentifier tenantIdentifier, String msg
getInstance(main).infoLogger.info(msg);
}

TelemetryProvider.createLogEvent(main, tenantIdentifier, msg, "info");
TelemetryProvider.getInstance(main).createLogEvent(tenantIdentifier, msg, "info");
} catch (NullPointerException ignored) {
}
}
Expand All @@ -180,7 +180,7 @@ public static void warn(Main main, TenantIdentifier tenantIdentifier, String msg
msg = getFormattedMessage(tenantIdentifier, msg);
if (getInstance(main) != null) {
getInstance(main).errorLogger.warn(msg);
TelemetryProvider.createLogEvent(main, tenantIdentifier, msg, "warn");
TelemetryProvider.getInstance(main).createLogEvent(tenantIdentifier, msg, "warn");
}
} catch (NullPointerException ignored) {
}
Expand All @@ -202,7 +202,7 @@ public static void error(Main main, TenantIdentifier tenantIdentifier, String er
if (getInstance(main) != null) {
String formattedMessage = getFormattedMessage(tenantIdentifier, err);
getInstance(main).errorLogger.error(formattedMessage);
TelemetryProvider.createLogEvent(main, tenantIdentifier, formattedMessage, "error");
TelemetryProvider.getInstance(main).createLogEvent(tenantIdentifier, formattedMessage, "error");
}
if (toConsoleAsWell || getInstance(main) == null) {
systemErr(prependTenantIdentifierToMessage(tenantIdentifier, err));
Expand Down Expand Up @@ -236,8 +236,8 @@ public static void error(Main main, TenantIdentifier tenantIdentifier, String me
message = message.trim();
if (getInstance(main) != null) {
getInstance(main).errorLogger.error(getFormattedMessage(tenantIdentifier, message, e));
TelemetryProvider
.createLogEvent(main, tenantIdentifier, getFormattedMessage(tenantIdentifier, message, e),
TelemetryProvider.getInstance(main)
.createLogEvent(tenantIdentifier, getFormattedMessage(tenantIdentifier, message, e),
"error");
}
if (toConsoleAsWell || getInstance(main) == null) {
Expand Down
41 changes: 28 additions & 13 deletions src/main/java/io/supertokens/storageLayer/StorageLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.useridmapping.UserIdMapping;
import io.supertokens.telemetry.TelemetryProvider;
import io.supertokens.telemetry.WebRequestTelemetryHandler;
import io.supertokens.useridmapping.UserIdType;
import jakarta.servlet.ServletException;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -321,7 +323,8 @@ public static void loadAllTenantStorage(Main main, TenantConfig[] tenants)
new ArrayList<>(storageToTenantIdentifiersMap.get(((StorageLayer) resource).storage)));
((StorageLayer) resource).storage.initFileLogging(
Config.getBaseConfig(main).getInfoLogPath(main),
Config.getBaseConfig(main).getErrorLogPath(main));
Config.getBaseConfig(main).getErrorLogPath(main),
TelemetryProvider.getInstance(main));
} catch (DbInitException e) {

Logging.error(main, TenantIdentifier.BASE_TENANT, e.getMessage(), false, e);
Expand Down Expand Up @@ -427,20 +430,32 @@ public static Storage[] getStoragesForApp(Main main, AppIdentifier appIdentifier
throws TenantOrAppNotFoundException {
Map<String, Storage> userPoolToStorage = new HashMap<>();

Map<ResourceDistributor.KeyClass, ResourceDistributor.SingletonResource> resources =
main.getResourceDistributor()
.getAllResourcesWithResourceKey(RESOURCE_KEY);
for (ResourceDistributor.KeyClass key : resources.keySet()) {
Storage storage = ((StorageLayer) resources.get(key)).storage;
if (key.getTenantIdentifier().toAppIdentifier().equals(appIdentifier)) {
userPoolToStorage.put(storage.getUserPoolId(), storage);
try {
return WebRequestTelemetryHandler.INSTANCE.wrapInSpan(appIdentifier.getAsPublicTenantIdentifier(),
"StorageLayer getStoragesForApp",
Map.of(), () -> {
Map<ResourceDistributor.KeyClass, ResourceDistributor.SingletonResource> resources =
main.getResourceDistributor()
.getAllResourcesWithResourceKey(RESOURCE_KEY);
for (ResourceDistributor.KeyClass key : resources.keySet()) {
Storage storage = ((StorageLayer) resources.get(key)).storage;
if (key.getTenantIdentifier().toAppIdentifier().equals(appIdentifier)) {
userPoolToStorage.put(storage.getUserPoolId(), storage);
}
}
Storage[] storages = userPoolToStorage.values().toArray(new Storage[0]);
if (storages.length == 0) {
throw new RuntimeException(new TenantOrAppNotFoundException(appIdentifier));
}
return storages;
});
} catch (RuntimeException e) {
if (e.getCause() instanceof TenantOrAppNotFoundException) {
throw (TenantOrAppNotFoundException) e.getCause();
} else {
throw new RuntimeException(e);
}
}
Storage[] storages = userPoolToStorage.values().toArray(new Storage[0]);
if (storages.length == 0) {
throw new TenantOrAppNotFoundException(appIdentifier);
}
return storages;
}

public static StorageAndUserIdMapping findStorageAndUserIdMappingForUser(
Expand Down
Loading