otelmetric

package
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package otelmetric adalah wrapper tipis di atas OTel Metrics API yang menyediakan helper untuk mencatat durasi fungsi, operasi DB, dan HTTP request. Pola penggunaannya sengaja dibuat mirip otellog agar konsisten di semua service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flush added in v1.1.8

func Flush(ctx context.Context) error

Flush forces the global MeterProvider to export any metrics still queued for its next periodic collection. Required at the end of short-lived processes (artisan/CLI commands, cron jobs) that call os.Exit right after their handler returns — the periodic reader otherwise never gets a scheduled tick to collect+export before the process dies. Pair with otellog.Flush for full observability on a one-shot command.

func RecordDB

func RecordDB(ctx context.Context, table, operation string) func()

RecordDB mencatat durasi operasi database sebagai histogram. Pasangan dari otellog.TraceDB — gunakan keduanya bersama.

func (r *Repo) GetList(ctx context.Context) (result []Model, err error) {
    ctx, traceDone := otellog.TraceDB(ctx, "mst_rekanan", "SELECT")
    defer otelmetric.RecordDB(ctx, "mst_rekanan", "SELECT")()
    defer traceDone(&err)
    ...
}

func RecordFunc

func RecordFunc(ctx context.Context, funcName string) func()

RecordFunc mencatat durasi satu pemanggilan fungsi sebagai histogram. Pasangan dari otellog.TraceFunc — gunakan keduanya bersama untuk observability lengkap.

func (u *Usecase) MyFunc(ctx context.Context, req Req) (resp Resp, err error) {
    ctx, traceDone := otellog.TraceFunc(ctx, "MyFunc")
    defer otelmetric.RecordFunc(ctx, "MyFunc")()
    defer traceDone(&err)
    ...
}

func RecordHTTP

func RecordHTTP(ctx goravelhttp.Context) func()

RecordHTTP mencatat metrics HTTP request: total, durasi (histogram), dan concurrent aktif. Gunakan di middleware — panggil sebelum Next(), gunakan returned func setelah Next():

func OtelMetrics(ctx goravelhttp.Context) {
    done := otelmetric.RecordHTTP(ctx)
    ctx.Request().Next()
    done()
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL