[Grafana Tempo] API ๊ธฐ๋ณธ
์ด๋ฒ์ ๊ทธ๋ฅ ๋์๋ณด๋๋ sdk๋ก ๋์ถฉ ๋ผ์ฐ๋๊ฑฐ ๋ง๊ณ , ์ง์ HTTP API ์ด๋ณด๋ฉด์ ๊ตฌ์กฐ๋ฅผ ํ์
ํด๋ณด์.
https://grafana.com/docs/tempo/latest/api_docs/
๊ตฌ์ฑ์ docker compose ๊ธฐ๋ฐ์ด๋ค.
์ด๊ฒ tempo.yml์ด๊ณ
stream_over_http_enabled: true
server:
http_listen_port: 3200
log_level: info
query_frontend:
search:
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
metadata_slo:
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
trace_by_id:
duration_slo: 5s
metrics:
max_duration: 120h
query_backend_after: 5m
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
distributor:
receivers:
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318"
grpc:
endpoint: "0.0.0.0:4317"
ingester:
max_block_duration: 5m # cut the headblock when this much time passes. this is being set for demo purposes and should probably be left alone normally
compactor:
compaction:
block_retention: 168h
metrics_generator:
registry:
external_labels:
source: tempo
cluster: docker-compose
storage:
path: /var/tempo/generator/wal
traces_storage:
path: /var/tempo/generator/traces
storage:
trace:
backend: local # backend configuration to use
wal:
path: /var/tempo/wal # where to store the wal locally
local:
path: /var/tempo/blocks
overrides:
defaults:
metrics_generator:
processors: [service-graphs, span-metrics, local-blocks] # enables metrics generator
generate_native_histograms: both
์ด๊ฒ docker-compose.yml์ด๋ค.
services:
tempo:
image: grafana/tempo:2.7.1
ports:
- "3200:3200"
command: ["-config.file=/etc/tempo.yaml"]
volumes:
- tempo_data:/var/tempo
- ./tempo.yaml:/etc/tempo.yaml
volumes:
tempo_data:
driver: local
์คํํ๋ค.
3200 ํฌํธ๋ก Tempo ์๋ฒ๋ฅผ, 4318 ํฌํธ๋ก open telemetry ํธํ ์๋ฒ๋ฅผ ์ด์๋ค.
์ํ ํ์ธ
๊ธฐ๋ณธ์ ์ผ๋ก Tempo์ ์ง์ ์ฝ๊ธฐ๋ฅผ ์๋ ๊ฒ์ 3200 ํฌํธ๋ฅผ ์ฌ์ฉํ๋ค.
curl -X GET http://localhost:3200/status
๊ทธ๋ผ ์ด๋ ๊ฒ ์ํ ์ ๋ณด๋ api ๋ชฉ๋ก๊ฐ์๊ฒ ๋ฌ๋ค.
trace ์ฝ์ ํ๊ธฐ
๋ฐ์ดํฐ๋ฅผ ์ง์ด๋ฃ์ ๋๋ oltp ํธํ ์๋ํฌ์ธํธ๋ฅผ ํตํด ์ฐ๋ฌ์ผ ํ๋ค.
์ด๋ ๊ฒ ๋ฃ์ผ๋ฉด ๋๋ค.
curl -X POST http://localhost:4318/v1/traces \
-H "Content-Type: application/json" \
-d '{
"resourceSpans": [{
"resource": {
"attributes": [{
"key": "service.name",
"value": { "stringValue": "test-service" }
}]
},
"scopeSpans": [{
"spans": [{
"traceId": "5b8aa5a2d2c872e8321cf37308d69df2",
"spanId": "5fb397be34d25d8b",
"name": "test-span",
"kind": 1,
"startTimeUnixNano": "1644238522000000000",
"endTimeUnixNano": "1644238522000000000"
}]
}]
}]
}'
์ด๋ ๊ฒ ๋จ๋ฉด ์ ๋ ๊ฒ์ด๋ค.
scopeSpans์ ์๋๊ฒ ๊ธฐ๋ณธ์ ์ธ span ํ๋ ๊ฐ๋ค์ด๋ค.
kind๊ฐ ์๋ฒ์ธ์ง consumer์ธ์ง ๊ตฌ๋ถํ๋ enum ์ ์๊ฐ์ด๊ณ , resource.attribute๊ฐ ๋ถ๊ฐ์ ์ธ ํ๊ทธ๊ฐ๋ค์ด๋ค.
๋จ์ ์กฐํ
traceID ๊ธฐ๋ฐ์ ์์ธ ์กฐํ๋ ๊ทธ๋ฅ trace ID๋ฅผ path parameter๋ก ์ฑ์์ ์๋ฉด ๋๋ค.
curl -X GET http://localhost:3200/api/traces/5b8aa5a2d2c872e8321cf37308d69df2

search API๋ฅผ ์ฐ๋ฉด ํ๊ทธ๊ฐ๋ค์ ๊ธฐ๋ฐ์ผ๋ก ํํฐํด์ ๊ฐ์ ธ์ฌ ์๋ ์๋ค.
curl -X GET "http://localhost:3200/api/search?tags=service.name%3Dtest-service"

grafana์์๋ explorer ํญ์์ ์ด search ๊ธฐ๋ฅ์ ์๊ฐํ๋ ํํ๋ก ์ฌ์ฉํ ์ ์๋ค.

๊ทผ๋ฐ ์ด๋ฐ ๋ฐฉ์์ ์ข ๋ถํธํ๊ธฐ๋ ํ๊ณ , ๋ณดํต traceQL์ด๋ผ๋ ํ์ฅ ๊ตฌ๋ฌธ์ ํตํด์ Grafana์์ ์ง์ ์๋ ํํ๋ก ์์ฃผ ์ด๋ค.
q๋ผ๋ ํ๋ผ๋ฏธํฐ์ TraceQL ํํ์์ ๋ด์์ ์๋ฉด ๊ฑฐ๊ธฐ ๋ง์ถฐ์ ๋ฟ๋ ค์ค๋ค.
TraceQL์ ๋ฌธ๋ฒ๊ณผ ์ฌ์ฉ๋ฒ์ ๋ค์ ํฌ์คํธ์์ ๋ค๋ค๋ณธ๋ค.
์ฐธ์กฐ
https://grafana.com/docs/tempo/latest/api_docs/
https://grafana.com/docs/tempo/latest/api_docs/pushing-spans-with-http/