# Adding honeycomb observation to postgres cluster

**URL:** <https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232>\
**Category:** General\
**Created:** [August 17, 2021, 2:44pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232 "2021-08-17T14:44:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kentcdodds](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kentcdodds/32/2803_2.png) [@kentcdodds](https://community.fly.io/u/kentcdodds)\
**Post date:** [August 17, 2021, 2:44pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/1 "2021-08-17T14:44:52Z")

</div>

I want to get some observability into my postgres cluster and I’m planning to use honeycomb for my app. So I was thinking about just following [this post](https://docs.honeycomb.io/getting-data-in/integrations/databases/postgresql/logs/), but thought I’d check first. Thoughts?

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [August 17, 2021, 3:51pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/2 "2021-08-17T15:51:49Z")

</div>

That post will probably work, but it’ll be a bit of a chore and, I think, require you run your own build of Postgres on Fly.

The [RDS post](https://docs.honeycomb.io/getting-data-in/integrations/databases/postgresql/rds/) seems close to something that’ll work. If I’m reading this right, you’d need two special settings on your Postgres cluster and a way to send logs to Honeycomb. Our NATs based log shipper [can output to Honeycomb](https://github.com/superfly/fly-log-shipper#honeycomb).

---

<div class="post-metadata">

**Author:** ![kentcdodds](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kentcdodds/32/2803_2.png) [@kentcdodds](https://community.fly.io/u/kentcdodds)\
**Post date:** [August 17, 2021, 3:58pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/3 "2021-08-17T15:58:43Z")

</div>

Oh, nice. So if I follow the RDS post then I should be able to get data to honeycomb?

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [August 17, 2021, 4:36pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/4 "2021-08-17T16:36:10Z")

</div>

That RDS post uses a custom utility to get logs from AWS. I think the first thing to do is setup our log shipper as an app in your org and point that at Honeycomb. It should be as simple as a `fly launch` with the right config.

We need to look at the safest way of changing PG settings, I’ll let you know what we think later today.

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gerhard/32/40165_2.png) [@gerhard](https://community.fly.io/u/gerhard)\
**Post date:** [May 10, 2022, 10:00pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/5 "2022-05-10T22:00:03Z")

</div>

What is the simplest way to configure [Fly.io](http://Fly.io) PostgreSQL logs shipping to [Honeycomb.io](http://Honeycomb.io) today?

I assume that [honeytail](https://github.com/honeycombio/honeytail) will ship the logs in a way that will make querying them easy. On the other hand, [fly-log-shipper](https://github.com/superfly/fly-log-shipper#honeycomb) seems super simple. The bit which I am missing is how to configure PostgreSQL. Maybe a PR that contributes [PostgreSQL logs](https://docs.honeycomb.io/getting-data-in/integrations/databases/postgresql/logs/) to [postgres-ha](https://github.com/fly-apps/postgres-ha) would make sense. WDYT?

---

<div class="post-metadata">

**Author:** ![patrickck](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/patrickck/32/48363_2.png) [@patrickck](https://community.fly.io/u/patrickck)\
**Post date:** [June 20, 2022, 9:55pm UTC](https://community.fly.io/t/adding-honeycomb-observation-to-postgres-cluster/2232/6 "2022-06-20T21:55:04Z")

</div>

Fly log shipper isn’t quite specific enough to get interesting query data into honeycomb from postgres at the moment, but I was able to cobble together shipper + vector remaps + file sink + honeytail to finally see something usable via queries + raw data tables that aren’t very useful…but it’s something.

There’s a few reasons this might not be worth it to you:

1. Honeytail reports durations differently than Honeycomb document for events and it’s hard to get traceIds into the events, so this data will be missing from your spans which is probably what you actually want.
2. The normalizer doesn’t work if you or your underlying ORM writes queries with table/column quotes like `"public"."column"`, which means even raw data tables have _too much_ cardinality to see meaningful trends.

If you want to try it:

- Clone the shipper
- Update the Dockerfile to install honeytail
- Update the entrypoint to launch honeytail, e.g.:

```auto
honeytail \
  --file="/var/honeytail.sink" \
  --dataset=$DATASET \
  --writekey=$HONEYCOMB_WRITE_KEY \
  --postgres.log_line_prefix="%m [%p] " \
  --add_field env=$ENV \
  --add_field service.name=$SERVICE &
/usr/local/bin/fly-logs | socat -u - UNIX-CONNECT:/var/run/vector.sock

```

- Update vector.toml to clean up as much as you want so that honeytail can actually parse the logs, and sink them to the file above:

```auto
[transforms.msg_no_prefix]
  type = "remap"
  inputs = ["fly_socket"]
  source = '''
  . = parse_json!(.message)
  . = parse_regex!(.message, r'(?:.+ \| )(?P<log>.+)').log
  '''

[transforms.filter_out_keeper]
type = "filter"
inputs = ["msg_no_prefix"]
condition = '''contains!(.message, "cmd/keeper.go") == false'''

[sinks.honeytail]
  type = "file"
  inputs = ["filter_out_keeper"] 
  path = "/var/honeytail.sink"

[sinks.honeytail.encoding]
  codec = "text"

```

`fly pg connect` and make sure the db is configured correctly:

```auto
ALTER SYSTEM SET log_min_duration_statement=0;
ALTER SYSTEM SET log_statement='none';
SELECT pg_reload_conf();

```
