-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Using simpler method for error handling
- Loading branch information
Showing
10 changed files
with
631 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Enable Opentelemetry | ||
|
||
## Install Jaeger | ||
Use [Jaeger](https://github.com/jaegertracing/jaeger) as the backend storage for tracing: | ||
``` | ||
docker run --rm --name jaeger \ | ||
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ | ||
-p 6831:6831/udp \ | ||
-p 6832:6832/udp \ | ||
-p 5778:5778 \ | ||
-p 16686:16686 \ | ||
-p 4317:4317 \ | ||
-p 4318:4318 \ | ||
-p 14250:14250 \ | ||
-p 14268:14268 \ | ||
-p 14269:14269 \ | ||
-p 9411:9411 \ | ||
jaegertracing/all-in-one | ||
``` | ||
|
||
## Install Prometheus | ||
Write the [Prometheus](https://prometheus.io/) configuration file and save it as **prometheus.yml**: | ||
``` | ||
global: | ||
scrape_interval: 10s | ||
scrape_configs: | ||
- job_name: greptimedb-ingester-go | ||
static_configs: | ||
- targets: ['host.docker.internal:2233'] | ||
``` | ||
|
||
Run prometheus: | ||
``` | ||
docker run \ | ||
-p 9090:9090 \ | ||
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \ | ||
prom/prometheus | ||
``` | ||
|
||
|
||
## Example | ||
Enable opentelemetry in the configuration: | ||
```go | ||
cfg := greptime.NewConfig(host).WithDatabase(database). | ||
WithTraceProvider(tracerProvider).WithTracesEnabled(true). | ||
WithMeterProvider(meterProvider).WithMetricsEnabled(true) | ||
``` | ||
|
||
Running the example: | ||
```go | ||
go run main.go | ||
``` | ||
|
||
Output: | ||
|
||
```log | ||
2024/09/19 11:36:29 Waiting for connection... | ||
2024/09/19 11:36:29 serving metrics at localhost:2233/metrics | ||
2024/09/19 11:36:29 affected rows: 1 | ||
2024/09/19 11:36:29 Sleep 30s... | ||
2024/09/19 11:36:39 Done! | ||
``` | ||
|
||
## View metrics | ||
We can use `curl localhost:2233/metrics` to view the metrics data. Also, Open the address http://localhost:9090/ to view metrics data. | ||
|
||
![prometheus.png](../../images/prometheus.png) | ||
|
||
## View tracing | ||
Open the address http://localhost:16686/ to view tracing data. | ||
|
||
![jaeger.png](../../images/jaeger.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module opentelemetry-example | ||
|
||
go 1.22 | ||
|
||
toolchain go1.22.7 | ||
|
||
require ( | ||
github.com/GreptimeTeam/greptimedb-ingester-go v0.5.3-0.20240918162118-d3f1530a9887 | ||
github.com/prometheus/client_golang v1.20.4 | ||
go.opentelemetry.io/otel v1.30.0 | ||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.30.0 | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0 | ||
go.opentelemetry.io/otel/exporters/prometheus v0.52.0 | ||
go.opentelemetry.io/otel/sdk v1.30.0 | ||
go.opentelemetry.io/otel/sdk/metric v1.30.0 | ||
go.opentelemetry.io/otel/trace v1.30.0 | ||
google.golang.org/grpc v1.66.2 | ||
github.com/GreptimeTeam/greptime-proto v0.7.0 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect | ||
github.com/klauspost/compress v1.17.9 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/prometheus/client_model v0.6.1 // indirect | ||
github.com/prometheus/common v0.59.1 // indirect | ||
github.com/prometheus/procfs v0.15.1 // indirect | ||
github.com/stoewer/go-strcase v1.3.0 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.30.0 // indirect | ||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect | ||
golang.org/x/net v0.29.0 // indirect | ||
golang.org/x/sys v0.25.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
) |
Oops, something went wrong.