import { useFlag, useParams } from 'common' import { BookOpen, Check, ChevronsUpDown, Copy, ExternalLink, List, X } from 'lucide-react' import Link from 'next/link' import { useState } from 'react' import { logConstants } from 'shared-data' import { Button, cn, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, copyToClipboard, Popover, PopoverContent, PopoverTrigger, SidePanel, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { DocsButton } from '../DocsButton' import { LOGS_EXPLORER_DOCS_URL } from '@/components/interfaces/Settings/Logs/Logs.constants' import { otelFieldsFromKeys, toOtelFieldSchemas, } from '@/components/interfaces/Settings/Logs/Logs.fieldReference' import Table from '@/components/to-be-cleaned/Table' import { useOtelLogKeysQuery } from '@/data/logs/otel-log-keys-query' import { DOCS_URL } from '@/lib/constants' export interface LogsExplorerHeaderProps { subtitle?: string } const LogsExplorerHeader = ({ subtitle }: LogsExplorerHeaderProps) => { const [showReference, setShowReference] = useState(false) const [open, setOpen] = useState(false) const useOtel = useFlag('otelLegacyLogs') const schemas = useOtel ? toOtelFieldSchemas(logConstants.schemas) : logConstants.schemas const [selectedRef, setSelectedRef] = useState(schemas[0]?.reference) const selectedSchema = schemas.find((s) => s.reference === selectedRef) ?? schemas[0] const { ref: projectRef } = useParams() const { data: discoveredKeys, isPending: isLoadingKeys } = useOtelLogKeysQuery( { projectRef, source: selectedRef }, { enabled: useOtel && showReference } ) return (

Logs Explorer

{subtitle && {subtitle}}

Field Reference

} visible={showReference} cancelText="Close" onCancel={() => setShowReference(false)} hideFooter triggerElement={ } >
{useOtel ? (

The following table shows the fields available on each source. Nested fields live in the log_attributes map and are read with{' '} log_attributes['key'] — no unnesting joins needed.

) : (

The following table shows all the available paths that can be queried from each respective source. Do note that to access nested keys, you would need to perform the necessary{' '} unnesting joins

)}
No source found. {schemas.map((schema) => ( { setSelectedRef(schema.reference) setOpen(false) }} > {schema.name} ))} {useOtel && isLoadingKeys ? (

Loading fields…

) : ( Path , Type , ]} body={(() => { const fields = useOtel ? otelFieldsFromKeys(discoveredKeys ?? []) : selectedSchema.fields return fields.map((field) => ) })()} /> )} ) } export default LogsExplorerHeader const Field = ({ field, }: { field: { path: string type: string } }) => { const [isCopied, setIsCopied] = useState(false) return ( copyToClipboard(field.path, () => { setIsCopied(true) setTimeout(() => setIsCopied(false), 3000) }) } > {field.path} {isCopied ? ( Copied ) : ( Copy value )} {field.type} ) }