{"title":"Query telemetry","description":"Query OpenTelemetry logs, traces, and metrics with SQL, correlate services and requests, and join telemetry with product or business data.","order":500,"askSuggestions":["How do I correlate logs with their traces?","Why are some logs missing from my log and span join?"],"navigation":true,"body":{"code":"var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var v=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},l=(n,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of y(e))!w.call(n,a)&&a!==r&&i(n,a,{get:()=>e[a],enumerable:!(s=p(e,a))||s.enumerable});return n};var b=(n,e,r)=>(r=n!=null?u(f(n)):{},l(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),_=n=>l(i({},\"__esModule\",{value:!0}),n);var h=v((S,d)=>{d.exports=_jsx_runtime});var q={};x(q,{default:()=>g,frontmatter:()=>D});var t=b(h()),D={title:\"Query telemetry\",description:\"Query OpenTelemetry logs, traces, and metrics with SQL, correlate services and requests, and join telemetry with product or business data.\",order:500,askSuggestions:[\"How do I correlate logs with their traces?\",\"Why are some logs missing from my log and span join?\"]};function m(n){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",p:\"p\",pre:\"pre\",ul:\"ul\",...n.components},{DocsPreviewDocument:r,DocsPreviewSection:s,DocsPrompt:a,DocsPrompts:c}=e;return r||o(\"DocsPreviewDocument\",!0),s||o(\"DocsPreviewSection\",!0),a||o(\"DocsPrompt\",!0),c||o(\"DocsPrompts\",!0),(0,t.jsxs)(r,{anchors:\"query-telemetry query-a-signal correlate-logs-and-traces investigate-with-an-agent\",children:[(0,t.jsxs)(s,{sectionId:\"query-telemetry\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,t.jsx)(e.h1,{id:\"query-telemetry\",children:\"Query telemetry\"}),`\n`,(0,t.jsx)(e.p,{children:\"Query OpenTelemetry logs, traces, and metrics with SQL-backed tools in Altertable. Use the signal guides for individual records, then correlate signals or join them to business data with SQL.\"}),`\n`,(0,t.jsx)(e.p,{children:\"In Altertable, the Logs explorer can group matching records into a segmentation chart over time. The Traces explorer can limit results to root spans, open a trace waterfall, and correlate a trace with its logs. Use SQL when you need to join telemetry to product, customer, or operational catalogs.\"}),`\n`]}),(0,t.jsxs)(s,{sectionId:\"query-a-signal\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,t.jsx)(e.h2,{id:\"query-a-signal\",children:\"Query a signal\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.a,{href:\"/docs/opentelemetry/logs#query-logs\",children:\"Logs\"}),\" contain log bodies, severity, and trace/span identifiers.\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.a,{href:\"/docs/opentelemetry/traces#query-traces\",children:\"Traces\"}),\" contain request spans, timings, and service attributes.\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.a,{href:\"/docs/opentelemetry/metrics#verify-the-data\",children:\"Metrics\"}),\" contain gauge, sum, histogram, and summary points.\"]}),`\n`]}),`\n`]}),(0,t.jsxs)(s,{sectionId:\"correlate-logs-and-traces\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,t.jsx)(e.h2,{id:\"correlate-logs-and-traces\",children:\"Correlate logs and traces\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Join a log to its span using both \",(0,t.jsx)(e.code,{children:\"trace_id\"}),\" and \",(0,t.jsx)(e.code,{children:\"span_id\"}),\":\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`SELECT\n  logs.timestamp,\n  logs.severity_text,\n  logs.body,\n  spans.service_name,\n  spans.name AS span_name\nFROM opentelemetry.main.logs AS logs\nJOIN opentelemetry.main.spans AS spans\n  ON logs.trace_id = spans.trace_id\n  AND logs.span_id = spans.span_id\nWHERE logs.timestamp >= now() - INTERVAL '1 hour'\nORDER BY logs.timestamp DESC\nLIMIT 100;\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"This query returns logs with matching spans. Logs without both identifiers or a matching span are not included. When joining telemetry to business data, also check customer or account identifiers and the time range.\"}),`\n`]}),(0,t.jsxs)(s,{sectionId:\"investigate-with-an-agent\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,t.jsx)(e.h2,{id:\"investigate-with-an-agent\",children:\"Investigate with an agent\"}),`\n`,(0,t.jsx)(c,{children:(0,t.jsx)(a,{children:\"Investigate errors from the last hour. Which services are affected, and what might be causing them?\"})}),`\n`,(0,t.jsxs)(e.p,{children:[\"For table schemas and accepted signals, see the \",(0,t.jsx)(e.a,{href:\"/docs/opentelemetry/data-model\",children:\"data model\"}),\". For the status of the Grafana integration, see \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/clients/grafana\",children:\"Grafana availability\"}),\".\"]})]})]})}function g(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,{...n,children:(0,t.jsx)(m,{...n})}):m(n)}function o(n,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+n+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return _(q);})();\n;return Component;"},"_id":"docs/opentelemetry/query.mdx","_raw":{"sourceFilePath":"docs/opentelemetry/query.mdx","sourceFileName":"query.mdx","sourceFileDir":"docs/opentelemetry","contentType":"mdx","flattenedPath":"docs/opentelemetry/query"},"type":"Docs","path":"/opentelemetry/query","level":2,"parent":"opentelemetry"}