Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `Version()` function in `go.opentelemetry.io/contrib/samplers/probability/consistent` has been replaced by `const Version`. (#8366)
- The `Version()` function in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace` has been replaced by `const Version`. (#8302)
- The `Version()` function in `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo` has been replaced by `const Version`. (#8370)
- Set `error.type` attribute instead of adding `exception` span events in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#8386)
- Set `error.type` attribute instead of adding `exception` span events in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#8386)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
20 changes: 20 additions & 0 deletions instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ Additionally the following guidelines for package composition need to be followe
- All instrumentation packages MUST NOT provide an option to accept a `Tracer` or `Meter`.
- All instrumentation packages MUST define a `ScopeName` constant with a value matching the instrumentation package and use it when creating a `Tracer` or `Meter`.
- All instrumentation packages MUST define a `Version` function returning the version of the module containing the instrumentation and use it when creating a `Tracer` or `Meter`.

### Recording Errors

When an instrumented operation returns a non-nil `error` and the semantic conventions classify the outcome as an error, the instrumentation:

1. MUST set the span status to `codes.Error` with a description of `err.Error()`,

2. SHOULD also set the `error.type` attribute, for example by using the `ErrorType` function from the `semconv` package,

3. SHOULD NOT use `span.RecordError(err)` for this purpose.

For example:

```go
res, err := t.rt.RoundTrip(r)
if err != nil {
span.SetAttributes(semconv.ErrorType(err))
span.SetStatus(codes.Error, err.Error())
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) erro
out, metadata, err = next.HandleInitialize(ctx, in)
span.SetAttributes(m.buildAttributes(ctx, in, out)...)
if err != nil {
span.RecordError(err)
span.SetAttributes(semconv.ErrorType(err))
span.SetStatus(codes.Error, err.Error())
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func ExampleMiddleware() {
if err != nil {
log.Println("error reading body: ", err)
// Record the error in the span and set its status
span.RecordError(err)
span.SetStatus(codes.Error, "failed to read request body")
return c.String(http.StatusBadRequest, "Bad request")
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading