sourcegraph/internal/tracer
Robert Lin 294fe3df22
cody-gateway: push GCP metrics or publish Prometheus metrics via OpenTelemetry (#55134)
Our first usage of [the recently stabilized OpenTelemetry
metrics](https://opentelemetry.io/docs/specs/otel/metrics/) 😁 Currently
this is Cody-Gateway-specific, nothing is added for Sourcegraph as a
whole.

We add the following:

- If a GCP project is configured, we set up a GCP exporter that pushes
metrics periodically and on shutdown. It's important this is push-based
as Cloud Run instances are ephemeral.
- Otherwise, we set up a Prometheus exporter that works the same as
using the Prometheus SDK, where metrics are exported in `/metrics` (set
up by debugserver) and Prometheus scrapes periodically.

To start off I've added a simple gauge that records concurrent ongoing
requests to upstream Cody Gateway services - see test plan below.

Closes https://github.com/sourcegraph/sourcegraph/issues/53775

## Test plan

I've only tested the Prometheus exporter. Hopefully the GCP one will
"just work" - the configuration is very similar to the one used in the
tracing equivalent, and that one "just worked".

```
sg start dotcom
sg run prometheus
```

See target picked up:

<img width="1145" alt="Screenshot 2023-07-19 at 7 09 31 PM"
src="https://github.com/sourcegraph/sourcegraph/assets/23356519/c9aa4c06-c817-400e-9086-c8ed6997844e">

Talk to Cody aggressively:

<img width="1705" alt="image"
src="https://github.com/sourcegraph/sourcegraph/assets/23356519/fbda23c7-565f-4a11-ae1b-1bdd8fbceca1">
2023-07-20 20:35:16 +00:00
..
oteldefaults cody-gateway: push GCP metrics or publish Prometheus metrics via OpenTelemetry (#55134) 2023-07-20 20:35:16 +00:00
BUILD.bazel Tracing: remove opentracing (#52978) 2023-06-06 11:02:15 -06:00
CODENOTIFY trace, tracer, errors, observation: add devx to CODENOTIFY (#38897) 2022-07-18 18:19:13 +02:00
conf.go service: allow more flexibility in conf-dependent configuration (#52039) 2023-05-17 09:13:19 -07:00
doc.go tracer: only swap underlying SpanProcessor, instead of entire tracers (#47428) 2023-02-21 09:39:07 -08:00
logged_otel.go tracer: only swap underlying SpanProcessor, instead of entire tracers (#47428) 2023-02-21 09:39:07 -08:00
otel_should_trace.go tracer: only swap underlying SpanProcessor, instead of entire tracers (#47428) 2023-02-21 09:39:07 -08:00
otel.go cody-gateway: push GCP metrics or publish Prometheus metrics via OpenTelemetry (#55134) 2023-07-20 20:35:16 +00:00
tracer.go Tracing: remove opentracing (#52978) 2023-06-06 11:02:15 -06:00
watch_test.go Tracing: remove opentracing (#52978) 2023-06-06 11:02:15 -06:00
watch.go service: allow more flexibility in conf-dependent configuration (#52039) 2023-05-17 09:13:19 -07:00