Skip to content

Commit

Permalink
chore: remove sentry-nextjs (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Oct 8, 2024
1 parent c9a931c commit 5aec8ab
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 1,413 deletions.
1 change: 0 additions & 1 deletion packages/ui/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@radix-ui/react-tooltip": "^1.1.2",
"@radix-ui/react-visually-hidden": "^1.1.0",
"@segment/snippet": "^5.2.1",
"@sentry/nextjs": "^8.30.0",
"@shikijs/transformers": "^1.2.2",
"@types/nprogress": "^0.2.3",
"algoliasearch": "^4.24.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/app/src/analytics/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { Router } from "next/router";
import type { PostHog } from "posthog-js";
import { useEffect } from "react";
import { useApiRoute } from "../hooks/useApiRoute";
import { safeCall } from "./sentry";

export function safeCall(action: () => void): void {
try {
return action();
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
}

/**
* Posthog natively allows us to define additional capture objects with distinct configs on the global instance,
Expand Down
40 changes: 0 additions & 40 deletions packages/ui/app/src/analytics/sentry.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { unknownToString, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { captureSentryError } from "../../analytics/sentry";
import { HttpRequestExample } from "./HttpRequestExample";

function requiresUrlEncode(str: string): boolean {
Expand All @@ -10,15 +9,12 @@ export function stringifyHttpRequestExampleToCurl(request: HttpRequestExample):
try {
return unsafeStringifyHttpRequestExampleToCurl(request);
} catch (e) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error(e);

captureSentryError(e, {
context: "ApiPage",
errorSource: "unsafeStringifyHttpRequestExampleToCurl",
errorDescription:
"Unable to stringify HTTP request example to curl. This is used to generate a curl command for the user to copy and paste into their terminal. When this fails, the user will not be able to see the curl command.",
});
console.error(
"Unable to stringify HTTP request example to curl. This is used to generate a curl command for the user to copy and paste into their terminal. When this fails, the user will not be able to see the curl command.",
e,
);

return "";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isPlainObject } from "@fern-ui/core-utils";
import { captureException } from "@sentry/nextjs";
import jsonpath from "jsonpath";
import { useMemo } from "react";
import { JsonPropertyPath, JsonPropertyPathPart } from "./JsonPropertyPath";
Expand Down Expand Up @@ -104,7 +103,9 @@ export function useHighlightJsonLines(
try {
return getJsonLineNumbers(json, hoveredPropertyPath, jsonStartLine + 1);
} catch (error) {
captureException(error);
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Error thrown while highlighting json lines", error);
return [];
}
}, [hoveredPropertyPath, json, jsonStartLine]);
Expand Down
9 changes: 6 additions & 3 deletions packages/ui/app/src/atoms/playground.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { useEventCallback } from "@fern-ui/react-commons";
import { captureMessage } from "@sentry/nextjs";
import { WritableAtom, atom, useAtom, useAtomValue, useSetAtom } from "jotai";
import { atomFamily, atomWithStorage, useAtomCallback } from "jotai/utils";
import { Dispatch, SetStateAction, useEffect } from "react";
Expand Down Expand Up @@ -270,7 +269,9 @@ export function useSetAndOpenPlayground(): (node: FernNavigation.NavigationNodeA
const context = createEndpointContext(node, definition);

if (context == null) {
captureMessage("Could not find endpoint for API playground selection state", "fatal");
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Could not find endpoint for API playground selection state");
return;
}

Expand All @@ -282,7 +283,9 @@ export function useSetAndOpenPlayground(): (node: FernNavigation.NavigationNodeA
const context = createWebSocketContext(node, definition);

if (context == null) {
captureMessage("Could not find websocket for API playground selection state", "fatal");
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Could not find websocket for API playground selection state");
playgroundFormStateFamily.remove(node.id);
return;
}
Expand Down
16 changes: 7 additions & 9 deletions packages/ui/app/src/components/FernErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { memoize } from "lodash-es";
import { Router, useRouter } from "next/router";
import React, { PropsWithChildren, ReactElement, useEffect } from "react";
import { ErrorBoundary, FallbackProps } from "react-error-boundary";
import { captureSentryError, captureSentryErrorMessage } from "../analytics/sentry";
import { useIsLocalPreview } from "../contexts/local-preview";

export declare interface FernErrorBoundaryProps {
Expand Down Expand Up @@ -37,15 +36,13 @@ export function FernErrorTag({
}): ReactElement | null {
const isLocalPreview = useIsLocalPreview();
useEffect(() => {
// TODO: sentry
// eslint-disable-next-line no-console
console.error(error);
captureSentryError(error, {
context: component,
errorSource: "FernErrorTag",
errorDescription:
errorDescription ??
console.error(
errorDescription ??
"An unknown UI error occurred. This could be a critical user-facing error that should be investigated.",
});
error,
);
}, [component, error, errorDescription]);

// if local preview, always show the error tag for markdown errors
Expand Down Expand Up @@ -99,8 +96,9 @@ const FernErrorBoundaryInternal: React.FC<FernErrorBoundaryProps> = ({

useEffect(() => {
if (refreshOnError) {
// TODO: sentry
// eslint-disable-next-line no-console
captureSentryErrorMessage("Fern Docs crashed. Reloading the page might fix the issue.");
console.error("Fern Docs crashed. Reloading the page might fix the issue.");
router.reload();
}
}, [refreshOnError, router]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fastdom from "fastdom";
import { useAtomValue } from "jotai";
import { useEffect, useRef } from "react";
import { useCallbackOne } from "use-memo-one";
import { captureSentryError } from "../../analytics/sentry";
import { SCROLL_BODY_ATOM } from "../../atoms";

function toIdQuerySelector(id: string): string {
Expand Down Expand Up @@ -120,7 +119,9 @@ export function useTableOfContentsObserver(ids: string[], setActiveId: (id: stri
return prev;
}, {});
} catch (e) {
captureSentryError(e, { errorDescription: "Error measuring table of contents" });
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Error measuring table of contents", e);
}
});

Expand Down
10 changes: 2 additions & 8 deletions packages/ui/app/src/mdx/bundlers/next-mdx-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import remarkSmartypants from "remark-smartypants";
import type { PluggableList } from "unified";
import { captureSentryError } from "../../analytics/sentry";
import { stringHasMarkdown } from "../common/util";
import { FernDocsFrontmatter } from "../frontmatter";
import { rehypeFernCode } from "../plugins/rehypeFernCode";
Expand Down Expand Up @@ -117,14 +116,9 @@ export async function serializeMdx(
scope: {},
};
} catch (e) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error(e);

captureSentryError(e, {
context: "MDX",
errorSource: "maybeSerializeMdxContent",
errorDescription: "Failed to serialize MDX content",
});
console.error("Failed to serialize MDX content", e);

return content;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { captureException } from "@sentry/nextjs";
import { atom, useAtomValue } from "jotai";
import { loadable } from "jotai/utils";
import * as LDClient from "launchdarkly-js-client-sdk";
Expand Down Expand Up @@ -35,7 +34,7 @@ const useLaunchDarklyFlag = (flag: string): boolean => {
const loadableClient = useAtomValue(loadable(ldClientAtom));
const client = loadableClient.state === "hasData" ? loadableClient.data : undefined;
if (loadableClient.state === "hasError") {
captureException(loadableClient.error);
// TODO: sentry
}

const getFlagEnabled = useCallback(() => {
Expand Down
20 changes: 5 additions & 15 deletions packages/ui/app/src/playground/endpoint/PlaygroundEndpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { SendSolid } from "iconoir-react";
import { useSetAtom } from "jotai";
import { mapValues } from "lodash-es";
import { ReactElement, useCallback, useState } from "react";
import { captureSentryError } from "../../analytics/sentry";
import {
PLAYGROUND_AUTH_STATE_ATOM,
PLAYGROUND_AUTH_STATE_OAUTH_ATOM,
Expand Down Expand Up @@ -159,22 +158,13 @@ export const PlaygroundEndpoint = ({ context }: { context: EndpointContext }): R
}
}
} catch (e) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error(e);
console.error(
"An unexpected error occurred while sending request to the proxy server. This is likely a bug, rather than a user error.",
e,
);
setResponse(failed(e));

captureSentryError(e, {
context: "ApiPlayground",
errorSource: "sendRequest",
errorDescription:
"An unexpected error occurred while sending request to the proxy server. This is likely a bug, rather than a user error.",
data: {
endpointId: endpoint.id,
endpointName: node.title,
method: endpoint.method,
route: `/${node.slug}`,
},
});
}
}, [
endpoint,
Expand Down
7 changes: 3 additions & 4 deletions packages/ui/app/src/resolver/ApiDefinitionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { DocsV1Read } from "@fern-api/fdr-sdk";
import type * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { isNonNullish, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { FernRegistry } from "../../../../fdr-sdk/src/client/generated";
import { captureSentryErrorMessage } from "../analytics/sentry";
import type { FeatureFlags } from "../atoms";
import { type MDX_SERIALIZER } from "../mdx/bundler";
import type { FernSerializeMdxOptions } from "../mdx/types";
Expand Down Expand Up @@ -151,9 +150,9 @@ export class ApiDefinitionResolver {
},
endpointPair: async (endpointPair) => {
if (this.featureFlags.isBatchStreamToggleDisabled) {
captureSentryErrorMessage(
"Batch stream toggle is disabled, but an endpoint pair was found",
);
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Batch stream toggle is disabled, but an endpoint pair was found");
}
const [nonStream, stream] = await Promise.all([
this.resolveEndpointDefinitionCached(endpointPair.nonStream),
Expand Down
14 changes: 5 additions & 9 deletions packages/ui/app/src/resolver/ApiEndpointResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { APIV1Read } from "@fern-api/fdr-sdk/client/types";
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { compact, mapValues } from "lodash-es";
import { captureSentryError } from "../analytics/sentry";
import { sortKeysByShape } from "../api-reference/examples/sortKeysByShape";
import type { FeatureFlags } from "../atoms";
import { MDX_SERIALIZER } from "../mdx/bundler";
Expand Down Expand Up @@ -755,15 +754,12 @@ export class ApiEndpointResolver {
try {
return this.stripUndefines(sortKeysByShape(value, shape, this.resolvedTypes));
} catch (e) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Failed to sort JSON keys by type shape", e);

captureSentryError(e, {
context: "ApiPage",
errorSource: "sortKeysByShape",
errorDescription:
"Failed to sort and strip undefines from JSON value, indicating a bug in the resolver. This error should be investigated.",
});
console.error(
"Failed to sort and strip undefines from JSON value, indicating a bug in the resolver. This error should be investigated.",
e,
);

return value;
}
Expand Down
12 changes: 5 additions & 7 deletions packages/ui/app/src/search/SearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useAtomValue, useSetAtom } from "jotai";
import dynamic from "next/dynamic";
import { PropsWithChildren, ReactElement, useMemo, useRef } from "react";
import { Configure, InstantSearch } from "react-instantsearch";
import { captureSentryError } from "../analytics/sentry";
import {
CURRENT_VERSION_ATOM,
IS_MOBILE_SCREEN_ATOM,
Expand Down Expand Up @@ -37,12 +36,11 @@ export const SearchDialog = (): ReactElement | null => {
const [config] = useSearchConfig();

if (!config.isAvailable) {
isSearchDialogOpen &&
captureSentryError(new Error("Search dialog config is null"), {
context: "SearchDialogOpen",
errorSource: "SearchDialog",
errorDescription: "Search dialog is null, when attempting to use search.",
});
if (isSearchDialogOpen) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Search dialog is null, when attempting to use search.");
}
return null;
}

Expand Down
18 changes: 7 additions & 11 deletions packages/ui/app/src/search/algolia/AlgoliaSearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Dialog from "@radix-ui/react-dialog";
import { SearchClient } from "algoliasearch";
import clsx from "clsx";
import { useAtomValue, useSetAtom } from "jotai";
import { ReactElement, useMemo, useRef } from "react";
import { ReactElement, ReactNode, useMemo, useRef } from "react";
import { Configure, InstantSearch, useInstantSearch } from "react-instantsearch";
import {
CURRENT_VERSION_ATOM,
Expand All @@ -14,6 +14,7 @@ import {
useIsSearchDialogOpen,
useSidebarNodes,
} from "../../atoms";
import { getFeatureFlagFilters } from "../../util/getFeatureFlagFilters";
import { SearchHits } from "../SearchHits";
import { SearchBox } from "./SearchBox";
import { useAlgoliaSearchClient } from "./useAlgoliaSearchClient";
Expand All @@ -27,12 +28,11 @@ export function AlgoliaSearchDialog(): ReactElement | null {
const setSearchDialogState = useSetAtom(SEARCH_DIALOG_OPEN_ATOM);
const algoliaSearchClient = useAlgoliaSearchClient();
if (algoliaSearchClient == null || isMobileScreen) {
algoliaSearchClient == null &&
captureSentryError(new Error("Algolia search client is null"), {
context: "AlgoliaSearchClient",
errorSource: "AlgoliaSearchDialog",
errorDescription: "Algolia search client is null, when attempting to use search.",
});
if (!isMobileScreen) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error("Algolia search client is null, when attempting to use search.");
}
return null;
}
const [searchClient, index] = algoliaSearchClient;
Expand All @@ -59,10 +59,6 @@ interface FernInstantSearchProps {
inputRef: React.RefObject<HTMLInputElement>;
}

import { ReactNode } from "react";
import { captureSentryError } from "../../analytics/sentry";
import { getFeatureFlagFilters } from "../../util/getFeatureFlagFilters";

function NoResultsBoundary({ children, fallback }: { children: ReactNode; fallback: ReactNode }) {
const { results } = useInstantSearch();

Expand Down
Loading

0 comments on commit 5aec8ab

Please sign in to comment.