Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/go/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const schemaName = "https://github.com/grafana/docker-otel-lgtm"
var (
tracer = otel.Tracer(schemaName)
logger = otelslog.NewLogger(schemaName)
meter = otel.Meter(schemaName)
)

// setupOTelSDK bootstraps the OpenTelemetry pipeline.
Expand Down
9 changes: 9 additions & 0 deletions examples/go/rolldice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"strconv"
"time"

"go.opentelemetry.io/otel/metric"
)

func rolldice(w http.ResponseWriter, r *http.Request) {
Expand All @@ -23,6 +25,13 @@ func rolldice(w http.ResponseWriter, r *http.Request) {
if _, err := io.WriteString(w, resp); err != nil {
logger.ErrorContext(ctx, "Write failed: %v\n", slog.Any("error", err))
}

histogram, err := meter.Int64Histogram("dice.roll", metric.WithDescription("The result of the dice roll"))
if err != nil {
logger.ErrorContext(ctx, "Histogram instantiation failed: %v\n", slog.Any("error", err))
} else {
histogram.Record(ctx, int64(roll), metric.WithAttributes())
}
}

func roll() int {
Expand Down