Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add span status and error recording subsections to trace docs #2893

Merged
merged 3 commits into from
May 10, 2022
Merged
Changes from 2 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
43 changes: 43 additions & 0 deletions website_docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,49 @@ Events can also have attributes of their own -
span.AddEvent("Cancelled wait due to external signal", trace.WithAttributes(attribute.Int("pid", 4328), attribute.String("signal", "SIGHUP")))
```

### Set span status

A status can be set on a span, typically used to specify that there was an error in the operation a span is tracking - .`Error`.

```go
import (
// ...
"go.opentelemetry.io/otel/codes"
// ...
)

// ...

result, err := operationThatCouldFail()
if err != nil {
span.SetStatus(codes.Error, "operationThatCouldFail failed")
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
}
```

By default, the status for all spans is `Unset`. In rare cases, you may also wish to set the status to `Ok`. This should generally not be necessary, though.

### Record errors

If you have an operation that failed and you wish to capture the error it produced, you can record that error.

```go
import (
// ...
"go.opentelemetry.io/otel/codes"
// ...
)

// ...

result, err := operationThatCouldFail()
if err != nil {
span.SetStatus(codes.Error, "operationThatCouldFail failed")

Choose a reason for hiding this comment

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

https://opentelemetry.io/docs/instrumentation/go/getting-started/

  1. setting the status before recording an error - This differs from the "Getting Started" documentation.
  2. Similarly, why use "operationThatCouldFail failed" for the description as opposed to err.Error(). Is there a best practice?

span.RecordError(err)
}
```

It is highly recommended that you also set a span's status to `Error` when using `RecordError`, unless you do not wish to consider the span tracking a failed operation as an error span. The `RecordError` function does **not** automatically set a span status when called.
cartermp marked this conversation as resolved.
Show resolved Hide resolved

## Creating Metrics

The metrics API is currently unstable, documentation TBA.
Expand Down