From cdd2dbb4748a8ffba53ec831a810fe2c7ce3356e Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 10 Sep 2024 11:04:33 -0700 Subject: [PATCH] Drop support for Go 1.21 in dice example (#5800) Resolves #5359 --- CHANGELOG.md | 2 +- example/dice/rolldice.go | 31 ++++++++++++++++++++++++ example/dice/rolldice_go1.21.go | 35 --------------------------- example/dice/rolldice_go1.22.go | 42 --------------------------------- 4 files changed, 32 insertions(+), 78 deletions(-) delete mode 100644 example/dice/rolldice_go1.21.go delete mode 100644 example/dice/rolldice_go1.22.go diff --git a/CHANGELOG.md b/CHANGELOG.md index ff23c860def..858bd2d1ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Removed -- Drop support for [Go 1.21]. (#5736, #5740) +- Drop support for [Go 1.21]. (#5736, #5740, #5800) diff --git a/example/dice/rolldice.go b/example/dice/rolldice.go index 186771df25e..1869b5183ad 100644 --- a/example/dice/rolldice.go +++ b/example/dice/rolldice.go @@ -4,8 +4,15 @@ package main import ( + "fmt" + "io" + "math/rand" + "net/http" + "strconv" + "go.opentelemetry.io/contrib/bridges/otelslog" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) @@ -27,3 +34,27 @@ func init() { panic(err) } } + +func rolldice(w http.ResponseWriter, r *http.Request) { + ctx, span := tracer.Start(r.Context(), "roll") + defer span.End() + + roll := 1 + rand.Intn(6) + + var msg string + if player := r.PathValue("player"); player != "" { + msg = fmt.Sprintf("%s is rolling the dice", player) + } else { + msg = "Anonymous player is rolling the dice" + } + logger.InfoContext(ctx, msg, "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) + } +} diff --git a/example/dice/rolldice_go1.21.go b/example/dice/rolldice_go1.21.go deleted file mode 100644 index 5f3b83f35b4..00000000000 --- a/example/dice/rolldice_go1.21.go +++ /dev/null @@ -1,35 +0,0 @@ -// 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) - } -} diff --git a/example/dice/rolldice_go1.22.go b/example/dice/rolldice_go1.22.go deleted file mode 100644 index fe964397bc0..00000000000 --- a/example/dice/rolldice_go1.22.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -//go:build go1.22 -// +build go1.22 - -package main - -import ( - "fmt" - "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) - - var msg string - if player := r.PathValue("player"); player != "" { - msg = fmt.Sprintf("%s is rolling the dice", player) - } else { - msg = "Anonymous player is rolling the dice" - } - logger.InfoContext(ctx, msg, "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) - } -}