SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(license-section): add section to view license key (#10039)
aniketio-ctrlf17a332c23d2
diff --git a/frontend/src/container/MySettings/LicenseSection/LicenseSection.styles.scss b/frontend/src/container/MySettings/LicenseSection/LicenseSection.styles.scssnew file mode 100644index 0000000000..0ad4957b8d--- /dev/null+++ b/frontend/src/container/MySettings/LicenseSection/LicenseSection.styles.scss@@ -0,0 +1,84 @@+.license-section {+ display: flex;+ flex-direction: column;+ gap: 16px;++ .license-section-header {+ display: flex;+ flex-direction: column;+ gap: 4px;++ .license-section-title {+ color: #fff;+ font-family: Inter;+ font-size: 16px;+ font-style: normal;+ line-height: 24px;+ letter-spacing: -0.08px;+ }+ }++ .license-section-content {+ display: flex;+ flex-direction: column;+ gap: 16px;++ .license-section-content-item {+ padding: 16px;+ border: 1px solid var(--Slate-500, #161922);+ background: var(--Ink-400, #121317);+ border-radius: 3px;++ .license-section-content-item-title-action {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 8px;++ color: var(--Vanilla-300, #eee);+ font-family: Inter;+ font-size: 14px;+ font-style: normal;+ font-weight: 500;+ line-height: normal;+ letter-spacing: -0.07px;++ margin-bottom: 8px;+ }++ .license-section-content-item-description {+ color: var(--Vanilla-400, #c0c1c3);+ font-family: Inter;+ font-size: 12px;+ font-style: normal;+ line-height: 20px;+ letter-spacing: -0.07px;+ }+ }+ }+}++.lightMode {+ .license-section {+ .license-section-header {+ .license-section-title {+ color: var(--bg-ink-400);+ }+ }++ .license-section-content {+ .license-section-content-item {+ border: 1px solid var(--bg-vanilla-300);+ background: var(--bg-vanilla-100);++ .license-section-content-item-title-action {+ color: var(--bg-ink-400);+ }++ .license-section-content-item-description {+ color: var(--bg-ink-300);+ }+ }+ }+ }+}diff --git a/frontend/src/container/MySettings/LicenseSection/LicenseSection.tsx b/frontend/src/container/MySettings/LicenseSection/LicenseSection.tsxnew file mode 100644index 0000000000..b691674679--- /dev/null+++ b/frontend/src/container/MySettings/LicenseSection/LicenseSection.tsx@@ -0,0 +1,65 @@+import './LicenseSection.styles.scss';++import { Button } from '@signozhq/button';+import { Typography } from 'antd';+import { useNotifications } from 'hooks/useNotifications';+import { Copy } from 'lucide-react';+import { useAppContext } from 'providers/App/App';+import { useCopyToClipboard } from 'react-use';++function LicenseSection(): JSX.Element | null {+ const { activeLicense } = useAppContext();+ const { notifications } = useNotifications();+ const [, handleCopyToClipboard] = useCopyToClipboard();++ const getMaskedKey = (key: string): string => {+ if (!key || key.length < 4) return key || 'N/A';+ return `${key.substring(0, 2)}********${key+ .substring(key.length - 2)+ .trim()}`;+ };++ const handleCopyKey = (text: string): void => {+ handleCopyToClipboard(text);+ notifications.success({+ message: 'Copied to clipboard',+ });+ };++ if (!activeLicense?.key) {+ return <></>;+ }++ return (+ <div className="license-section">+ <div className="license-section-header">+ <div className="license-section-title">License</div>+ </div>++ <div className="license-section-content">+ <div className="license-section-content-item">+ <div className="license-section-content-item-title-action">+ <span>License key</span>+ <span style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>+ <Typography.Text code>{getMaskedKey(activeLicense.key)}</Typography.Text>+ <Button+ variant="ghost"+ aria-label="Copy license key"+ data-testid="license-key-copy-btn"+ onClick={(): void => handleCopyKey(activeLicense.key)}+ >+ <Copy size={14} />+ </Button>+ </span>+ </div>++ <div className="license-section-content-item-description">+ Your SigNoz license key.+ </div>+ </div>+ </div>+ </div>+ );+}++export default LicenseSection;diff --git a/frontend/src/container/MySettings/LicenseSection/index.ts b/frontend/src/container/MySettings/LicenseSection/index.tsnew file mode 100644index 0000000000..c6984816db--- /dev/null+++ b/frontend/src/container/MySettings/LicenseSection/index.ts@@ -0,0 +1 @@+export { default } from './LicenseSection';diff --git a/frontend/src/container/MySettings/__tests__/MySettings.test.tsx b/frontend/src/container/MySettings/__tests__/MySettings.test.tsxindex 2802ea7e2d..a06d52b4fb 100644--- a/frontend/src/container/MySettings/__tests__/MySettings.test.tsx+++ b/frontend/src/container/MySettings/__tests__/MySettings.test.tsx@@ -1,8 +1,31 @@+import userEvent from '@testing-library/user-event';import MySettingsContainer from 'container/MySettings';-import { act, fireEvent, render, screen, waitFor } from 'tests/test-utils';+import {+ act,+ fireEvent,+ render,+ screen,+ waitFor,+ within,+} from 'tests/test-utils';const toggleThemeFunction = jest.fn();const logEventFunction = jest.fn();+const copyToClipboardFn = jest.fn();+const editUserFn = jest.fn();++jest.mock('react-use', () => ({+ __esModule: true,+ useCopyToClipboard: (): [unknown, (text: string) => void] => [+ null,+ copyToClipboardFn,+ ],+}));++jest.mock('api/v1/user/id/update', () => ({+ __esModule: true,+ default: (...args: unknown[]): Promise<unknown> => editUserFn(...args),+}));jest.mock('hooks/useDarkMode', () => ({__esModule: true,@@ -44,6 +67,7 @@ const PASSWORD_VALIDATION_MESSAGE_TEST_ID = 'password-validation-message';describe('MySettings Flows', () => {beforeEach(() => {jest.clearAllMocks();+ editUserFn.mockResolvedValue({});render(<MySettingsContainer />);});@@ -215,4 +239,71 @@ describe('MySettings Flows', () => {expect(submitButton).not.toBeDisabled();});});++ describe('License section', () => {+ it('Should render license section content when license key exists', () => {+ expect(screen.getByText('License')).toBeInTheDocument();+ expect(screen.getByText('License key')).toBeInTheDocument();+ expect(screen.getByText('Your SigNoz license key.')).toBeInTheDocument();+ });++ it('Should not render license section when license key is missing', () => {+ const { container } = render(<MySettingsContainer />, undefined, {+ appContextOverrides: {+ activeLicense: null,+ },+ });++ const scoped = within(container);+ expect(scoped.queryByText('License')).not.toBeInTheDocument();+ expect(scoped.queryByText('License key')).not.toBeInTheDocument();+ expect(+ scoped.queryByText('Your SigNoz license key.'),+ ).not.toBeInTheDocument();+ });++ it('Should mask license key in the UI', () => {+ const { container } = render(<MySettingsContainer />, undefined, {+ appContextOverrides: {+ activeLicense: {+ key: 'abcd',+ } as any,+ },+ });++ expect(within(container).getByText('ab********cd')).toBeInTheDocument();+ });++ it('Should not mask license key if it is too short', () => {+ const { container } = render(<MySettingsContainer />, undefined, {+ appContextOverrides: {+ activeLicense: {+ key: 'abc',+ } as any,+ },+ });++ expect(within(container).getByText('abc')).toBeInTheDocument();+ });++ it('Should copy license key and show success toast', async () => {+ const user = userEvent.setup();+ const { container } = render(<MySettingsContainer />, undefined, {+ appContextOverrides: {+ activeLicense: {+ key: 'test-license-key-12345',+ } as any,+ },+ });++ await user.click(within(container).getByTestId('license-key-copy-btn'));++ await waitFor(() => {+ expect(copyToClipboardFn).toHaveBeenCalledWith('test-license-key-12345');+ expect(successNotification).toHaveBeenCalledWith({+ message: 'Copied to clipboard',+ });+ });+ });+ });});diff --git a/frontend/src/container/MySettings/index.tsx b/frontend/src/container/MySettings/index.tsxindex d5b779c362..b8dd8d9ef0 100644--- a/frontend/src/container/MySettings/index.tsx+++ b/frontend/src/container/MySettings/index.tsx@@ -15,6 +15,7 @@ import { useMutation } from 'react-query';import { UserPreference } from 'types/api/preferences/preference';import { showErrorNotification } from 'utils/error';+import LicenseSection from './LicenseSection';import TimezoneAdaptation from './TimezoneAdaptation/TimezoneAdaptation';import UserInfo from './UserInfo';@@ -230,6 +231,8 @@ function MySettings(): JSX.Element {</div></div></div>++ <LicenseSection /></div>);}