[VOL-5051] - Build and deploy voltctl
[VOL-5152]
[VOL-4961]
[VOL-5063]
[VOL-4966]
[VOL-4893]
[VOL-4906]
go.mod
go.sum
vendor/modules.txt
------------------
o Update voltha-lib-go dep to 7.5.3
o Update voltha-protos dep to 5.4.11
o make mod-update
Makefile
makefiles/
o Add more repo:onf-make makefile logic
o make LOCAL_FIX_PERMS=1 mod-update need to work around docker perm problems.
internal/
pkg/
vendor/
---------
o Update copyright ending date to span 2024.
o make mod-update to regenerate vendor/
Change-Id: Ib89fd6a9cc15c7e08b1274b110dd8141832557e9
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/api.go b/vendor/go.opentelemetry.io/otel/api/trace/api.go
new file mode 100644
index 0000000..3f15f48
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/api.go
@@ -0,0 +1,314 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+import (
+ "context"
+ "time"
+
+ "go.opentelemetry.io/otel/codes"
+ "go.opentelemetry.io/otel/label"
+)
+
+// TracerProvider provides access to instrumentation Tracers.
+type TracerProvider interface {
+ // Tracer creates an implementation of the Tracer interface.
+ // The instrumentationName must be the name of the library providing
+ // instrumentation. This name may be the same as the instrumented code
+ // only if that code provides built-in instrumentation. If the
+ // instrumentationName is empty, then a implementation defined default
+ // name will be used instead.
+ Tracer(instrumentationName string, opts ...TracerOption) Tracer
+}
+
+// TracerConfig is a group of options for a Tracer.
+//
+// Most users will use the tracer options instead.
+type TracerConfig struct {
+ // InstrumentationVersion is the version of the instrumentation library.
+ InstrumentationVersion string
+}
+
+// NewTracerConfig applies all the options to a returned TracerConfig.
+// The default value for all the fields of the returned TracerConfig are the
+// default zero value of the type. Also, this does not perform any validation
+// on the returned TracerConfig (e.g. no uniqueness checking or bounding of
+// data), instead it is left to the implementations of the SDK to perform this
+// action.
+func NewTracerConfig(opts ...TracerOption) *TracerConfig {
+ config := new(TracerConfig)
+ for _, option := range opts {
+ option.Apply(config)
+ }
+ return config
+}
+
+// TracerOption applies an options to a TracerConfig.
+type TracerOption interface {
+ Apply(*TracerConfig)
+}
+
+type instVersionTracerOption string
+
+func (o instVersionTracerOption) Apply(c *TracerConfig) { c.InstrumentationVersion = string(o) }
+
+// WithInstrumentationVersion sets the instrumentation version for a Tracer.
+func WithInstrumentationVersion(version string) TracerOption {
+ return instVersionTracerOption(version)
+}
+
+type Tracer interface {
+ // Start a span.
+ Start(ctx context.Context, spanName string, opts ...SpanOption) (context.Context, Span)
+}
+
+// ErrorConfig provides options to set properties of an error
+// event at the time it is recorded.
+//
+// Most users will use the error options instead.
+type ErrorConfig struct {
+ Timestamp time.Time
+ StatusCode codes.Code
+}
+
+// ErrorOption applies changes to ErrorConfig that sets options when an error event is recorded.
+type ErrorOption func(*ErrorConfig)
+
+// WithErrorTime sets the time at which the error event should be recorded.
+func WithErrorTime(t time.Time) ErrorOption {
+ return func(c *ErrorConfig) {
+ c.Timestamp = t
+ }
+}
+
+// WithErrorStatus indicates the span status that should be set when recording an error event.
+func WithErrorStatus(s codes.Code) ErrorOption {
+ return func(c *ErrorConfig) {
+ c.StatusCode = s
+ }
+}
+
+type Span interface {
+ // Tracer returns tracer used to create this span. Tracer cannot be nil.
+ Tracer() Tracer
+
+ // End completes the span. No updates are allowed to span after it
+ // ends. The only exception is setting status of the span.
+ End(options ...SpanOption)
+
+ // AddEvent adds an event to the span.
+ AddEvent(ctx context.Context, name string, attrs ...label.KeyValue)
+ // AddEventWithTimestamp adds an event with a custom timestamp
+ // to the span.
+ AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
+
+ // IsRecording returns true if the span is active and recording events is enabled.
+ IsRecording() bool
+
+ // RecordError records an error as a span event.
+ RecordError(ctx context.Context, err error, opts ...ErrorOption)
+
+ // SpanContext returns span context of the span. Returned SpanContext is usable
+ // even after the span ends.
+ SpanContext() SpanContext
+
+ // 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 on the Span.
+ //
+ // The default span status is OK, so it is not necessary to
+ // explicitly set an OK status on successful Spans unless it
+ // is to add an OK message or to override a previous status on the Span.
+ SetStatus(code codes.Code, msg string)
+
+ // SetName sets the name of the span.
+ SetName(name string)
+
+ // Set span attributes
+ SetAttributes(kv ...label.KeyValue)
+}
+
+// SpanConfig is a group of options for a Span.
+//
+// Most users will use span options instead.
+type SpanConfig struct {
+ // Attributes describe the associated qualities of a Span.
+ Attributes []label.KeyValue
+ // Timestamp is a time in a Span life-cycle.
+ Timestamp time.Time
+ // Links are the associations a Span has with other Spans.
+ Links []Link
+ // Record is the recording state of a Span.
+ Record bool
+ // NewRoot identifies a Span as the root Span for a new trace. This is
+ // commonly used when an existing trace crosses trust boundaries and the
+ // remote parent span context should be ignored for security.
+ NewRoot bool
+ // SpanKind is the role a Span has in a trace.
+ SpanKind SpanKind
+}
+
+// NewSpanConfig applies all the options to a returned SpanConfig.
+// The default value for all the fields of the returned SpanConfig are the
+// default zero value of the type. Also, this does not perform any validation
+// on the returned SpanConfig (e.g. no uniqueness checking or bounding of
+// data). Instead, it is left to the implementations of the SDK to perform this
+// action.
+func NewSpanConfig(opts ...SpanOption) *SpanConfig {
+ c := new(SpanConfig)
+ for _, option := range opts {
+ option.Apply(c)
+ }
+ return c
+}
+
+// SpanOption applies an option to a SpanConfig.
+type SpanOption interface {
+ Apply(*SpanConfig)
+}
+
+type attributeSpanOption []label.KeyValue
+
+func (o attributeSpanOption) Apply(c *SpanConfig) {
+ c.Attributes = append(c.Attributes, []label.KeyValue(o)...)
+}
+
+// WithAttributes adds the attributes to a span. These attributes are meant to
+// provide additional information about the work the Span represents. The
+// attributes are added to the existing Span attributes, i.e. this does not
+// overwrite.
+func WithAttributes(attributes ...label.KeyValue) SpanOption {
+ return attributeSpanOption(attributes)
+}
+
+type timestampSpanOption time.Time
+
+func (o timestampSpanOption) Apply(c *SpanConfig) { c.Timestamp = time.Time(o) }
+
+// WithTimestamp sets the time of a Span life-cycle moment (e.g. started or
+// stopped).
+func WithTimestamp(t time.Time) SpanOption {
+ return timestampSpanOption(t)
+}
+
+type linksSpanOption []Link
+
+func (o linksSpanOption) Apply(c *SpanConfig) { c.Links = append(c.Links, []Link(o)...) }
+
+// WithLinks adds links to a Span. The links are added to the existing Span
+// links, i.e. this does not overwrite.
+func WithLinks(links ...Link) SpanOption {
+ return linksSpanOption(links)
+}
+
+type recordSpanOption bool
+
+func (o recordSpanOption) Apply(c *SpanConfig) { c.Record = bool(o) }
+
+// WithRecord specifies that the span should be recorded. It is important to
+// note that implementations may override this option, i.e. if the span is a
+// child of an un-sampled trace.
+func WithRecord() SpanOption {
+ return recordSpanOption(true)
+}
+
+type newRootSpanOption bool
+
+func (o newRootSpanOption) Apply(c *SpanConfig) { c.NewRoot = bool(o) }
+
+// WithNewRoot specifies that the Span should be treated as a root Span. Any
+// existing parent span context will be ignored when defining the Span's trace
+// identifiers.
+func WithNewRoot() SpanOption {
+ return newRootSpanOption(true)
+}
+
+type spanKindSpanOption SpanKind
+
+func (o spanKindSpanOption) Apply(c *SpanConfig) { c.SpanKind = SpanKind(o) }
+
+// WithSpanKind sets the SpanKind of a Span.
+func WithSpanKind(kind SpanKind) SpanOption {
+ return spanKindSpanOption(kind)
+}
+
+// Link is used to establish relationship between two spans within the same Trace or
+// across different Traces. Few examples of Link usage.
+// 1. Batch Processing: A batch of elements may contain elements associated with one
+// or more traces/spans. Since there can only be one parent SpanContext, Link is
+// used to keep reference to SpanContext of all elements in the batch.
+// 2. Public Endpoint: A SpanContext in incoming client request on a public endpoint
+// is untrusted from service provider perspective. In such case it is advisable to
+// start a new trace with appropriate sampling decision.
+// However, it is desirable to associate incoming SpanContext to new trace initiated
+// on service provider side so two traces (from Client and from Service Provider) can
+// be correlated.
+type Link struct {
+ SpanContext
+ Attributes []label.KeyValue
+}
+
+// SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span
+// will be processed and visualized by various backends.
+type SpanKind int
+
+const (
+ // As a convenience, these match the proto definition, see
+ // opentelemetry/proto/trace/v1/trace.proto
+ //
+ // The unspecified value is not a valid `SpanKind`. Use
+ // `ValidateSpanKind()` to coerce a span kind to a valid
+ // value.
+ SpanKindUnspecified SpanKind = 0
+ SpanKindInternal SpanKind = 1
+ SpanKindServer SpanKind = 2
+ SpanKindClient SpanKind = 3
+ SpanKindProducer SpanKind = 4
+ SpanKindConsumer SpanKind = 5
+)
+
+// ValidateSpanKind returns a valid span kind value. This will coerce
+// invalid values into the default value, SpanKindInternal.
+func ValidateSpanKind(spanKind SpanKind) SpanKind {
+ switch spanKind {
+ case SpanKindInternal,
+ SpanKindServer,
+ SpanKindClient,
+ SpanKindProducer,
+ SpanKindConsumer:
+ // valid
+ return spanKind
+ default:
+ return SpanKindInternal
+ }
+}
+
+// String returns the specified name of the SpanKind in lower-case.
+func (sk SpanKind) String() string {
+ switch sk {
+ case SpanKindInternal:
+ return "internal"
+ case SpanKindServer:
+ return "server"
+ case SpanKindClient:
+ return "client"
+ case SpanKindProducer:
+ return "producer"
+ case SpanKindConsumer:
+ return "consumer"
+ default:
+ return "unspecified"
+ }
+}
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/context.go b/vendor/go.opentelemetry.io/otel/api/trace/context.go
new file mode 100644
index 0000000..0f330e3
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/context.go
@@ -0,0 +1,55 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+import (
+ "context"
+)
+
+type traceContextKeyType int
+
+const (
+ currentSpanKey traceContextKeyType = iota
+ remoteContextKey
+)
+
+// ContextWithSpan creates a new context with a current span set to
+// the passed span.
+func ContextWithSpan(ctx context.Context, span Span) context.Context {
+ return context.WithValue(ctx, currentSpanKey, span)
+}
+
+// SpanFromContext returns the current span stored in the context.
+func SpanFromContext(ctx context.Context) Span {
+ if span, has := ctx.Value(currentSpanKey).(Span); has {
+ return span
+ }
+ return noopSpan{}
+}
+
+// ContextWithRemoteSpanContext creates a new context with a remote
+// span context set to the passed span context.
+func ContextWithRemoteSpanContext(ctx context.Context, sc SpanContext) context.Context {
+ return context.WithValue(ctx, remoteContextKey, sc)
+}
+
+// RemoteSpanContextFromContext returns the remote span context stored
+// in the context.
+func RemoteSpanContextFromContext(ctx context.Context) SpanContext {
+ if sc, ok := ctx.Value(remoteContextKey).(SpanContext); ok {
+ return sc
+ }
+ return EmptySpanContext()
+}
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/doc.go b/vendor/go.opentelemetry.io/otel/api/trace/doc.go
new file mode 100644
index 0000000..24f2dfb
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/doc.go
@@ -0,0 +1,16 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package trace provides tracing support.
+package trace // import "go.opentelemetry.io/otel/api/trace"
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/noop_span.go b/vendor/go.opentelemetry.io/otel/api/trace/noop_span.go
new file mode 100644
index 0000000..f014f21
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/noop_span.go
@@ -0,0 +1,75 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+import (
+ "context"
+ "time"
+
+ "go.opentelemetry.io/otel/codes"
+ "go.opentelemetry.io/otel/label"
+)
+
+type noopSpan struct {
+}
+
+var _ Span = noopSpan{}
+
+// SpanContext returns an invalid span context.
+func (noopSpan) SpanContext() SpanContext {
+ return EmptySpanContext()
+}
+
+// IsRecording always returns false for NoopSpan.
+func (noopSpan) IsRecording() bool {
+ return false
+}
+
+// SetStatus does nothing.
+func (noopSpan) SetStatus(status codes.Code, msg string) {
+}
+
+// SetError does nothing.
+func (noopSpan) SetError(v bool) {
+}
+
+// SetAttributes does nothing.
+func (noopSpan) SetAttributes(attributes ...label.KeyValue) {
+}
+
+// End does nothing.
+func (noopSpan) End(options ...SpanOption) {
+}
+
+// RecordError does nothing.
+func (noopSpan) RecordError(ctx context.Context, err error, opts ...ErrorOption) {
+}
+
+// Tracer returns noop implementation of Tracer.
+func (noopSpan) Tracer() Tracer {
+ return noopTracer{}
+}
+
+// AddEvent does nothing.
+func (noopSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue) {
+}
+
+// AddEventWithTimestamp does nothing.
+func (noopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue) {
+}
+
+// SetName does nothing.
+func (noopSpan) SetName(name string) {
+}
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/noop_trace.go b/vendor/go.opentelemetry.io/otel/api/trace/noop_trace.go
new file mode 100644
index 0000000..954f9e8
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/noop_trace.go
@@ -0,0 +1,29 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+import (
+ "context"
+)
+
+type noopTracer struct{}
+
+var _ Tracer = noopTracer{}
+
+// Start starts a noop span.
+func (noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
+ span := noopSpan{}
+ return ContextWithSpan(ctx, span), span
+}
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/noop_trace_provider.go b/vendor/go.opentelemetry.io/otel/api/trace/noop_trace_provider.go
new file mode 100644
index 0000000..414c8e3
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/noop_trace_provider.go
@@ -0,0 +1,30 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+type noopTracerProvider struct{}
+
+var _ TracerProvider = noopTracerProvider{}
+
+// Tracer returns noop implementation of Tracer.
+func (p noopTracerProvider) Tracer(_ string, _ ...TracerOption) Tracer {
+ return noopTracer{}
+}
+
+// NoopTracerProvider returns a noop implementation of TracerProvider. The
+// Tracer and Spans created from the noop provider will also be noop.
+func NoopTracerProvider() TracerProvider {
+ return noopTracerProvider{}
+}
diff --git a/vendor/go.opentelemetry.io/otel/api/trace/span_context.go b/vendor/go.opentelemetry.io/otel/api/trace/span_context.go
new file mode 100644
index 0000000..914ce5f
--- /dev/null
+++ b/vendor/go.opentelemetry.io/otel/api/trace/span_context.go
@@ -0,0 +1,197 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace
+
+import (
+ "bytes"
+ "encoding/hex"
+ "encoding/json"
+)
+
+const (
+ // FlagsSampled is a bitmask with the sampled bit set. A SpanContext
+ // with the sampling bit set means the span is sampled.
+ FlagsSampled = byte(0x01)
+ // FlagsDeferred is a bitmask with the deferred bit set. A SpanContext
+ // with the deferred bit set means the sampling decision has been
+ // defered to the receiver.
+ FlagsDeferred = byte(0x02)
+ // FlagsDebug is a bitmask with the debug bit set.
+ FlagsDebug = byte(0x04)
+
+ ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase"
+
+ ErrInvalidTraceIDLength errorConst = "hex encoded trace-id must have length equals to 32"
+ ErrNilTraceID errorConst = "trace-id can't be all zero"
+
+ ErrInvalidSpanIDLength errorConst = "hex encoded span-id must have length equals to 16"
+ ErrNilSpanID errorConst = "span-id can't be all zero"
+)
+
+type errorConst string
+
+func (e errorConst) Error() string {
+ return string(e)
+}
+
+// ID is a unique identity of a trace.
+type ID [16]byte
+
+var nilTraceID ID
+var _ json.Marshaler = nilTraceID
+
+// IsValid checks whether the trace ID is valid. A valid trace ID does
+// not consist of zeros only.
+func (t ID) IsValid() bool {
+ return !bytes.Equal(t[:], nilTraceID[:])
+}
+
+// MarshalJSON implements a custom marshal function to encode TraceID
+// as a hex string.
+func (t ID) MarshalJSON() ([]byte, error) {
+ return json.Marshal(t.String())
+}
+
+// String returns the hex string representation form of a TraceID
+func (t ID) String() string {
+ return hex.EncodeToString(t[:])
+}
+
+// SpanID is a unique identify of a span in a trace.
+type SpanID [8]byte
+
+var nilSpanID SpanID
+var _ json.Marshaler = nilSpanID
+
+// IsValid checks whether the span ID is valid. A valid span ID does
+// not consist of zeros only.
+func (s SpanID) IsValid() bool {
+ return !bytes.Equal(s[:], nilSpanID[:])
+}
+
+// MarshalJSON implements a custom marshal function to encode SpanID
+// as a hex string.
+func (s SpanID) MarshalJSON() ([]byte, error) {
+ return json.Marshal(s.String())
+}
+
+// String returns the hex string representation form of a SpanID
+func (s SpanID) String() string {
+ return hex.EncodeToString(s[:])
+}
+
+// IDFromHex returns a TraceID from a hex string if it is compliant
+// with the w3c trace-context specification.
+// See more at https://www.w3.org/TR/trace-context/#trace-id
+func IDFromHex(h string) (ID, error) {
+ t := ID{}
+ if len(h) != 32 {
+ return t, ErrInvalidTraceIDLength
+ }
+
+ if err := decodeHex(h, t[:]); err != nil {
+ return t, err
+ }
+
+ if !t.IsValid() {
+ return t, ErrNilTraceID
+ }
+ return t, nil
+}
+
+// SpanIDFromHex returns a SpanID from a hex string if it is compliant
+// with the w3c trace-context specification.
+// See more at https://www.w3.org/TR/trace-context/#parent-id
+func SpanIDFromHex(h string) (SpanID, error) {
+ s := SpanID{}
+ if len(h) != 16 {
+ return s, ErrInvalidSpanIDLength
+ }
+
+ if err := decodeHex(h, s[:]); err != nil {
+ return s, err
+ }
+
+ if !s.IsValid() {
+ return s, ErrNilSpanID
+ }
+ return s, nil
+}
+
+func decodeHex(h string, b []byte) error {
+ for _, r := range h {
+ switch {
+ case 'a' <= r && r <= 'f':
+ continue
+ case '0' <= r && r <= '9':
+ continue
+ default:
+ return ErrInvalidHexID
+ }
+ }
+
+ decoded, err := hex.DecodeString(h)
+ if err != nil {
+ return err
+ }
+
+ copy(b, decoded)
+ return nil
+}
+
+// SpanContext contains basic information about the span - its trace
+// ID, span ID and trace flags.
+type SpanContext struct {
+ TraceID ID
+ SpanID SpanID
+ TraceFlags byte
+}
+
+// EmptySpanContext is meant for internal use to return invalid span
+// context during error conditions.
+func EmptySpanContext() SpanContext {
+ return SpanContext{}
+}
+
+// IsValid checks if the span context is valid. A valid span context
+// has a valid trace ID and a valid span ID.
+func (sc SpanContext) IsValid() bool {
+ return sc.HasTraceID() && sc.HasSpanID()
+}
+
+// HasTraceID checks if the span context has a valid trace ID.
+func (sc SpanContext) HasTraceID() bool {
+ return sc.TraceID.IsValid()
+}
+
+// HasSpanID checks if the span context has a valid span ID.
+func (sc SpanContext) HasSpanID() bool {
+ return sc.SpanID.IsValid()
+}
+
+// IsDeferred returns if the deferred bit is set in the trace flags.
+func (sc SpanContext) IsDeferred() bool {
+ return sc.TraceFlags&FlagsDeferred == FlagsDeferred
+}
+
+// IsDebug returns if the debug bit is set in the trace flags.
+func (sc SpanContext) IsDebug() bool {
+ return sc.TraceFlags&FlagsDebug == FlagsDebug
+}
+
+// IsSampled returns if the sampling bit is set in the trace flags.
+func (sc SpanContext) IsSampled() bool {
+ return sc.TraceFlags&FlagsSampled == FlagsSampled
+}