Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for backend telemetry (tracing & metrics) #1013

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

zacps
Copy link
Contributor

@zacps zacps commented Apr 14, 2024

This uses the opentelemetry SDK to provide support for traces and two simple metrics (a conversations count and a messages count).

The telemetry entrypoint is built separately (unfortunately it does not seem like there is a method for doing this in one build as sveltekit overrides rollupOptions).

As written the metrics may be too high cardinality for some use cases (as they are keyed per user), but these attributes can always be dropped in a collector.

Fixes #692, #633

@@ -0,0 +1,19 @@
import { defineConfig } from "vite";

export default defineConfig({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We unfortunately need a second build step because sveltekit overrides vite's rollupOptions which we need to specify a second entrypoint

This uses the opentelemetry SDK to provide support for traces and two
simple metrics (a conversations count and a messages count).

The telemetry entrypoint is built separately (unfortunately it does not
seem like there is a method for doing this in one build as sveltekit
overrides rollupOptions).

As written the metrics may be too high cardinality for some use cases
(as they are keyed per user), but these attributes can always be dropped
in a collector.
@zacps zacps force-pushed the opentelemetry-pr branch from ff7cfe4 to 6c6f991 Compare April 14, 2024 21:18
@@ -0,0 +1,7 @@
#!/bin/bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nsarrazin nsarrazin self-requested a review April 16, 2024 06:58
@antonioramos1
Copy link
Contributor

Very happy to see this contribution! I was also missing having better observability since we currently have little visibility on how many users we have and how they are using chat-ui

@antonioramos1
Copy link
Contributor

Hi @nsarrazin if you dont mind me asking, are we looking to merge this PR or to support observability in a different way?

@nsarrazin
Copy link
Collaborator

Hey so I was working on adding support for prometheus metrics because we need them for HuggingChat but I think we can probably do it with this PR! Thanks for the contribution. 🚀

I'd like to have a /metrics route on a different port which exports metrics in a format compatible with prometheus. I think that's doable with opentelemetry, will dive into this

@nsarrazin
Copy link
Collaborator

The type checking error seems to be reported here open-telemetry/opentelemetry-js#3944

@zacps
Copy link
Contributor Author

zacps commented Apr 30, 2024

Hey so I was working on adding support for prometheus metrics because we need them for HuggingChat but I think we can probably do it with this PR!

It looks like this is possible via the prometheus exporter. If we add this I would like to keep the opentelemetry exporter as an option.

flowchart LR
    c["chat-ui"]-->|Prometheus|m["/metrics"]
Loading

Alternatively we could only support otlp exports and anyone who wanted a prometheus endpoint could get it through the opentelemetry-collector:

flowchart LR
    chat-ui --> |OTLP|opentelemetry-collector-->|Prometheus|/metrics
    opentelemetry-collector-->|prometheus-remote-write|endpoint
    
Loading

In my experience with opentelemetry so far using a collector has been pretty useful to add/transform labels, drop healthcheck data, etc

zacps added 3 commits May 1, 2024 09:30
@nsarrazin nsarrazin added back This issue is related to the Svelte backend or the DB observability labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back This issue is related to the Svelte backend or the DB observability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: add Open Telemetry (OTEL)/Prometheus exporter in chatui
3 participants