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 log pipeline - populate logs into kusto #170

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## placeholder
* Update sdk loggin logics so all level logs are recored into kusto. ([#170](https://github.com/microsoft/durabletask-java/pull/170))

## v1.4.0

### Updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.microsoft.durabletask.implementation.protobuf.OrchestratorService.WorkItem.RequestCase;
import com.microsoft.durabletask.implementation.protobuf.TaskHubSidecarServiceGrpc.*;

import com.microsoft.durabletask.log.LoggerManager;
import io.grpc.*;

import java.time.Duration;
Expand All @@ -22,7 +23,7 @@
*/
public final class DurableTaskGrpcWorker implements AutoCloseable {
private static final int DEFAULT_PORT = 4001;
private static final Logger logger = Logger.getLogger(DurableTaskGrpcWorker.class.getPackage().getName());
private static final Logger logger = LoggerManager.getLogger();
private static final Duration DEFAULT_MAXIMUM_TIMER_INTERVAL = Duration.ofDays(3);

private final HashMap<String, TaskOrchestrationFactory> orchestrationFactories = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.StringValue;
import com.microsoft.durabletask.implementation.protobuf.OrchestratorService;
import com.microsoft.durabletask.log.LoggerManager;

import java.time.Duration;
import java.util.Base64;
Expand All @@ -18,7 +19,7 @@
* caller must provide orchestration state as serialized protobuf bytes.
*/
public final class OrchestrationRunner {
private static final Logger logger = Logger.getLogger(OrchestrationRunner.class.getPackage().getName());
private static final Logger logger = LoggerManager.getLogger();
private static final Duration DEFAULT_MAXIMUM_TIMER_INTERVAL = Duration.ofDays(3);

private OrchestrationRunner() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.microsoft.durabletask.log;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

class FunctionKustoHandler extends Handler {
private static final String FUNCTIONSKUSTOPREFIX = "LanguageWorkerConsoleLog";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core logging abstractions can be in durabletask-client but anything specific to the either Kusto or Functions should instead go into the durabletask-azure-functions package. This is very important because durabletask-client will also be used outside of Azure by Dapr OSS customers, and we don't want to add any Azure-specific logic or dependencies for those users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

private static final String DURABLEPREFIX = "DURABLE_JAVA_SDK";
@Override
public void publish(LogRecord record) {
if (record != null && record.getLevel() != null) {
PrintStream output = record.getLevel().intValue() <= Level.INFO.intValue() ? System.out : System.err;
output.printf("%s%s [%s] {%s.%s}: %s%n",
FUNCTIONSKUSTOPREFIX,
DURABLEPREFIX,
record.getLevel(),
record.getSourceClassName(),
record.getSourceMethodName(),
record.getMessage());
if (record.getThrown() != null) {
output.printf("%s%s%s%n", FUNCTIONSKUSTOPREFIX, DURABLEPREFIX, Arrays.toString(record.getThrown().getStackTrace()));
}
}
}

@Override
public void flush() {
System.out.flush();
System.err.flush();
}

@Override
public void close() throws SecurityException { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.microsoft.durabletask.log;

import java.util.logging.*;

public class LoggerManager {
private static final Logger logger = initLogger();

private static Logger initLogger() {
Logger logger = Logger.getAnonymousLogger();
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
logger.addHandler(new FunctionKustoHandler());
return logger;
}

public static void setHandler(Handler handler) {
clearHandler();
addHandler(handler);
}

public static void addHandler(Handler handler) {
logger.addHandler(handler);
}

private static void clearHandler() {
for (Handler handler : logger.getHandlers()) {
logger.removeHandler(handler);
}
}

public static Logger getLogger() {
return logger;
}
}
Loading