OpenTelemetryデータのクエリ
備考
ベータ版
この機能はベータ版です。
このページでは、Zerobus Ingest OTLPによってDeltaテーブルに取り込まれたOpenTelemetryデータに対するSQLクエリの例を示します。テーブルスキーマと列の詳細については、 Zerobus Ingest の OpenTelemetry テーブルリファレンスを参照してください。
以下の例では、 <catalog>.<schema>.<prefix>カタログ名、スキーマ名、テーブル名の接頭辞に置き換えてください。
attributes 、 resource.attributes 、 instrumentation_scope.attributes 、 body (ログ)などの列はVARIANTとして保存されます。値を抽出するには、 :key::type構文を使用します。例えば、 attributes:['http.method']::string http.method属性を文字列として返します。
注記
VARIANT列のクエリを実行するには、Databricks Runtime 15.3以降が必要です。バリアントの細断処理のパフォーマンスを向上させるには、Databricks Runtime 17.2以降を使用してください。
スパン
以下のクエリは、分散トレースデータを格納するspansテーブルからデータを返します。
SQL
-- Recent spans with duration and attributes
SELECT
time,
service_name,
name,
(end_time_unix_nano - start_time_unix_nano) / 1000000 AS duration_ms,
status.code AS status_code,
attributes:['http.method']::string AS http_method,
attributes:['http.status_code']::int AS http_status
FROM <catalog>.<schema>.<prefix>_otel_spans
WHERE time > current_timestamp() - INTERVAL 1 HOUR
ORDER BY time DESC
LIMIT 100;
-- Filter spans by attribute value
SELECT *
FROM <catalog>.<schema>.<prefix>_otel_spans
WHERE attributes:['http.status_code']::int = 200
AND time > current_timestamp() - INTERVAL 1 HOUR;
-- Slowest operations by service
SELECT
service_name,
name,
COUNT(*) AS call_count,
AVG((end_time_unix_nano - start_time_unix_nano) / 1000000) AS avg_duration_ms,
PERCENTILE_APPROX((end_time_unix_nano - start_time_unix_nano) / 1000000, 0.95) AS p95_duration_ms
FROM <catalog>.<schema>.<prefix>_otel_spans
WHERE time > current_timestamp() - INTERVAL 1 HOUR
GROUP BY service_name, name
ORDER BY avg_duration_ms DESC;
-- Spans by service name, environment, and SDK version
SELECT
service_name,
resource.attributes:['deployment.environment']::string AS environment,
instrumentation_scope.attributes:['otel.library.version']::string AS sdk_version,
COUNT(*) AS span_count
FROM <catalog>.<schema>.<prefix>_otel_spans
WHERE time > current_timestamp() - INTERVAL 1 HOUR
GROUP BY service_name, environment, sdk_version;
ログ
以下のクエリは、構造化されたログレコードとその重大度レベルを格納するログテーブルからデータを返します。
SQL
-- Recent logs with body and attributes
SELECT
time,
service_name,
severity_text,
body::string AS message,
attributes:['exception.type']::string AS exception_type
FROM <catalog>.<schema>.<prefix>_otel_logs
WHERE time > current_timestamp() - INTERVAL 1 HOUR
ORDER BY time DESC
LIMIT 100;
-- Error logs by service
SELECT
service_name,
severity_text,
COUNT(*) AS log_count
FROM <catalog>.<schema>.<prefix>_otel_logs
WHERE severity_text IN ('ERROR', 'WARN')
AND time > current_timestamp() - INTERVAL 1 HOUR
GROUP BY service_name, severity_text
ORDER BY log_count DESC;
-- Structured log body
SELECT
time,
service_name,
body:message::string AS message,
body:error.code::int AS error_code
FROM <catalog>.<schema>.<prefix>_otel_logs
WHERE time > current_timestamp() - INTERVAL 1 HOUR
AND body:error.code IS NOT NULL;
メトリクス
以下のクエリは、ゲージ、合計、ヒストグラムの測定値を格納するメトリクステーブルからデータを返します。
SQL
-- Recent metrics with values
SELECT
time,
service_name,
name,
metric_type,
COALESCE(gauge.value, sum.value) AS value
FROM <catalog>.<schema>.<prefix>_otel_metrics
WHERE time > current_timestamp() - INTERVAL 1 HOUR
ORDER BY time DESC
LIMIT 100;
-- Gauge metrics over time
SELECT
date_trunc('minute', time) AS minute,
name,
AVG(gauge.value) AS avg_value,
MAX(gauge.value) AS max_value
FROM <catalog>.<schema>.<prefix>_otel_metrics
WHERE metric_type = 'gauge'
AND time > current_timestamp() - INTERVAL 1 HOUR
GROUP BY 1, 2
ORDER BY minute;
-- Gauge attributes (attributes are nested inside each metric-type struct)
SELECT
time,
name,
gauge.value,
gauge.attributes:['host.name']::string AS host
FROM <catalog>.<schema>.<prefix>_otel_metrics
WHERE metric_type = 'gauge'
AND time > current_timestamp() - INTERVAL 1 HOUR;
-- Filter metrics by resource attribute
SELECT
time,
name,
gauge.value
FROM <catalog>.<schema>.<prefix>_otel_metrics
WHERE resource.attributes:['deployment.environment']::string = 'production'
AND metric_type = 'gauge'
AND time > current_timestamp() - INTERVAL 1 HOUR;
次のステップ
- Zerobus Ingest の OpenTelemetry テーブル リファレンス: スパン、ログ、メトリクス テーブルのテーブル スキーマと列定義のリファレンス。
- OpenTelemetry (OTLP) クライアントを設定してデータを Unity Catalog に送信する: OpenTelemetry SDK または Collector を設定してデータを Zerobus Ingest に送信する。
- Zerobus取り込みエラー処理:一般的なエラーとエラーコードのトラブルシューティング。