Skip to content

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.

858 B
Raw Blame
import type { TagtypesPostableTagDTO } from 'api/generated/services/sigNoz.schemas';

export { parseKeyValueTag } from 'components/TagKeyValueInput/utils';

// The tag editor is strictly key:value, so always render both sides — a
// `key:key` tag stays `key:key` rather than collapsing to a bare `key`.
export function tagsToStrings(tags: TagtypesPostableTagDTO[]): string[] {
	return tags.map((t) => `${t.key}:${t.value}`);
}

export function stringsToTags(tagStrings: string[]): TagtypesPostableTagDTO[] {
	return tagStrings
		.map((s) => {
			const trimmed = s.trim();
			const idx = trimmed.indexOf(':');
			if (idx === -1) {
				return { key: trimmed, value: trimmed };
			}
			const key = trimmed.slice(0, idx).trim();
			const value = trimmed.slice(idx + 1).trim();
			return { key, value: value || key };
		})
		.filter((t) => t.key.length > 0);
}