Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
50 changes: 43 additions & 7 deletions cmd/up.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand All @@ -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
}
}
}
2 changes: 1 addition & 1 deletion otel-config/loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ schema_config:
storage_config:
filesystem:
directory: /tmp/loki/chunks

analytics:
reporting_enabled: false