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
import {
Bot,
Cable,
ChartLine,
DraftingCompass,
FileKey,
Gauge,
Grid3X3,
Key,
ListFilter,
Logs,
Receipt,
Shield,
TowerControl,
} from '@signozhq/icons';
import permissionsType from 'lib/authz/hooks/useAuthZ/permissions.type';
import {
AuthZResource,
AuthZVerb,
OBJECT_SCOPED_VERBS,
ObjectScopedVerb,
} from 'lib/authz/hooks/useAuthZ/types';
import { CoretypesTypeDTO } from 'api/generated/services/sigNoz.schemas';
/** Shared shape of the icon components exported by `@signozhq/icons`. */
type IconComponent = typeof Shield;
const OBJECT_SCOPED_VERB_SET = new Set<string>(OBJECT_SCOPED_VERBS);
export type SelectorType = 'input' | 'telemetryBuilder';
export interface ResourcePanelConfig {
label: string;
description: string;
icon: IconComponent;
selectorPlaceholder: string;
docsAnchor: string;
selectorType?: SelectorType;
}
/**
* Do not use CoretypesTypeDTO to represent this,
* we want to add resource panel configs for only types we actually are using,
* not all of them
*/
export const RESOURCE_PANELS: Record<AuthZResource, ResourcePanelConfig> = {
dashboard: {
label: 'Dashboards',
description: 'Dashboards and their panels across the workspace.',
icon: Grid3X3,
selectorPlaceholder:
'Type dashboard ID, separate multiple with comma or space',
docsAnchor: 'dashboard',
},
'factor-api-key': {
label: 'API Keys',
description: 'Programmatic access tokens for the workspace.',
icon: Key,
selectorPlaceholder: 'Type API key ID, separate multiple with comma or space',
docsAnchor: 'factor-api-key',
},
role: {
label: 'Roles',
description: 'Custom and managed roles and their assignments.',
icon: Shield,
selectorPlaceholder: 'Type role name, separate multiple with comma or space',
docsAnchor: 'role',
},
serviceaccount: {
label: 'Service Accounts',
description: 'Non-human identities used by integrations.',
icon: Bot,
selectorPlaceholder:
'Type service account ID, separate multiple with comma or space',
docsAnchor: 'service-account',
},
license: {
label: 'Licenses',
description: 'Licenses of the workspace, including the license key.',
icon: FileKey,
selectorPlaceholder: 'Type license ID, separate multiple with comma or space',
docsAnchor: 'license',
},
subscription: {
label: 'Subscription',
description: 'The workspace subscription, its usage and billing details.',
icon: Receipt,
selectorPlaceholder: 'Type * to cover the workspace subscription',
docsAnchor: 'subscription',
},
'quick-filter': {
label: 'Quick Filters',
description: 'Quick filters shown in the logs, traces, and other explorers.',
icon: ListFilter,
selectorPlaceholder:
'Type quick filter ID, separate multiple with comma or space',
docsAnchor: 'quick-filter',
},
'saved-view': {
label: 'Saved Views',
description: 'Saved views in the logs, traces, metrics and meter explorers.',
icon: TowerControl,
selectorPlaceholder:
'Type saved view ID, separate multiple with comma or space',
docsAnchor: 'saved-view',
},
'notification-channel': {
label: 'Notification Channels',
description:
'Destinations for alert notifications, such as Slack, PagerDuty, webhooks, etc.',
icon: Cable,
selectorPlaceholder:
'Type notification channel ID, separate multiple with comma or space',
docsAnchor: 'notification-channel',
},
logs: {
label: 'Logs',
description: 'Log data collected across the workspace.',
icon: Logs,
selectorPlaceholder:
'Enter selector as <query-type>/<key>/<value> or <query-type>/* or use wizard...',
docsAnchor: 'logs',
selectorType: 'telemetryBuilder',
},
traces: {
label: 'Traces',
description: 'Distributed tracing data collected across the workspace.',
icon: DraftingCompass,
selectorPlaceholder:
'Enter selector as <query-type>/<key>/<value> or <query-type>/* or use wizard...',
docsAnchor: 'traces',
selectorType: 'telemetryBuilder',
},
metrics: {
label: 'Metrics',
description: 'Metric data collected across the workspace.',
icon: ChartLine,
selectorPlaceholder:
'Enter selector as <query-type>/<key>/<value> or <query-type>/* or use wizard...',
docsAnchor: 'metrics',
selectorType: 'telemetryBuilder',
},
'meter-metrics': {
label: 'Meter Metrics',
description: 'Usage metering data for the workspace.',
icon: Gauge,
selectorPlaceholder:
'Enter selector as <query-type>/<key>/<value> or <query-type>/* or use wizard...',
docsAnchor: 'meter-metrics',
selectorType: 'telemetryBuilder',
},
};
export const RESOURCE_ORDER = (
Object.keys(RESOURCE_PANELS) as AuthZResource[]
).sort((left, right) =>
RESOURCE_PANELS[left].label.localeCompare(RESOURCE_PANELS[right].label),
);
export function getResourcePanel(resource: AuthZResource): ResourcePanelConfig {
const panel = RESOURCE_PANELS[resource];
if (panel) {
return panel;
}
// Ideally we will have all the resources mapped by compile time, in case we forgot or we are using a backend
// that is newer than frontend, we should have this as fallback to avoid crashing the UI
return {
label: resource,
description: 'Manage permissions for this resource.',
icon: Shield,
selectorPlaceholder: 'Type ID, separate multiple with comma or space',
docsAnchor: '',
};
}
export function getResourceVerbs(
resource: AuthZResource,
): readonly AuthZVerb[] {
const match = permissionsType.data.resources.find(
(entry) => entry.kind === resource,
);
if (!match) {
return [];
}
// Role resource cannot have assignee verb
// TODO(H4ad): Remove this once we get rid of frontend/lib/authz/hooks/useAuthZ/legacy.ts
if (resource === 'role') {
return match.allowedVerbs.filter((verb) => verb !== 'assignee');
}
return match.allowedVerbs;
}
export function getResourceType(resource: AuthZResource): CoretypesTypeDTO {
const match = permissionsType.data.resources.find(
(entry) => entry.kind === resource,
);
return match
? (match.type as CoretypesTypeDTO)
: CoretypesTypeDTO.metaresource;
}
export function supportsOnlySelected(
verb: AuthZVerb,
): verb is ObjectScopedVerb {
return OBJECT_SCOPED_VERB_SET.has(verb);
}