Skip to content

Commit cdd2dbb

Browse files
authored
Drop support for Go 1.21 in dice example (open-telemetry#5800)
Resolves open-telemetry#5359
1 parent e9ac0d2 commit cdd2dbb

File tree

4 files changed

+32
-78
lines changed

4 files changed

+32
-78
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2323

2424
### Removed
2525

26-
- Drop support for [Go 1.21]. (#5736, #5740)
26+
- Drop support for [Go 1.21]. (#5736, #5740, #5800)
2727

2828
<!-- Released section -->
2929
<!-- Don't change this section unless doing release -->

example/dice/rolldice.go

+31
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
package main
55

66
import (
7+
"fmt"
8+
"io"
9+
"math/rand"
10+
"net/http"
11+
"strconv"
12+
713
"go.opentelemetry.io/contrib/bridges/otelslog"
814
"go.opentelemetry.io/otel"
15+
"go.opentelemetry.io/otel/attribute"
916
"go.opentelemetry.io/otel/metric"
1017
)
1118

@@ -27,3 +34,27 @@ func init() {
2734
panic(err)
2835
}
2936
}
37+
38+
func rolldice(w http.ResponseWriter, r *http.Request) {
39+
ctx, span := tracer.Start(r.Context(), "roll")
40+
defer span.End()
41+
42+
roll := 1 + rand.Intn(6)
43+
44+
var msg string
45+
if player := r.PathValue("player"); player != "" {
46+
msg = fmt.Sprintf("%s is rolling the dice", player)
47+
} else {
48+
msg = "Anonymous player is rolling the dice"
49+
}
50+
logger.InfoContext(ctx, msg, "result", roll)
51+
52+
rollValueAttr := attribute.Int("roll.value", roll)
53+
span.SetAttributes(rollValueAttr)
54+
rollCnt.Add(ctx, 1, metric.WithAttributes(rollValueAttr))
55+
56+
resp := strconv.Itoa(roll) + "\n"
57+
if _, err := io.WriteString(w, resp); err != nil {
58+
logger.ErrorContext(ctx, "Write failed", "error", err)
59+
}
60+
}

example/dice/rolldice_go1.21.go

-35
This file was deleted.

example/dice/rolldice_go1.22.go

-42
This file was deleted.

0 commit comments

Comments
 (0)