Começar com a analítica de apps
Visualização
Esse recurso está em Prévia privada. Para experimentar, fale com o seu contato no Databricks.
Add analítica to an existing app in three passos: record an event, forward it through your backend, and verify it in analítica . No specific analítica biblioteca is required.
Pré-requisitos
- An app enrolled in the App analítica preview, with app telemetry enabled.
- As permissões listadas em Requirements.
O passo 1: Registrar um evento
Call this code from an existing interaction handler. This example records report_exported after a report export succeeds:
const logRecord = {
timeUnixNano: (BigInt(Date.now()) * 1000000n).toString(),
eventName: 'report_exported',
attributes: [
{ key: 'databricks.app.analytics.schema.version', value: { intValue: '1' } },
{ key: 'databricks.app.analytics.event.id', value: { stringValue: crypto.randomUUID() } },
{ key: 'databricks.app.analytics.event.type', value: { stringValue: 'action' } },
{ key: 'databricks.app.analytics.event.name', value: { stringValue: 'report_exported' } },
],
};
const response = await fetch('/_analytics', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(logRecord),
});
if (!response.ok) throw new Error('Analytics export failed.');
/_analytics is a route you add to your app, not a **integrada** Databricks endpoint. Step 2 shows the export logic for its backend handler.
session_id é opcional. Se você fornecer uma, reutilize a sessão de analítica de origem em vez de gerar um novo ID de sessão para cada evento. Se você repetir um evento, reenvie o mesmo registro, incluindo o ID e o Timestamp.
For page views, Web Vitals, and action properties, see Payload examples.
O passo 2: Exportar do seu backend
Adicione um manipulador de POST /_analytics ao seu back-end existente. Passe o corpo da solicitação analisado e validado para a função a seguir. Mantenha a rota protegida pelos controles de acesso do seu aplicativo e aplique seus limites de solicitação e tratamento de erros existentes. Retorne o sucesso ao navegador somente após a função ser bem-sucedida.
A função envolve o registro em uma solicitação do Protocolo OpenTelemetry (OTLP) e o envia para o coletor do aplicativo:
async function exportAnalyticsRecord(logRecord) {
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
if (endpoint !== 'http://localhost:4314') {
throw new Error('This example requires the TCP OTLP/HTTP receiver at localhost:4314.');
}
const response = await fetch(`${endpoint}/v1/logs`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
resourceLogs: [
{
resource: {
attributes: [{ key: 'service.name', value: { stringValue: process.env.DATABRICKS_APP_NAME } }],
},
scopeLogs: [{ logRecords: [logRecord] }],
},
],
}),
});
if (!response.ok) throw new Error('Collector rejected the request.');
const text = await response.text();
const result = text ? JSON.parse(text) : {};
if (Number(result.partialSuccess?.rejectedLogRecords ?? 0) > 0) {
throw new Error('Collector rejected the event.');
}
}
This HTTP example uses the TCP receiver at localhost:4314, which supports HTTP as well as gRPC. For a unix:// or gRPC-only endpoint, use a compatible OpenTelemetry exporter instead. The collector runs inside the app implantado, not on the visitor's device. See App telemetry environment variables.
O passo 3: Verificar em analítica
- Implante as alterações usando o fluxo de trabalho de implantação existente do seu aplicativo e, em seguida, Trigger a interação instrumentada.
- On the app details page, open Analítica and select a SQL warehouse.
- Se a integração for exibida, selecione Check for events e, em seguida, Abrir Analítica quando os eventos chegarem.
- Encontre
report_exportedem Top actions ou Live Events .
Collector acceptance precedes table ingestion. If the event doesn't appear, refresh Analytics and check the time range. Follow any permission guidance shown by the UI. To check the underlying telemetry data, see Verify telemetry data.