feat: produce OpenTelemetry traces with hs-opentelemetry#3140
feat: produce OpenTelemetry traces with hs-opentelemetry#3140develop7 wants to merge 1 commit intoPostgREST:mainfrom
hs-opentelemetry#3140Conversation
|
Awesome work! 🔥 🔥
Found this Nix flake that contains an OTel GUI: https://flakestry.dev/flake/github/FriendsOfOpenTelemetry/opentelemetry-nix/1.0.1 I'll try to integrate that once the PR is ready for review. |
8c0e16a to
64a0ee9
Compare
|
The recent problem I'm seemingly stuck with is There's a more straightforward It also seems to boil down to the conceptual choice between online and offline traces' delivery-wise, or push and pull model. @steve-chavez @wolfgangwalther @laurenceisla what do you think guys? |
|
@develop7 Would vault help? It was introduced on #1988, I recall it helped with IORef handling. It's still used on postgrest/src/PostgREST/Auth.hs Lines 160 to 165 in d2fb67f I'm still not that familiar with OTel but the basic idea I had was to store these traces on AppState and export them async. |
6b891c2 to
586e7a1
Compare
Not only that, you want traces in tests too, for one. The good news is
Good call @steve-chavez, thank you for the suggestion. Will try too. |
0830a45 to
dc882f1
Compare
|
Since now we have an postgrest/src/PostgREST/App.hs Lines 170 to 172 in 229bc77 postgrest/src/PostgREST/Observation.hs Lines 15 to 18 in 229bc77 Perhaps we can add some observations for the timings? Also the Logger is now used like: postgrest/src/PostgREST/Logger.hs Lines 53 to 54 in 7c6c056 postgrest/src/PostgREST/CLI.hs Line 50 in 7c6c056 For OTel, maybe the following would make sense: otelState <- Otel.init
App.run appState (Logger.logObservation loggerState >> OTel.tracer otelState)) |
dc882f1 to
7794848
Compare
Agreed, server timings definitely belong there. |
7794848 to
398206b
Compare
398206b to
4cd99c6
Compare
|
Okay, the PR is in the cooking for long enough, let's pull the plug and start small. Let's have it reviewed while I'm fixing the remaining CI failures. |
4cd99c6 to
94d2b9b
Compare
|
I don't think we depend on this in the current state. And we should certainly not depend on an even-less-maintained fork of the same. So to go forward here, there needs to be some effort put into the upstream package first, to make it usable for us. |
590d142 to
e809a65
Compare
|
A status update:
|
Hm. I looked at your fork. It depends on support for GHC 9.8 in I guess for GHC 9.8 support it's just a matter of time. What about the other issues mentioned above? Were you able to make progress on those? |
In my prototype I actually played with replacing HASQL Session with an https://github.com/haskell-effectful/effectful based monad to make it extensible: https://github.com/mkleczek/hasql-api/blob/master/src/Hasql/Api/Eff/Session.hs#L37 Using it in PostgREST required some mixins usage in Cabal: 29b946e#diff-eb6a76805a0bd3204e7abf68dcceb024912d0200dee7e4e9b9bce3040153f1e1R140 Some work was required in PostgREST startup/configuration code to set-up appropriate effect handlers and middlewares but the changes were quite well isolated. At the end of the day I think basing your monad stack on an effect library (effectful, cleff etc.) is the way forward as it makes the solution highly extensible and configurable. |
e809a65 to
4697009
Compare
650d008 to
ac33872
Compare
|
Update: rebased the PR against latest |
0205761 to
9c1b361
Compare
659d8c2 to
4755f08
Compare
4755f08 to
a429185
Compare
* Introduces producing OpenTelemetry traces with hs-opentelemetry. * Adds OTel spans over the whole application loop and over each request processing phase * Preliminary OTel tracing support in spec tests * Disables tracing in load and memory tests
a429185 to
c199822
Compare
|
@develop7 |
|
I tested the feature in Honeycomb and locally using otel-tui and otel-desktop-viewer and from what I can see it's working on all of them 🎉 ! I executed the following (first env. vars are for Honeycomb): # OTEL_EXPORTER_OTLP_ENDPOINT="https://api.honeycomb.io:443" \
# OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=<REDACTED>" \
OTEL_EXPORTER_OTLP_ENDPOINT='http://localhost:4318' \
OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf' \
OTEL_SERVICE_NAME='PostgREST' \
OTEL_LOG_LEVEL='debug' \
OTEL_TRACES_SAMPLER='always_on' \
PGRST_SERVER_OTEL_ENABLED=true \
PGRST_DB_AGGREGATES_ENABLED=true \
PGRST_DB_PLAN_ENABLED=true \
PGRST_SERVER_TIMING_ENABLED=true \
PGRST_LOG_LEVEL=info \
postgrest-with-pg-17 -f ./test/spec/fixtures/load.sql postgrest-runPrint screens: The only thing out of the ordinary is that |
@mkleczek it's absolutely worth trying to implement; will look into it. |
I'll add that to examples section of the doc; what collector did you use BTW?
Seems like upstream issue; which they just fixed in CtrlSpice/otel-desktop-viewer#203 |
Oh, I didn't use a collector, it sent data directly to Honeycomb. I'll try it out with one and come back with the info. |
| OTEL_TRACES_SAMPLER='always_on' \ | ||
| postgrest | ||
|
|
||
| Since current OpenTelemetry implementation incurs a small (~6% in our "Loadtest (mixed)" suite) |
There was a problem hiding this comment.
Since OTel is only applied to the timing headers, maybe the loss in perf is not from OTel but from the timing headers? The measured loss matches the one reported in #3410 (comment)




This PR introduces producing OpenTelemetry traces containing, among others, metrics same as in
ServerTimingheader from before.TODO:
build with Nix as well (for now Stack only)DONE for freemake an example of exporting log messageshs-opentelemetrydoesn't support logging, per Logging roadmap iand675/hs-opentelemetry#100makeseems like impossible without major refactoringgetTraceravailable globally: we're interested in using as many different spans as it makes sense, sogetTracershould be available everywhere, as described inhs-opentelemetry-sdk's READMEhs-opentelemetry-waimiddlewarelook into failing Windows buildshs-opentelemetry-sdkdepends onunix, tracking in Windows support iand675/hs-opentelemetry#109Running:
I sort of gave up deploying and configuring all the moving bits locally, so you'd need to create the honeycomb.io account for this one (or ask me for the invite). After that, it's quite straightforward:
stack build, and get its path withstack exec -- which postgrestnix-shell, thenpostgrest-with-postgresql-15 --fixture ./test/load/fixture.sql -- cat). Note the server URL, you'll need it when running PostgREST serverpostgrest-jwt --exp 36000 postgrest_test_anonymousTests
hspec tests are also instrumented, for those to produce traces you need to set
OTEL_*vars only: