-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into otelhttp-semconv-metricdatatest
- Loading branch information
Showing
39 changed files
with
252 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Dice example | ||
|
||
This is the foundation example for [Getting Started](https://opentelemetry.io/docs/languages/go/getting-started/) with OpenTelemetry. | ||
|
||
Below, you will see instructions on how to run this application, either with or without instrumentation. | ||
|
||
## Usage | ||
|
||
The `run.sh` script accepts one argument to determine which example to run: | ||
|
||
- `uninstrumented` | ||
- `instrumented` | ||
|
||
### Running the Uninstrumented Example | ||
|
||
The uninstrumented example is a very simple dice application, without OpenTelemetry instrumentation. | ||
|
||
To run the uninstrumented example, execute: | ||
|
||
```bash | ||
./run.sh uninstrumented | ||
``` | ||
|
||
### Running the Instrumented Example | ||
|
||
The instrumented example is exactly the same application, which includes OpenTelemetry instrumentation. | ||
|
||
To run the instrumented example, execute: | ||
|
||
```bash | ||
./run.sh instrumented | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
go get "go.opentelemetry.io/otel" \ | ||
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" \ | ||
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace" \ | ||
"go.opentelemetry.io/otel/exporters/stdout/stdoutlog" \ | ||
"go.opentelemetry.io/otel/sdk/log" \ | ||
"go.opentelemetry.io/otel/log/global" \ | ||
"go.opentelemetry.io/otel/propagation" \ | ||
"go.opentelemetry.io/otel/sdk/metric" \ | ||
"go.opentelemetry.io/otel/sdk/resource" \ | ||
"go.opentelemetry.io/otel/sdk/trace" \ | ||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"\ | ||
"go.opentelemetry.io/contrib/bridges/otelslog" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
go mod init go.opentelemetry.io/contrib/examples/dice/instrumented |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
go mod tidy | ||
export OTEL_RESOURCE_ATTRIBUTES="service.name=dice,service.version=0.1.0" | ||
go run . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
go mod tidy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
# Check if at least one argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 {instrumented|uninstrumented}" | ||
exit 1 | ||
fi | ||
|
||
# Switch based on the first argument | ||
case "$1" in | ||
instrumented) | ||
echo "Running instrumented example..." | ||
cd instrumented || exit | ||
source tidy.sh | ||
source run.sh | ||
;; | ||
uninstrumented) | ||
echo "Running uninstrumented example..." | ||
cd uninstrumented || exit | ||
source run.sh | ||
;; | ||
*) | ||
echo "Invalid argument: $1. Use 'instrumented' or 'uninstrumented'." | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module go.opentelemetry.io/otel/example/dice/uninstrumented | ||
|
||
go 1.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"time" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func run() (err error) { | ||
// Handle SIGINT (CTRL+C) gracefully. | ||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) | ||
defer stop() | ||
|
||
// Start HTTP server. | ||
srv := &http.Server{ | ||
Addr: ":8080", | ||
BaseContext: func(_ net.Listener) context.Context { return ctx }, | ||
ReadTimeout: time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
Handler: newHTTPHandler(), | ||
} | ||
srvErr := make(chan error, 1) | ||
go func() { | ||
log.Println("Running HTTP server...") | ||
srvErr <- srv.ListenAndServe() | ||
}() | ||
|
||
// Wait for interruption. | ||
select { | ||
case err = <-srvErr: | ||
// Error when starting HTTP server. | ||
return | ||
case <-ctx.Done(): | ||
// Wait for first CTRL+C. | ||
// Stop receiving signal notifications as soon as possible. | ||
stop() | ||
} | ||
|
||
// When Shutdown is called, ListenAndServe immediately returns ErrServerClosed. | ||
err = srv.Shutdown(context.Background()) | ||
return | ||
} | ||
|
||
func newHTTPHandler() http.Handler { | ||
mux := http.NewServeMux() | ||
|
||
// Register handlers. | ||
mux.HandleFunc("/rolldice/", rolldice) | ||
mux.HandleFunc("/rolldice/{player}", rolldice) | ||
|
||
return mux | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"math/rand" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
func rolldice(w http.ResponseWriter, r *http.Request) { | ||
roll := 1 + rand.Intn(6) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) is ignored as this is not security-sensitive. | ||
|
||
var msg string | ||
if player := r.PathValue("player"); player != "" { | ||
msg = player + " is rolling the dice" | ||
} else { | ||
msg = "Anonymous player is rolling the dice" | ||
} | ||
log.Printf("%s, result: %d", msg, roll) | ||
|
||
resp := strconv.Itoa(roll) + "\n" | ||
if _, err := io.WriteString(w, resp); err != nil { | ||
log.Printf("Write failed: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#!/bin/bash | ||
|
||
go run . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.