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

Add metrics logs observer #120

Merged
12 changes: 12 additions & 0 deletions ballerina/init.bal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function init() {
externPrintError("failed to enable tracing");
}
}

if (observe:isMetricsLogsEnabled()) {
var err = externEnableMetricsLogging(observe:getMetricsLogsProvider());
if (err is error) {
externPrintError("failed to enable tracing");
}
}
}

function externEnableMetrics(string provider) returns error? = @java:Method {
Expand All @@ -43,6 +50,11 @@ function externEnableTracing(string provider) returns error? = @java:Method {
name: "enableTracing"
} external;

function externEnableMetricsLogging(string provider) returns error? = @java:Method {
'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
name: "enableMetricsLogging"
} external;

function externPrintError(string message) = @java:Method {
'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
name: "printError"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/
package io.ballerina.stdlib.observe.internal;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.observability.ObserveUtils;
import io.ballerina.runtime.observability.metrics.BallerinaMetricsLogsObserver;
import io.ballerina.runtime.observability.metrics.BallerinaMetricsObserver;
import io.ballerina.runtime.observability.metrics.DefaultMetricRegistry;
import io.ballerina.runtime.observability.metrics.MetricRegistry;
Expand Down Expand Up @@ -94,6 +96,15 @@ public static BError enableTracing(BString providerName) {
}
}

public static BError enableMetricsLogging(Environment env, BString providerName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Return type should be Object

try {
ObserveUtils.addObserver(new BallerinaMetricsLogsObserver(env));
return null;
} catch (BError e) {
return e;
}
}

public static void printError(BString message) {
errStream.println("error: " + message.getValue());
}
Expand Down
Loading