Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cbandy/pg_otel
OpenTelemetry Exporter for PostgreSQL
https://github.com/cbandy/pg_otel
logging observability opentelemetry postgres postgresql postgresql-extension
Last synced: about 2 months ago
JSON representation
OpenTelemetry Exporter for PostgreSQL
- Host: GitHub
- URL: https://github.com/cbandy/pg_otel
- Owner: cbandy
- License: isc
- Created: 2022-10-20T23:57:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-04T05:30:28.000Z (about 1 year ago)
- Last Synced: 2024-10-12T09:16:54.796Z (3 months ago)
- Topics: logging, observability, opentelemetry, postgres, postgresql, postgresql-extension
- Language: C
- Homepage:
- Size: 89.8 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg_otel
A loadable module for PostgreSQL that exports server log messages
to an OpenTelemetry [collector][].[collector]: https://docs.opentelemetry.io/concepts/data-collection/
## Getting Started
Add `pg_otel` to your [shared_preload_libraries][] and restart PostgreSQL.
Its default settings do nothing, so this is safe to leave in all the time.```ini
# postgresql.conf
shared_preload_libraries = pg_otel
```OpenTelemetry recommends running its [collector][] as an [agent][] on the same
machine as the application generating telemetry data. If that is how your
system is arranged, this module's default settings are for you!If your collector is somewhere else, you need put its URL in `otel.otlp_endpoint`.
```sql
ALTER SYSTEM SET otel.otlp_endpoint TO 'https://my-collector:4318';
```With that in place, the `otel.export` setting starts or stops the flow of logs.
These settings affect every connection to PostgreSQL, so the server needs to
[reload][] to finally apply them.```sql
ALTER SYSTEM SET otel.export TO 'logs';
SELECT pg_reload_conf();
```You should see logs in your collector and connected logging systems right away.
Congratulations! 🎉If you want to stop exporting logs, [reset][] `otel.export` to its empty default.
```sql
ALTER SYSTEM RESET otel.export;
SELECT pg_reload_conf();
```[agent]: https://opentelemetry.io/docs/collector/deployment/
[reload]: https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL
[reset]: https://www.postgresql.org/docs/current/sql-altersystem.html
[shared_preload_libraries]: https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-SHARED-PRELOAD-LIBRARIES## Configuration
There are number of other OpenTelemetry settings that can be adjusted for your
environment. Their respective [environment variables][sdk-env] also work.```
name | default | unit | description
----------------------------+-----------------------+------+-----------------------------------------------------------
otel.export | | | Signals to export over OTLP
otel.otlp_endpoint | http://localhost:4318 | | Target URL to which the exporter sends signals
otel.otlp_timeout | 10000 | ms | Maximum time the exporter will wait for each batch export
otel.resource_attributes | | | Key-value pairs to be used as resource attributes
otel.service_name | postgresql | | Logical name of this service
```The following settings cannot be changed at this time:
```
name | value | unit | description
----------------------------+-----------------------+------+-----------------------------------------------------------
otel.attribute_count_limit | 128 | | Maximum attributes allowed on each signal
otel.otlp_protocol | http/protobuf | | The exporter transport protocol
```[sdk-env]: https://opentelemetry.io/docs/reference/specification/sdk-environment-variables/