1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-07 00:35:52 +02:00

Add SetStatus, SpanContext and IsRecordingEvent (#12)

* Add span apis.
- SetStatus
- SpanContext
- IsRecordingEvent

* fix formatting.

* use grpc/codes.Code

* change Option to SpanOption

* fix format errors.
This commit is contained in:
rghetia
2019-06-19 10:44:46 -07:00
committed by GitHub
parent 063035e9e0
commit 3c3532fb04
11 changed files with 191 additions and 46 deletions

View File

@ -17,6 +17,9 @@ package core
import (
"context"
"fmt"
"strconv"
"google.golang.org/grpc/codes"
"github.com/open-telemetry/opentelemetry-go/api/unit"
)
@ -132,6 +135,12 @@ const (
DELETE
)
var (
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
// conditions.
INVALID_SPAN_CONTEXT = SpanContext{}
)
func (sc SpanContext) HasTraceID() bool {
return sc.TraceIDHigh != 0 || sc.TraceIDLow != 0
}
@ -191,3 +200,44 @@ func (m Measurement) With(id ScopeID) Measurement {
m.ScopeID = id
return m
}
func GrpcCodeToString(s codes.Code) string {
switch c := s; c {
case codes.OK:
return "OK"
case codes.Canceled:
return "CANCELLED"
case codes.Unknown:
return "UNKNOWN"
case codes.InvalidArgument:
return "INVALID_ARGUMENT"
case codes.DeadlineExceeded:
return "DEADLINE_EXCEEDED"
case codes.NotFound:
return "NOT_FOUND"
case codes.AlreadyExists:
return "ALREADY_EXISTS"
case codes.PermissionDenied:
return "PERMISSION_DENIED"
case codes.ResourceExhausted:
return "RESOURCE_EXHAUSTED"
case codes.FailedPrecondition:
return "FAILED_PRECONDITION"
case codes.Aborted:
return "ABORTED"
case codes.OutOfRange:
return "OUT_OF_RANGE"
case codes.Unimplemented:
return "UNIMPLEMENTED"
case codes.Internal:
return "INTERNAL"
case codes.Unavailable:
return "UNAVAILABLE"
case codes.DataLoss:
return "DATA_LOSS"
case codes.Unauthenticated:
return "UNAUTHENTICATED"
default:
return "STATUS_" + strconv.FormatInt(int64(c), 10)
}
}