ormushq / ormus

Ormus - Customer Data Platform
MIT License
28 stars 19 forks source link

feat(ormus): implement open telemetry #97

Closed mohsenHa closed 3 months ago

mohsenHa commented 3 months ago

I add these services to docker compose

After up local docker compose services you can access to each of them with bellow links:

grafana.ormuse.local
prometheus.ormuse.local
jaeger.ormuse.local

I also create an adapter to use to configure otel trace and metric and write an example for work with it.

Usage:

First you need to configure otela package:

import "github.com/ormushq/ormus/adapter/otela"

var cfg = otela.Config{
    Endpoint:           "otel_collector:4317",
    EnableMetricExpose: true,
    MetricExposePath:   "metrics",
        ServiceName: "test"
    MetricExposePort:   8081,
}

wg := &sync.WaitGroup{}
done := make(chan bool)

err := otela.Configure(wg, done, cfg)
if err != nil {
         panic(err)
}

After you configure the otela package you can use this for init new tracer and start a span:

tracer := otela.NewTracer("test-tracer")
ctx, span := tracer.Start(ctx, "test-span2")

after done work you can close span

span.End()

For metric you can use this:

meter := otel.Meter("test-meter")
counter, _ := meter.Float64Counter("test_counter")
counter.Add(context.Background(), 1)

Jaeger trace preview image

Grafana dashboard preview image