oh my, self hosting those cloud services is a deep deep rabbit hole to go. it would be much easier to just use their cloud services, just grab the API key and copy the endpoint URL, you are good to go, anyway, I digress.
I'd suggest use tracing-loki
crate directly. loki
is the log storage service from grafana, although this page lists grafana as a vendor supporting native OTLP
, from what I can tell, native OTLP
is supported on the grafana cloud platform as an integrated whole, but loki
itself uses an prometheus compatible API.
opentelemetry defines OTLP
as a canonical interchange protocol, but not every backend speaks OTLP
natively, some need a translation layer in between, called exporters(OTLP to vendor specific protocol) and/or receivers(vendor specific protocol to OTLP). according to this list, loki
has both a receiver and an exporter, so the translation is bidirectional. but why bother the indirection if you can use the tracing-loki
crate directly? however, if you are targeting an backend which speaks OTLP natively, opentelemetry could worth a try.
back to the loki crate, I tried the example code in the crate documentation with their sample set up using docker compose, it works, but I feel overwhelmed by the grafana UI. following the guide, I managed to query the logs using the label {lang=rust}
.
I basically copy pasted the code from the document. note: at least one label is required to be able to do queries on the logs, and the X-Scope-OrgID
header is mentioned in the crate doc, I just looked at the docker config files and find tenant1
is the correct value for the example setup. I don't want to spend time to read all the documents on loki.
let fmt_layer = fmt::layer().with_filter(filter::LevelFilter::from_level(tr::Level::INFO));
let (loki_layer, loki_task) = tracing_loki::builder()
.label("lang", "rust")
.unwrap()
.http_header("X-Scope-OrgID", "tenant1")
.unwrap()
.build_url("http://127.0.0.1:3100".try_into().unwrap())
.unwrap();
registry().with(loki_layer).with(fmt_layer).init();
tokio::spawn(loki_task);