Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Feature
What is the current behavior?
No current behavior.
What is the new behavior?
This PR will start sending OpenTelemetry traces to the configured OTel vendor.
My goal with this PR is to set up OpenTelemetry in the repository + a development environment to send the traces. This will lower the bar for more contributors to explore this library and play with the traces (add more traces, trace other events, trace the different libraries this project uses, etc).
The OTel vendor can be configured with the following environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT
. The endpoint to send the traces to. For example:http://localhost:4318
.OTEL_EXPORTER_OTLP_HEADERS
. The headers to include in the request. For example:authorization="Bearer your-api-key"
.What's currently traced?
Ideally, this trace will have information on all the interactions with different systems: caches, pools, partisan, client_handler, db_handler, pg_parser, etc.
As the project is complex, I didn't have enough time to deep dive into each flow of queries + edge cases. That's why this PR just traces the query sent to the proxy, and when the
ClientHandler
responds to the callerNext steps
I need more time to think about how to share the
otel_span
created in theClientHandler
to theDbHandler
up to thetelemetry
produced event.Local environment producing traces
Pre-requisites:
To display the traces, I chose Grafana OTel because this project already uses the great library PromEx. I figured that Grafana had been already used in the stack. Of course, this is very easy to change :).
docker compose up grafana-otel
.admin/admin
.make dev.otel
psql postgresql://postgres.dev_tenant:postgres@localhost:6543/postgres
select * from _supavisor.tenants;
I added
dev.otel
to the Makefile, which adds two environment variables to send the traces tohttp://localhost:4318
.Visualizing the traces:
As you can see in the image, the trace shows the duration of the executed query with additional information that'll help filter traces when making queries.
Additional context
Related issue: #93
Let me know what can be improved in this PR. I'll address the reviews when I have free time 🙂.