Skip to content
Merged
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 workspaces/ballerina/ballerina-extension/src/utils/bi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ generated/
# Contains configuration values used during development time.
# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details.
Config.toml

# File used to enable development-time tracing.
# This should not be committed to version control.
trace_enabled.bal
`;

export function getUsername(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export function DiagramWrapper(param: DiagramWrapperProps) {
const [functionModel, setFunctionModel] = useState<FunctionModel>();
const [servicePosition, setServicePosition] = useState<NodePosition>();
const [isSaving, setIsSaving] = useState(false);
const [isTracingEnabled, setIsTracingEnabled] = useState(false);
const [isToggling, setIsToggling] = useState(false);

useEffect(() => {
rpcClient.getVisualizerLocation().then((location) => {
Expand Down Expand Up @@ -164,6 +166,37 @@ export function DiagramWrapper(param: DiagramWrapperProps) {
}, [rpcClient]);


useEffect(() => {
checkTracingStatus();
}, []);

const checkTracingStatus = async () => {
try {
const status = await rpcClient.getAgentChatRpcClient().getTracingStatus();
setIsTracingEnabled(status.enabled);
} catch (error) {
setIsTracingEnabled(false);
}
};

const handleToggleTracing = async () => {
if (isToggling) {
return;
}

setIsToggling(true);
try {
const command = isTracingEnabled ? "ballerina.disableTracing" : "ballerina.enableTracing";
await rpcClient.getCommonRpcClient().executeCommand({ commands: [command] });
await checkTracingStatus();
} catch (error) {
console.error("Failed to toggle tracing:", error);
throw error;
} finally {
setIsToggling(false);
}
};

const handleFunctionClose = () => {
setFunctionModel(undefined);
};
Expand Down Expand Up @@ -269,25 +302,44 @@ export function DiagramWrapper(param: DiagramWrapperProps) {

// Calculate actions based on conditions
const getActions = () => {
const tracingButton = (
<ActionButton
appearance={isTracingEnabled ? "primary" : "secondary"}
onClick={handleToggleTracing}
disabled={isToggling}
>
<Icon
name={isTracingEnabled ? "telescope" : "circle-slash"}
isCodicon={true}
sx={{ marginRight: 5, width: 16, height: 16, fontSize: 14 }}
/>
{isTracingEnabled ? "Tracing: On" : "Tracing: Off"}
</ActionButton>
);

if (isAgent) {
return (
<ActionButton
appearance="secondary"
onClick={() => handleResourceTryIt(parentMetadata?.accessor || "", parentMetadata?.label || "")}
>
<Icon
name="comment-discussion"
isCodicon={true}
sx={{ marginRight: 5, width: 16, height: 16, fontSize: 14 }}
/>
Chat
</ActionButton>
<>
{tracingButton}
<ActionButton
appearance="secondary"
onClick={() => handleResourceTryIt(parentMetadata?.accessor || "", parentMetadata?.label || "")}
>
<Icon
name="comment-discussion"
isCodicon={true}
sx={{ marginRight: 5, width: 16, height: 16, fontSize: 14 }}
/>
Chat
</ActionButton>
</>
);
}

if (isResource && serviceType === "http") {
return (
<>
{tracingButton}
<ActionButton id="bi-edit" appearance="secondary" onClick={() => getFunctionModel()}>
<Icon
name="bi-settings"
Expand Down
Loading