// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 //go:build !go1.22 // +build !go1.22 package main import ( "io" "math/rand" "net/http" "strconv" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) func rolldice(w http.ResponseWriter, r *http.Request) { ctx, span := tracer.Start(r.Context(), "roll") defer span.End() roll := 1 + rand.Intn(6) logger.InfoContext(ctx, "Anonymous player is rolling the dice", "result", roll) rollValueAttr := attribute.Int("roll.value", roll) span.SetAttributes(rollValueAttr) rollCnt.Add(ctx, 1, metric.WithAttributes(rollValueAttr)) resp := strconv.Itoa(roll) + "\n" if _, err := io.WriteString(w, resp); err != nil { logger.ErrorContext(ctx, "Write failed", "error", err) } }