Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions data_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ var suites = []FixtureSuite{
},
},
},
// exec false reports a span
// {
// {
// Name: "#258 Commands that exit with a non-zero exit code should report a span",
// Config: FixtureConfig{
// CliArgs: []string{"exec", "--endpoint", "{{endpoint}}", "--", "false"},
// },
// Expect: Results{
// SpanCount: 1,
// CliOutput: "",
// Diagnostics: otelcli.Diagnostics{
// ExecExitCode: 1,
// },
// Config: otelcli.DefaultConfig().WithEndpoint("grpc://{{endpoint}}"),
// },
// },
// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this test looks right.

Try adding "--fail", "--verbose" to the CliArgs. It looks like config.SoftFail is being called when child.Run() returns an err.

If the command starts but does not complete successfully, the error is of type *ExitError. Other error types may be returned for other situations.

so the if err :- child.Run(); err != nil needs to be expanded to check for ExitError and not SoftFail on that so you can send the error upstream in the span status.

// regression tests
{
{
Expand Down
6 changes: 5 additions & 1 deletion otelcli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

tracev1 "go.opentelemetry.io/proto/otlp/trace/v1"
"github.com/equinix-labs/otel-cli/otlpclient"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -94,7 +95,10 @@ func doExec(cmd *cobra.Command, args []string) {
}

if err := child.Run(); err != nil {
config.SoftFail("command failed: %s", err)
span.Status = & tracev1.Status {
Message: fmt.Sprintln("exec command failed: ", err),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just do fmt.Sprintf here, message doesn't need the newline.

Code: tracev1.Status_STATUS_CODE_ERROR,
}
}
span.EndTimeUnixNano = uint64(time.Now().UnixNano())

Expand Down