diff --git a/README.md b/README.md index a870bcc..acf54d4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a plugin that makes it easy to use OTel with Spin. ## Background -Spin applications have the ability to export metrics and trace data. This plugin provides dashboards for viewing the data. +Spin applications have the ability to export metrics, logs, and trace data. This plugin provides dashboards for viewing the data. ## Requirements @@ -71,7 +71,7 @@ spin otel setup --aspire ``` -## Run a Spin app that exports telemetry data +## Run a Spin app and exports telemetry data ```sh spin otel up @@ -83,6 +83,8 @@ Any flags that work with the `spin up` command, will work with the `spin otel up spin otel up -- --help ``` +Additionally, the `spin otel up` command enables the `wasi-otel` features in versions of Spin >= v3.6.0, which means that users will be able to instrument their applications with OpenTelemetry using the [opentelemetry-wasi](github.com/bytecodealliance/opentelemetry-wasi) SDKs. + ## Open the dashboards in the default browser Depending on the chosen observability stack, you can use the sub-commands of `spin otel open` to open corresponding dashboards using your default browser. diff --git a/cmd/root.go b/cmd/root.go index 2e721d8..373f257 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -83,6 +83,15 @@ func detectContainerRuntime() (string, error) { return runtime, nil } +func getSpinPath() (string, error) { + pathToSpin := os.Getenv("SPIN_BIN_PATH") + if pathToSpin == "" { + return "", fmt.Errorf("Please ensure that you are running \"spin otel up\", rather than calling the OpenTelemetry plugin binary directly") + } + + return pathToSpin, nil +} + func Execute() { if err := setOtelConfigPath(); err != nil { fmt.Fprintln(os.Stderr, fmt.Errorf("Error finding the \"otel-config\" directory: %w", err)) diff --git a/cmd/up.go b/cmd/up.go index 340577e..00464d7 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -1,17 +1,23 @@ package cmd import ( - "fmt" "os" "os/exec" + "strconv" "github.com/spf13/cobra" ) +var experimentalWasiOtel = false + +func init() { + upCmd.Flags().BoolVarP(&experimentalWasiOtel, "experimental-wasi-otel", "", false, "Enable the experimental wasi-otel feature in Spin") +} + var upCmd = &cobra.Command{ Use: "up", - Short: "Runs a Spin App with the default OpenTelemetry environment variables.", - Long: "Runs a Spin App with the default OpenTelemetry environment variables. Any flags that work with the \"spin up\" command, will work with the \"spin otel up\" command: \"spin otel up -- --help\"", + Short: "Runs a Spin App with the default OpenTelemetry environment variables and wasi-otel features enabled.", + Long: "Runs a Spin App with the default OpenTelemetry environment variables and wasi-otel features enabled. Any flags that work with the \"spin up\" command, will work with the \"spin otel up\" command: \"spin otel up -- --help\"", RunE: func(cmd *cobra.Command, args []string) error { if err := up(args); err != nil { return err @@ -22,13 +28,19 @@ var upCmd = &cobra.Command{ } func up(args []string) error { - pathToSpin := os.Getenv("SPIN_BIN_PATH") - if pathToSpin == "" { - return fmt.Errorf("Please ensure that you are running \"spin otel up\", rather than calling the OpenTelemetry plugin binary directly") + pathToSpin, err := getSpinPath() + if err != nil { + return err + } + + cmdArgs := []string{"up"} + + if spinHasWasiOtel() { + cmdArgs = append(cmdArgs, "--experimental-wasi-otel") } // Passing flags and args after the '--' - cmdArgs := append([]string{"up"}, args...) + cmdArgs = append(cmdArgs, args...) cmd := exec.Command(pathToSpin, cmdArgs...) cmd.Env = append( os.Environ(), @@ -41,3 +53,27 @@ func up(args []string) error { return cmd.Run() } + +func spinHasWasiOtel() bool { + major, err := strconv.Atoi(os.Getenv("SPIN_VERSION_MAJOR")) + if err != nil { + panic("Something went wrong parsing the SPIN_VERSION_MAJOR env var: " + err.Error()) + } + + minor, err := strconv.Atoi(os.Getenv("SPIN_VERSION_MINOR")) + if err != nil { + panic("Something went wrong parsing the SPIN_VERSION_MINOR env var: " + err.Error()) + } + + if major < 3 { + return false + } else if major > 3 { + return true + } else { // if major == 3 + if minor >= 6 { + return true + } else { + return false + } + } +} diff --git a/otel-config/loki.yaml b/otel-config/loki.yaml index 2426182..187b274 100644 --- a/otel-config/loki.yaml +++ b/otel-config/loki.yaml @@ -24,6 +24,6 @@ schema_config: storage_config: filesystem: directory: /tmp/loki/chunks - + analytics: reporting_enabled: false