Skip to content

Commit

Permalink
Add metrics logs provider configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NipunaMadhushan committed Nov 19, 2024
1 parent ec729fd commit d646d6e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ballerina/commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ configurable string metricsReporter = "";
configurable boolean tracingEnabled = false;
configurable string tracingProvider = "";
configurable boolean metricsLogsEnabled = false;
configurable string metricsLogsProvider = "";

function init() returns error? {
boolean isMissingMetricsReporter = ((enabled || metricsEnabled) && (provider == "" && metricsReporter == ""));
boolean isMissingTracingProvider = ((enabled || tracingEnabled) && (provider == "" && tracingProvider == ""));
if (isMissingMetricsReporter || isMissingTracingProvider) {
boolean isMissingMetricsLogsProvider = ((enabled || metricsLogsEnabled) && (provider == "" && metricsLogsProvider == ""));
if (isMissingMetricsReporter || isMissingTracingProvider || isMissingMetricsLogsProvider) {
string[] enabledObservers = [];
string[] missingProviders = [];
if (isMissingMetricsReporter) {
Expand All @@ -39,6 +41,10 @@ function init() returns error? {
enabledObservers.push("tracing");
missingProviders.push("tracing provider");
}
if (isMissingMetricsLogsProvider) {
enabledObservers.push("metrics logs");
missingProviders.push("metrics logs provider");
}
return error("Observability (" + " and ".join(...enabledObservers) + ") enabled without " +
" and ".join(...missingProviders) + ". Please visit https://central.ballerina.io/ballerina/observe for " +
"the list of officially supported Observability providers.");
Expand All @@ -61,13 +67,27 @@ public isolated function isMetricsEnabled() returns boolean = @java:Method {
'class: "io.ballerina.runtime.observability.ObserveUtils"
} external;

# Check whether metrics logs is enabled.
# + return - metrics enabled/disabled.
public isolated function isMetricsLogsEnabled() returns boolean = @java:Method {
name: "isMetricsLogsEnabled",
'class: "io.ballerina.runtime.observability.ObserveUtils"
} external;

# Retrieve metrics provider.
# + return - metrics provider.
public isolated function getMetricsProvider() returns string = @java:Method {
name: "getMetricsProvider",
'class: "io.ballerina.runtime.observability.ObserveUtils"
} external;

# Retrieve metrics logs provider.
# + return - metrics logs provider.
public isolated function getMetricsLogsProvider() returns string = @java:Method {
name: "getMetricsLogsProvider",
'class: "io.ballerina.runtime.observability.ObserveUtils"
} external;

# Retrieve metrics reporter.
# + return - metrics reporter.
public isolated function getMetricsReporter() returns string = @java:Method {
Expand Down

0 comments on commit d646d6e

Please sign in to comment.