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 Status type to SDK #1874

Merged
merged 8 commits into from May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
| 10 | Out of Range |
| 14 | Unavailable |
| 15 | Data Loss |
- The `Status` type was added to the `go.opentelemetry.io/otel/sdk/trace` package to represent the status of a span. (#1874)

### Changed

Expand All @@ -30,6 +31,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Move the `Event` type from the `go.opentelemetry.io/otel` package to the `go.opentelemetry.io/otel/sdk/trace` package. (#1846)
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
- `Set.Encoded(Encoder)` no longer caches the result of an encoding. (#1855)
- The `StatusCode` and `StatusMessage` methods of the `ReadOnlySpan` interfaceand the `Span` produced by the `go.opentelemetry.io/otel/sdk/trace` package have been replaced with a single `Status` method.
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
This method returns the status of a span using the new `Status` type. (#1874)

### Deprecated

Expand Down
3 changes: 1 addition & 2 deletions exporters/otlp/internal/otlptest/data.go
Expand Up @@ -99,8 +99,7 @@ func SingleSpanSnapshot() []*tracesdk.SpanSnapshot {
Attributes: []attribute.KeyValue{},
MessageEvents: []tracesdk.Event{},
Links: []trace.Link{},
StatusCode: codes.Ok,
StatusMessage: "",
Status: tracesdk.Status{Code: codes.Ok},
DroppedAttributeCount: 0,
DroppedMessageEventCount: 0,
DroppedLinkCount: 0,
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/internal/transform/span.go
Expand Up @@ -108,7 +108,7 @@ func span(sd *tracesdk.SpanSnapshot) *tracepb.Span {
TraceId: tid[:],
SpanId: sid[:],
TraceState: sd.SpanContext.TraceState().String(),
Status: status(sd.StatusCode, sd.StatusMessage),
Status: status(sd.Status.Code, sd.Status.Description),
StartTimeUnixNano: uint64(sd.StartTime.UnixNano()),
EndTimeUnixNano: uint64(sd.EndTime.UnixNano()),
Links: links(sd.Links),
Expand Down
8 changes: 5 additions & 3 deletions exporters/otlp/internal/transform/span_test.go
Expand Up @@ -249,8 +249,10 @@ func TestSpanData(t *testing.T) {
},
},
},
StatusCode: codes.Error,
StatusMessage: "utterly unrecognized",
Status: tracesdk.Status{
Code: codes.Error,
Description: "utterly unrecognized",
},
Attributes: []attribute.KeyValue{
attribute.Int64("timeout_ns", 12e9),
},
Expand All @@ -276,7 +278,7 @@ func TestSpanData(t *testing.T) {
Kind: tracepb.Span_SPAN_KIND_SERVER,
StartTimeUnixNano: uint64(startTime.UnixNano()),
EndTimeUnixNano: uint64(endTime.UnixNano()),
Status: status(spanData.StatusCode, spanData.StatusMessage),
Status: status(spanData.Status.Code, spanData.Status.Description),
Events: spanEvents(spanData.MessageEvents),
Links: links(spanData.Links),
Attributes: Attributes(spanData.Attributes),
Expand Down
32 changes: 20 additions & 12 deletions exporters/otlp/otlp_span_test.go
Expand Up @@ -68,9 +68,11 @@ func TestExportSpans(t *testing.T) {
attribute.String("user", "alice"),
attribute.Bool("authenticated", true),
},
StatusCode: codes.Ok,
StatusMessage: "Ok",
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
Status: tracesdk.Status{
Code: codes.Ok,
Description: "Ok",
},
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v0.1.0",
Expand All @@ -90,9 +92,11 @@ func TestExportSpans(t *testing.T) {
attribute.String("user", "alice"),
attribute.Bool("authenticated", true),
},
StatusCode: codes.Ok,
StatusMessage: "Ok",
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
Status: tracesdk.Status{
Code: codes.Ok,
Description: "Ok",
},
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-b",
Version: "v0.1.0",
Expand All @@ -117,9 +121,11 @@ func TestExportSpans(t *testing.T) {
attribute.String("user", "alice"),
attribute.Bool("authenticated", true),
},
StatusCode: codes.Ok,
StatusMessage: "Ok",
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
Status: tracesdk.Status{
Code: codes.Ok,
Description: "Ok",
},
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v0.1.0",
Expand All @@ -139,9 +145,11 @@ func TestExportSpans(t *testing.T) {
attribute.String("user", "bob"),
attribute.Bool("authenticated", false),
},
StatusCode: codes.Error,
StatusMessage: "Unauthenticated",
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")),
Status: tracesdk.Status{
Code: codes.Error,
Description: "Unauthenticated",
},
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")),
InstrumentationLibrary: instrumentation.Library{
Name: "lib-a",
Version: "v1.1.0",
Expand Down
13 changes: 7 additions & 6 deletions exporters/stdout/trace_test.go
Expand Up @@ -64,10 +64,12 @@ func TestExporter_ExportSpan(t *testing.T) {
{Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now},
},
SpanKind: trace.SpanKindInternal,
StatusCode: codes.Error,
StatusMessage: "interesting",
Resource: resource,
SpanKind: trace.SpanKindInternal,
Status: tracesdk.Status{
Code: codes.Error,
Description: "interesting",
},
Resource: resource,
}
if err := ex.ExportSpans(context.Background(), []*tracesdk.SpanSnapshot{testSpan}); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -129,8 +131,7 @@ func TestExporter_ExportSpan(t *testing.T) {
`}` +
`],` +
`"Links":null,` +
`"StatusCode":"Error",` +
`"StatusMessage":"interesting",` +
`"Status":{"Code":"Error","Description":"interesting"},` +
`"DroppedAttributeCount":0,` +
`"DroppedMessageEventCount":0,` +
`"DroppedLinkCount":0,` +
Expand Down
10 changes: 5 additions & 5 deletions exporters/trace/jaeger/jaeger.go
Expand Up @@ -170,13 +170,13 @@ func spanSnapshotToThrift(ss *sdktrace.SpanSnapshot) *gen.Span {
)
}

if ss.StatusCode != codes.Unset {
tags = append(tags, getInt64Tag(keyStatusCode, int64(ss.StatusCode)))
if ss.StatusMessage != "" {
tags = append(tags, getStringTag(keyStatusMessage, ss.StatusMessage))
if ss.Status.Code != codes.Unset {
tags = append(tags, getInt64Tag(keyStatusCode, int64(ss.Status.Code)))
if ss.Status.Description != "" {
tags = append(tags, getStringTag(keyStatusMessage, ss.Status.Description))
}

if ss.StatusCode == codes.Error {
if ss.Status.Code == codes.Error {
tags = append(tags, getBoolTag(keyError, true))
}
}
Expand Down
34 changes: 20 additions & 14 deletions exporters/trace/jaeger/jaeger_test.go
Expand Up @@ -229,11 +229,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
TraceID: traceID,
SpanID: spanID,
}),
Name: "/foo",
StartTime: now,
EndTime: now,
StatusCode: codes.Error,
SpanKind: trace.SpanKindClient,
Name: "/foo",
StartTime: now,
EndTime: now,
Status: sdktrace.Status{Code: codes.Error},
SpanKind: trace.SpanKindClient,
InstrumentationLibrary: instrumentation.Library{
Name: instrLibName,
Version: instrLibVersion,
Expand Down Expand Up @@ -287,9 +287,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
Time: now,
},
},
StatusCode: codes.Error,
StatusMessage: statusMessage,
SpanKind: trace.SpanKindClient,
Status: sdktrace.Status{
Code: codes.Error,
Description: statusMessage,
},
SpanKind: trace.SpanKindClient,
InstrumentationLibrary: instrumentation.Library{
Name: instrLibName,
Version: instrLibVersion,
Expand Down Expand Up @@ -370,9 +372,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
Attributes: []attribute.KeyValue{
attribute.Array("arr", []int{0, 1, 2, 3}),
},
StatusCode: codes.Unset,
StatusMessage: statusMessage,
SpanKind: trace.SpanKindInternal,
Status: sdktrace.Status{
Code: codes.Unset,
Description: statusMessage,
},
SpanKind: trace.SpanKindInternal,
InstrumentationLibrary: instrumentation.Library{
Name: instrLibName,
Version: instrLibVersion,
Expand Down Expand Up @@ -421,9 +425,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
attribute.Int64("rk2", rv2),
semconv.ServiceNameKey.String("service name"),
),
StatusCode: codes.Unset,
StatusMessage: statusMessage,
SpanKind: trace.SpanKindInternal,
Status: sdktrace.Status{
Code: codes.Unset,
Description: statusMessage,
},
SpanKind: trace.SpanKindInternal,
InstrumentationLibrary: instrumentation.Library{
Name: instrLibName,
Version: instrLibVersion,
Expand Down
8 changes: 4 additions & 4 deletions exporters/trace/zipkin/model.go
Expand Up @@ -187,12 +187,12 @@ func toZipkinTags(data *tracesdk.SpanSnapshot) map[string]string {
}
}

if data.StatusCode != codes.Unset {
m["otel.status_code"] = data.StatusCode.String()
if data.Status.Code != codes.Unset {
m["otel.status_code"] = data.Status.Code.String()
}

if data.StatusCode == codes.Error {
m["error"] = data.StatusMessage
if data.Status.Code == codes.Error {
m["error"] = data.Status.Description
} else {
delete(m, "error")
}
Expand Down
74 changes: 46 additions & 28 deletions exporters/trace/zipkin/model_test.go
Expand Up @@ -30,6 +30,7 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
"go.opentelemetry.io/otel/semconv"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -74,9 +75,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data with no parent (same as typical, but has
// invalid parent)
Expand Down Expand Up @@ -107,9 +110,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data of unspecified kind
{
Expand Down Expand Up @@ -143,9 +148,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data of internal kind
{
Expand Down Expand Up @@ -179,9 +186,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data of client kind
{
Expand Down Expand Up @@ -218,9 +227,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data of producer kind
{
Expand Down Expand Up @@ -254,9 +265,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data of consumer kind
{
Expand Down Expand Up @@ -290,9 +303,11 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data with no events
{
Expand All @@ -313,9 +328,11 @@ func TestModelConversion(t *testing.T) {
attribute.String("attr2", "bar"),
},
MessageEvents: nil,
StatusCode: codes.Error,
StatusMessage: "404, file not found",
Resource: resource,
Status: sdktrace.Status{
Code: codes.Error,
Description: "404, file not found",
},
Resource: resource,
},
// span data with an "error" attribute set to "false"
{
Expand Down Expand Up @@ -348,8 +365,7 @@ func TestModelConversion(t *testing.T) {
Attributes: nil,
},
},
StatusCode: codes.Unset,
Resource: resource,
Resource: resource,
},
}

Expand Down Expand Up @@ -759,8 +775,10 @@ func TestTagsTransformation(t *testing.T) {
attribute.String("key", keyValue),
attribute.Bool("error", true),
},
StatusCode: codes.Error,
StatusMessage: statusMessage,
Status: sdktrace.Status{
Code: codes.Error,
Description: statusMessage,
},
},
want: map[string]string{
"error": statusMessage,
Expand Down