mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-30 04:40:41 +02:00
Add Status type to SDK (#1874)
Add Status type to SDK Use this type to encapsulate the Span status similar to the Event type encapsulating a Span event and the Link type a span link. Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
This commit is contained in:
parent
f90d0d93f8
commit
b7d02db147
@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
| 10 | Out of Range |
|
| 10 | Out of Range |
|
||||||
| 14 | Unavailable |
|
| 14 | Unavailable |
|
||||||
| 15 | Data Loss |
|
| 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
|
### Changed
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
|
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
|
||||||
- `Set.Encoded(Encoder)` no longer caches the result of an encoding. (#1855)
|
- `Set.Encoded(Encoder)` no longer caches the result of an encoding. (#1855)
|
||||||
- Renamed `CloudZoneKey` to `CloudAvailabilityZoneKey` in Resource semantic conventions according to spec. (#1871)
|
- Renamed `CloudZoneKey` to `CloudAvailabilityZoneKey` in Resource semantic conventions according to spec. (#1871)
|
||||||
|
- The `StatusCode` and `StatusMessage` methods of the `ReadOnlySpan` interface and the `Span` produced by the `go.opentelemetry.io/otel/sdk/trace` package have been replaced with a single `Status` method.
|
||||||
|
This method returns the status of a span using the new `Status` type. (#1874)
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
@ -99,8 +99,7 @@ func SingleSpanSnapshot() []*tracesdk.SpanSnapshot {
|
|||||||
Attributes: []attribute.KeyValue{},
|
Attributes: []attribute.KeyValue{},
|
||||||
MessageEvents: []tracesdk.Event{},
|
MessageEvents: []tracesdk.Event{},
|
||||||
Links: []trace.Link{},
|
Links: []trace.Link{},
|
||||||
StatusCode: codes.Ok,
|
Status: tracesdk.Status{Code: codes.Ok},
|
||||||
StatusMessage: "",
|
|
||||||
DroppedAttributeCount: 0,
|
DroppedAttributeCount: 0,
|
||||||
DroppedMessageEventCount: 0,
|
DroppedMessageEventCount: 0,
|
||||||
DroppedLinkCount: 0,
|
DroppedLinkCount: 0,
|
||||||
|
@ -108,7 +108,7 @@ func span(sd *tracesdk.SpanSnapshot) *tracepb.Span {
|
|||||||
TraceId: tid[:],
|
TraceId: tid[:],
|
||||||
SpanId: sid[:],
|
SpanId: sid[:],
|
||||||
TraceState: sd.SpanContext.TraceState().String(),
|
TraceState: sd.SpanContext.TraceState().String(),
|
||||||
Status: status(sd.StatusCode, sd.StatusMessage),
|
Status: status(sd.Status.Code, sd.Status.Description),
|
||||||
StartTimeUnixNano: uint64(sd.StartTime.UnixNano()),
|
StartTimeUnixNano: uint64(sd.StartTime.UnixNano()),
|
||||||
EndTimeUnixNano: uint64(sd.EndTime.UnixNano()),
|
EndTimeUnixNano: uint64(sd.EndTime.UnixNano()),
|
||||||
Links: links(sd.Links),
|
Links: links(sd.Links),
|
||||||
|
@ -249,8 +249,10 @@ func TestSpanData(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "utterly unrecognized",
|
Code: codes.Error,
|
||||||
|
Description: "utterly unrecognized",
|
||||||
|
},
|
||||||
Attributes: []attribute.KeyValue{
|
Attributes: []attribute.KeyValue{
|
||||||
attribute.Int64("timeout_ns", 12e9),
|
attribute.Int64("timeout_ns", 12e9),
|
||||||
},
|
},
|
||||||
@ -276,7 +278,7 @@ func TestSpanData(t *testing.T) {
|
|||||||
Kind: tracepb.Span_SPAN_KIND_SERVER,
|
Kind: tracepb.Span_SPAN_KIND_SERVER,
|
||||||
StartTimeUnixNano: uint64(startTime.UnixNano()),
|
StartTimeUnixNano: uint64(startTime.UnixNano()),
|
||||||
EndTimeUnixNano: uint64(endTime.UnixNano()),
|
EndTimeUnixNano: uint64(endTime.UnixNano()),
|
||||||
Status: status(spanData.StatusCode, spanData.StatusMessage),
|
Status: status(spanData.Status.Code, spanData.Status.Description),
|
||||||
Events: spanEvents(spanData.MessageEvents),
|
Events: spanEvents(spanData.MessageEvents),
|
||||||
Links: links(spanData.Links),
|
Links: links(spanData.Links),
|
||||||
Attributes: Attributes(spanData.Attributes),
|
Attributes: Attributes(spanData.Attributes),
|
||||||
|
@ -68,9 +68,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
attribute.String("user", "alice"),
|
attribute.String("user", "alice"),
|
||||||
attribute.Bool("authenticated", true),
|
attribute.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Ok,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "Ok",
|
Code: codes.Ok,
|
||||||
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
Description: "Ok",
|
||||||
|
},
|
||||||
|
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -90,9 +92,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
attribute.String("user", "alice"),
|
attribute.String("user", "alice"),
|
||||||
attribute.Bool("authenticated", true),
|
attribute.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Ok,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "Ok",
|
Code: codes.Ok,
|
||||||
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
Description: "Ok",
|
||||||
|
},
|
||||||
|
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-b",
|
Name: "lib-b",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -117,9 +121,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
attribute.String("user", "alice"),
|
attribute.String("user", "alice"),
|
||||||
attribute.Bool("authenticated", true),
|
attribute.Bool("authenticated", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Ok,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "Ok",
|
Code: codes.Ok,
|
||||||
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
Description: "Ok",
|
||||||
|
},
|
||||||
|
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-a")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v0.1.0",
|
Version: "v0.1.0",
|
||||||
@ -139,9 +145,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
attribute.String("user", "bob"),
|
attribute.String("user", "bob"),
|
||||||
attribute.Bool("authenticated", false),
|
attribute.Bool("authenticated", false),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "Unauthenticated",
|
Code: codes.Error,
|
||||||
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")),
|
Description: "Unauthenticated",
|
||||||
|
},
|
||||||
|
Resource: resource.NewWithAttributes(attribute.String("instance", "tester-b")),
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: "lib-a",
|
Name: "lib-a",
|
||||||
Version: "v1.1.0",
|
Version: "v1.1.0",
|
||||||
|
@ -64,10 +64,12 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
{Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
|
{Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
|
||||||
{Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now},
|
{Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now},
|
||||||
},
|
},
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "interesting",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "interesting",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
}
|
}
|
||||||
if err := ex.ExportSpans(context.Background(), []*tracesdk.SpanSnapshot{testSpan}); err != nil {
|
if err := ex.ExportSpans(context.Background(), []*tracesdk.SpanSnapshot{testSpan}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -129,8 +131,7 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
`}` +
|
`}` +
|
||||||
`],` +
|
`],` +
|
||||||
`"Links":null,` +
|
`"Links":null,` +
|
||||||
`"StatusCode":"Error",` +
|
`"Status":{"Code":"Error","Description":"interesting"},` +
|
||||||
`"StatusMessage":"interesting",` +
|
|
||||||
`"DroppedAttributeCount":0,` +
|
`"DroppedAttributeCount":0,` +
|
||||||
`"DroppedMessageEventCount":0,` +
|
`"DroppedMessageEventCount":0,` +
|
||||||
`"DroppedLinkCount":0,` +
|
`"DroppedLinkCount":0,` +
|
||||||
|
@ -170,13 +170,13 @@ func spanSnapshotToThrift(ss *sdktrace.SpanSnapshot) *gen.Span {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.StatusCode != codes.Unset {
|
if ss.Status.Code != codes.Unset {
|
||||||
tags = append(tags, getInt64Tag(keyStatusCode, int64(ss.StatusCode)))
|
tags = append(tags, getInt64Tag(keyStatusCode, int64(ss.Status.Code)))
|
||||||
if ss.StatusMessage != "" {
|
if ss.Status.Description != "" {
|
||||||
tags = append(tags, getStringTag(keyStatusMessage, ss.StatusMessage))
|
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))
|
tags = append(tags, getBoolTag(keyError, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,11 +229,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
|||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
}),
|
}),
|
||||||
Name: "/foo",
|
Name: "/foo",
|
||||||
StartTime: now,
|
StartTime: now,
|
||||||
EndTime: now,
|
EndTime: now,
|
||||||
StatusCode: codes.Error,
|
Status: sdktrace.Status{Code: codes.Error},
|
||||||
SpanKind: trace.SpanKindClient,
|
SpanKind: trace.SpanKindClient,
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: instrLibName,
|
Name: instrLibName,
|
||||||
Version: instrLibVersion,
|
Version: instrLibVersion,
|
||||||
@ -287,9 +287,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
|||||||
Time: now,
|
Time: now,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: sdktrace.Status{
|
||||||
StatusMessage: statusMessage,
|
Code: codes.Error,
|
||||||
SpanKind: trace.SpanKindClient,
|
Description: statusMessage,
|
||||||
|
},
|
||||||
|
SpanKind: trace.SpanKindClient,
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: instrLibName,
|
Name: instrLibName,
|
||||||
Version: instrLibVersion,
|
Version: instrLibVersion,
|
||||||
@ -370,9 +372,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
|||||||
Attributes: []attribute.KeyValue{
|
Attributes: []attribute.KeyValue{
|
||||||
attribute.Array("arr", []int{0, 1, 2, 3}),
|
attribute.Array("arr", []int{0, 1, 2, 3}),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Unset,
|
Status: sdktrace.Status{
|
||||||
StatusMessage: statusMessage,
|
Code: codes.Unset,
|
||||||
SpanKind: trace.SpanKindInternal,
|
Description: statusMessage,
|
||||||
|
},
|
||||||
|
SpanKind: trace.SpanKindInternal,
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: instrLibName,
|
Name: instrLibName,
|
||||||
Version: instrLibVersion,
|
Version: instrLibVersion,
|
||||||
@ -421,9 +425,11 @@ func Test_spanSnapshotToThrift(t *testing.T) {
|
|||||||
attribute.Int64("rk2", rv2),
|
attribute.Int64("rk2", rv2),
|
||||||
semconv.ServiceNameKey.String("service name"),
|
semconv.ServiceNameKey.String("service name"),
|
||||||
),
|
),
|
||||||
StatusCode: codes.Unset,
|
Status: sdktrace.Status{
|
||||||
StatusMessage: statusMessage,
|
Code: codes.Unset,
|
||||||
SpanKind: trace.SpanKindInternal,
|
Description: statusMessage,
|
||||||
|
},
|
||||||
|
SpanKind: trace.SpanKindInternal,
|
||||||
InstrumentationLibrary: instrumentation.Library{
|
InstrumentationLibrary: instrumentation.Library{
|
||||||
Name: instrLibName,
|
Name: instrLibName,
|
||||||
Version: instrLibVersion,
|
Version: instrLibVersion,
|
||||||
|
@ -187,12 +187,12 @@ func toZipkinTags(data *tracesdk.SpanSnapshot) map[string]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.StatusCode != codes.Unset {
|
if data.Status.Code != codes.Unset {
|
||||||
m["otel.status_code"] = data.StatusCode.String()
|
m["otel.status_code"] = data.Status.Code.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.StatusCode == codes.Error {
|
if data.Status.Code == codes.Error {
|
||||||
m["error"] = data.StatusMessage
|
m["error"] = data.Status.Description
|
||||||
} else {
|
} else {
|
||||||
delete(m, "error")
|
delete(m, "error")
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data with no parent (same as typical, but has
|
// span data with no parent (same as typical, but has
|
||||||
// invalid parent)
|
// invalid parent)
|
||||||
@ -107,9 +109,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data of unspecified kind
|
// span data of unspecified kind
|
||||||
{
|
{
|
||||||
@ -143,9 +147,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data of internal kind
|
// span data of internal kind
|
||||||
{
|
{
|
||||||
@ -179,9 +185,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data of client kind
|
// span data of client kind
|
||||||
{
|
{
|
||||||
@ -218,9 +226,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data of producer kind
|
// span data of producer kind
|
||||||
{
|
{
|
||||||
@ -254,9 +264,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data of consumer kind
|
// span data of consumer kind
|
||||||
{
|
{
|
||||||
@ -290,9 +302,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data with no events
|
// span data with no events
|
||||||
{
|
{
|
||||||
@ -313,9 +327,11 @@ func TestModelConversion(t *testing.T) {
|
|||||||
attribute.String("attr2", "bar"),
|
attribute.String("attr2", "bar"),
|
||||||
},
|
},
|
||||||
MessageEvents: nil,
|
MessageEvents: nil,
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// span data with an "error" attribute set to "false"
|
// span data with an "error" attribute set to "false"
|
||||||
{
|
{
|
||||||
@ -348,8 +364,7 @@ func TestModelConversion(t *testing.T) {
|
|||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StatusCode: codes.Unset,
|
Resource: resource,
|
||||||
Resource: resource,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,8 +774,10 @@ func TestTagsTransformation(t *testing.T) {
|
|||||||
attribute.String("key", keyValue),
|
attribute.String("key", keyValue),
|
||||||
attribute.Bool("error", true),
|
attribute.Bool("error", true),
|
||||||
},
|
},
|
||||||
StatusCode: codes.Error,
|
Status: tracesdk.Status{
|
||||||
StatusMessage: statusMessage,
|
Code: codes.Error,
|
||||||
|
Description: statusMessage,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: map[string]string{
|
want: map[string]string{
|
||||||
"error": statusMessage,
|
"error": statusMessage,
|
||||||
|
@ -246,9 +246,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC),
|
||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
MessageEvents: nil,
|
MessageEvents: nil,
|
||||||
StatusCode: codes.Error,
|
Status: sdktrace.Status{
|
||||||
StatusMessage: "404, file not found",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "404, file not found",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
// child
|
// child
|
||||||
{
|
{
|
||||||
@ -266,9 +268,11 @@ func TestExportSpans(t *testing.T) {
|
|||||||
EndTime: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC),
|
EndTime: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC),
|
||||||
Attributes: nil,
|
Attributes: nil,
|
||||||
MessageEvents: nil,
|
MessageEvents: nil,
|
||||||
StatusCode: codes.Error,
|
Status: sdktrace.Status{
|
||||||
StatusMessage: "403, forbidden",
|
Code: codes.Error,
|
||||||
Resource: resource,
|
Description: "403, forbidden",
|
||||||
|
},
|
||||||
|
Resource: resource,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
models := []zkmodel.SpanModel{
|
models := []zkmodel.SpanModel{
|
||||||
|
@ -46,8 +46,7 @@ type ReadOnlySpan interface {
|
|||||||
Attributes() []attribute.KeyValue
|
Attributes() []attribute.KeyValue
|
||||||
Links() []trace.Link
|
Links() []trace.Link
|
||||||
Events() []Event
|
Events() []Event
|
||||||
StatusCode() codes.Code
|
Status() Status
|
||||||
StatusMessage() string
|
|
||||||
Tracer() trace.Tracer
|
Tracer() trace.Tracer
|
||||||
IsRecording() bool
|
IsRecording() bool
|
||||||
InstrumentationLibrary() instrumentation.Library
|
InstrumentationLibrary() instrumentation.Library
|
||||||
@ -92,11 +91,8 @@ type span struct {
|
|||||||
// value of time.Time until the span is ended.
|
// value of time.Time until the span is ended.
|
||||||
endTime time.Time
|
endTime time.Time
|
||||||
|
|
||||||
// statusCode represents the status of this span as a codes.Code value.
|
// status is the status of this span.
|
||||||
statusCode codes.Code
|
status Status
|
||||||
|
|
||||||
// statusMessage represents the status of this span as a string.
|
|
||||||
statusMessage string
|
|
||||||
|
|
||||||
// childSpanCount holds the number of child spans created for this span.
|
// childSpanCount holds the number of child spans created for this span.
|
||||||
childSpanCount int
|
childSpanCount int
|
||||||
@ -154,19 +150,22 @@ func (s *span) IsRecording() bool {
|
|||||||
return !s.startTime.IsZero() && s.endTime.IsZero()
|
return !s.startTime.IsZero() && s.endTime.IsZero()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStatus sets the status of this span in the form of a code and a
|
// SetStatus sets the status of the Span in the form of a code and a
|
||||||
// message. This overrides the existing value of this span's status if one
|
// description, overriding previous values set. The description is only
|
||||||
// exists. Message will be set only if status is error. If this span is not being
|
// included in the set status when the code is for an error. If this span is
|
||||||
// recorded than this method does nothing.
|
// not being recorded than this method does nothing.
|
||||||
func (s *span) SetStatus(code codes.Code, msg string) {
|
func (s *span) SetStatus(code codes.Code, description string) {
|
||||||
if !s.IsRecording() {
|
if !s.IsRecording() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.mu.Lock()
|
|
||||||
s.statusCode = code
|
status := Status{Code: code}
|
||||||
if code == codes.Error {
|
if code == codes.Error {
|
||||||
s.statusMessage = msg
|
status.Description = description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.mu.Lock()
|
||||||
|
s.status = status
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,18 +380,11 @@ func (s *span) Events() []Event {
|
|||||||
return s.interfaceArrayToMessageEventArray()
|
return s.interfaceArrayToMessageEventArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusCode returns the status code of this span.
|
// Status returns the status of this span.
|
||||||
func (s *span) StatusCode() codes.Code {
|
func (s *span) Status() Status {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
return s.statusCode
|
return s.status
|
||||||
}
|
|
||||||
|
|
||||||
// StatusMessage returns the status message of this span.
|
|
||||||
func (s *span) StatusMessage() string {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
return s.statusMessage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstrumentationLibrary returns the instrumentation.Library associated with
|
// InstrumentationLibrary returns the instrumentation.Library associated with
|
||||||
@ -443,8 +435,7 @@ func (s *span) Snapshot() *SpanSnapshot {
|
|||||||
sd.SpanContext = s.spanContext
|
sd.SpanContext = s.spanContext
|
||||||
sd.SpanKind = s.spanKind
|
sd.SpanKind = s.spanKind
|
||||||
sd.StartTime = s.startTime
|
sd.StartTime = s.startTime
|
||||||
sd.StatusCode = s.statusCode
|
sd.Status = s.status
|
||||||
sd.StatusMessage = s.statusMessage
|
|
||||||
|
|
||||||
if s.attributes.evictList.Len() > 0 {
|
if s.attributes.evictList.Len() > 0 {
|
||||||
sd.Attributes = s.attributes.toKeyValue()
|
sd.Attributes = s.attributes.toKeyValue()
|
||||||
@ -580,6 +571,15 @@ func isSampled(s SamplingResult) bool {
|
|||||||
return s.Decision == RecordAndSample
|
return s.Decision == RecordAndSample
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status is the classified state of a Span.
|
||||||
|
type Status struct {
|
||||||
|
// Code is an identifier of a Span's state classification.
|
||||||
|
Code codes.Code
|
||||||
|
// Message is a user hint about why the status was set. It is only
|
||||||
|
// applicable when Code is Error.
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
// SpanSnapshot is a snapshot of a span which contains all the information
|
// SpanSnapshot is a snapshot of a span which contains all the information
|
||||||
// collected by the span. Its main purpose is exporting completed spans.
|
// collected by the span. Its main purpose is exporting completed spans.
|
||||||
// Although SpanSnapshot fields can be accessed and potentially modified,
|
// Although SpanSnapshot fields can be accessed and potentially modified,
|
||||||
@ -597,8 +597,7 @@ type SpanSnapshot struct {
|
|||||||
Attributes []attribute.KeyValue
|
Attributes []attribute.KeyValue
|
||||||
MessageEvents []Event
|
MessageEvents []Event
|
||||||
Links []trace.Link
|
Links []trace.Link
|
||||||
StatusCode codes.Code
|
Status Status
|
||||||
StatusMessage string
|
|
||||||
|
|
||||||
// DroppedAttributeCount contains dropped attributes for the span itself.
|
// DroppedAttributeCount contains dropped attributes for the span itself.
|
||||||
DroppedAttributeCount int
|
DroppedAttributeCount int
|
||||||
|
@ -738,11 +738,13 @@ func TestSetSpanStatus(t *testing.T) {
|
|||||||
TraceID: tid,
|
TraceID: tid,
|
||||||
TraceFlags: 0x1,
|
TraceFlags: 0x1,
|
||||||
}),
|
}),
|
||||||
Parent: sc.WithRemote(true),
|
Parent: sc.WithRemote(true),
|
||||||
Name: "span0",
|
Name: "span0",
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
StatusCode: codes.Error,
|
Status: Status{
|
||||||
StatusMessage: "Error",
|
Code: codes.Error,
|
||||||
|
Description: "Error",
|
||||||
|
},
|
||||||
InstrumentationLibrary: instrumentation.Library{Name: "SpanStatus"},
|
InstrumentationLibrary: instrumentation.Library{Name: "SpanStatus"},
|
||||||
}
|
}
|
||||||
if diff := cmpDiff(got, want); diff != "" {
|
if diff := cmpDiff(got, want); diff != "" {
|
||||||
@ -766,11 +768,13 @@ func TestSetSpanStatusWithoutMessageWhenStatusIsNotError(t *testing.T) {
|
|||||||
TraceID: tid,
|
TraceID: tid,
|
||||||
TraceFlags: 0x1,
|
TraceFlags: 0x1,
|
||||||
}),
|
}),
|
||||||
Parent: sc.WithRemote(true),
|
Parent: sc.WithRemote(true),
|
||||||
Name: "span0",
|
Name: "span0",
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
StatusCode: codes.Ok,
|
Status: Status{
|
||||||
StatusMessage: "",
|
Code: codes.Ok,
|
||||||
|
Description: "",
|
||||||
|
},
|
||||||
InstrumentationLibrary: instrumentation.Library{Name: "SpanStatus"},
|
InstrumentationLibrary: instrumentation.Library{Name: "SpanStatus"},
|
||||||
}
|
}
|
||||||
if diff := cmpDiff(got, want); diff != "" {
|
if diff := cmpDiff(got, want); diff != "" {
|
||||||
@ -1115,10 +1119,10 @@ func TestRecordError(t *testing.T) {
|
|||||||
TraceID: tid,
|
TraceID: tid,
|
||||||
TraceFlags: 0x1,
|
TraceFlags: 0x1,
|
||||||
}),
|
}),
|
||||||
Parent: sc.WithRemote(true),
|
Parent: sc.WithRemote(true),
|
||||||
Name: "span0",
|
Name: "span0",
|
||||||
StatusCode: codes.Unset,
|
Status: Status{Code: codes.Unset},
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
MessageEvents: []Event{
|
MessageEvents: []Event{
|
||||||
{
|
{
|
||||||
Name: semconv.ExceptionEventName,
|
Name: semconv.ExceptionEventName,
|
||||||
@ -1154,11 +1158,13 @@ func TestRecordErrorNil(t *testing.T) {
|
|||||||
TraceID: tid,
|
TraceID: tid,
|
||||||
TraceFlags: 0x1,
|
TraceFlags: 0x1,
|
||||||
}),
|
}),
|
||||||
Parent: sc.WithRemote(true),
|
Parent: sc.WithRemote(true),
|
||||||
Name: "span0",
|
Name: "span0",
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
StatusCode: codes.Unset,
|
Status: Status{
|
||||||
StatusMessage: "",
|
Code: codes.Unset,
|
||||||
|
Description: "",
|
||||||
|
},
|
||||||
InstrumentationLibrary: instrumentation.Library{Name: "RecordErrorNil"},
|
InstrumentationLibrary: instrumentation.Library{Name: "RecordErrorNil"},
|
||||||
}
|
}
|
||||||
if diff := cmpDiff(got, want); diff != "" {
|
if diff := cmpDiff(got, want); diff != "" {
|
||||||
@ -1380,8 +1386,8 @@ func TestReadOnlySpan(t *testing.T) {
|
|||||||
assert.Equal(t, linked, ro.Links()[0].SpanContext)
|
assert.Equal(t, linked, ro.Links()[0].SpanContext)
|
||||||
assert.Equal(t, kv.Key, ro.Events()[0].Attributes[0].Key)
|
assert.Equal(t, kv.Key, ro.Events()[0].Attributes[0].Key)
|
||||||
assert.Equal(t, kv.Value, ro.Events()[0].Attributes[0].Value)
|
assert.Equal(t, kv.Value, ro.Events()[0].Attributes[0].Value)
|
||||||
assert.Equal(t, codes.Ok, ro.StatusCode())
|
assert.Equal(t, codes.Ok, ro.Status().Code)
|
||||||
assert.Equal(t, "", ro.StatusMessage())
|
assert.Equal(t, "", ro.Status().Description)
|
||||||
assert.Equal(t, "ReadOnlySpan", ro.InstrumentationLibrary().Name)
|
assert.Equal(t, "ReadOnlySpan", ro.InstrumentationLibrary().Name)
|
||||||
assert.Equal(t, "3", ro.InstrumentationLibrary().Version)
|
assert.Equal(t, "3", ro.InstrumentationLibrary().Version)
|
||||||
assert.Equal(t, kv.Key, ro.Resource().Attributes()[0].Key)
|
assert.Equal(t, kv.Key, ro.Resource().Attributes()[0].Key)
|
||||||
|
@ -525,9 +525,9 @@ type Span interface {
|
|||||||
SpanContext() SpanContext
|
SpanContext() SpanContext
|
||||||
|
|
||||||
// SetStatus sets the status of the Span in the form of a code and a
|
// SetStatus sets the status of the Span in the form of a code and a
|
||||||
// message. SetStatus overrides the value of previous calls to SetStatus
|
// description, overriding previous values set. The description is only
|
||||||
// on the Span.
|
// included in a status when the code is for an error.
|
||||||
SetStatus(code codes.Code, msg string)
|
SetStatus(code codes.Code, description string)
|
||||||
|
|
||||||
// SetName sets the Span name.
|
// SetName sets the Span name.
|
||||||
SetName(name string)
|
SetName(name string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user