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

Chore: added heartbeat for monitoring #36704

Merged
merged 1 commit into from
Oct 9, 2024
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
34 changes: 34 additions & 0 deletions app/client/src/Heartbeat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect } from "react";
import log from "loglevel";
const Heartbeat = () => {
const heartbeatUrl =
ApekshaBhosale marked this conversation as resolved.
Show resolved Hide resolved
"https://uptime.betterstack.com/api/v1/heartbeat/71SZmsvAVW73QvEPQzLvxwEL";
const interval = 30 * 1000; // 30 secs in milliseconds
ApekshaBhosale marked this conversation as resolved.
Show resolved Hide resolved

const sendHeartbeat = async () => {
try {
const response = await fetch(heartbeatUrl);

if (response.ok) {
log.info("Heartbeat sent successfully");
} else {
log.error("Failed to send heartbeat", response.status);
}
} catch (error) {
log.error("Error sending heartbeat:", error);
}
};
ApekshaBhosale marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const heartbeatInterval = setInterval(() => {
sendHeartbeat();
}, interval);

// Cleanup the interval when the component is unmounted
return () => clearInterval(heartbeatInterval);
}, []); // Empty dependency array ensures this runs once on mount

return null; // This component doesn't render anything
};

export default Heartbeat;
7 changes: 6 additions & 1 deletion app/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PageViewTiming } from "@newrelic/browser-agent/features/page_view_timin
import { PageViewEvent } from "@newrelic/browser-agent/features/page_view_event";
import { Agent } from "@newrelic/browser-agent/loaders/agent";
import { getCommonTelemetryAttributes } from "UITelemetry/generateTraces";

import Heartbeat from "Heartbeat";
const { newRelic } = getAppsmithConfigs();
const { enableNewRelic } = newRelic;

Expand Down Expand Up @@ -73,8 +73,12 @@ if (enableNewRelic) {
newRelicBrowserAgent.setCustomAttribute("appMode", appMode);
}

const { cloudHosting } = getAppsmithConfigs();

const shouldAutoFreeze = process.env.NODE_ENV === "development";

const isProduction = process.env.NODE_ENV === "production";

setAutoFreeze(shouldAutoFreeze);
runSagaMiddleware();

Expand All @@ -96,6 +100,7 @@ function App() {
<Sentry.ErrorBoundary fallback={"An error has occured"}>
<Provider store={store}>
<LayersContext.Provider value={Layers}>
{cloudHosting && isProduction && <Heartbeat />}
<ThemedAppWithProps />
</LayersContext.Provider>
</Provider>
Expand Down
Loading