Skip to content

Commit

Permalink
Remove license headers and add notes about origins of code
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosman committed Aug 25, 2021
1 parent a0e4b85 commit 126bd33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
33 changes: 19 additions & 14 deletions propagation/b3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"strings"
)

// this file contains functions and types used for parsing and generating B3 headers.
// it mostly contains code based on the implementation found here:
// https://github.com/open-telemetry/opentelemetry-go-contrib/blob/05ef436536dc499361b6c9d3546662a99c2f918f/propagators/b3/b3_propagator.go
// the only exported functions are MarshalB3TraceContext and UnmarshalB3TraceContext

const (
// Default B3 Header names.
b3ContextHeader = "b3"
Expand Down Expand Up @@ -43,15 +48,15 @@ var (
errInvalidParentSpanIDValue = errors.New("invalid B3 ParentSpanID value found")
)

// extractMultiple reconstructs a SpanContext from header values based on B3
// extractMultiple reconstructs a PropagationContext from header values based on B3
// Multiple header. It is based on the implementation found here:
// https://github.com/openzipkin/zipkin-go/blob/v0.2.2/propagation/b3/spancontext.go
// and adapted to support a SpanContext.
// and adapted to support a PropagationContext.
func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled, flags string) (context.Context, PropagationContext, error) {
var (
err error
requiredCount int
scc = PropagationContext{}
prop = PropagationContext{}
)

// correct values for an existing sampled header are "0" and "1".
Expand All @@ -61,7 +66,7 @@ func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled
case "0", "false":
// Zero value for TraceFlags sample bit is unset.
case "1", "true":
scc.TraceFlags = FlagsSampled
prop.TraceFlags = FlagsSampled
case "":
ctx = withDeferred(ctx, true)
default:
Expand All @@ -76,7 +81,7 @@ func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled
if flags == "1" {
ctx = withDeferred(ctx, false)
ctx = withDebug(ctx, true)
scc.TraceFlags |= FlagsSampled
prop.TraceFlags |= FlagsSampled
}

if traceID != "" {
Expand All @@ -90,7 +95,7 @@ func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled
if err != nil {
return ctx, empty, errInvalidTraceIDHeader
}
scc.TraceID = tID.String()
prop.TraceID = tID.String()
}

if spanID != "" {
Expand All @@ -99,7 +104,7 @@ func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled
if err != nil {
return ctx, empty, errInvalidSpanIDHeader
}
scc.ParentID = sID.String()
prop.ParentID = sID.String()
}

if requiredCount != 0 && requiredCount != 2 {
Expand All @@ -116,7 +121,7 @@ func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled
}
}

return ctx, scc, nil
return ctx, prop, nil
}

// extractSingle reconstructs a SpanContext from contextHeader based on a B3
Expand All @@ -129,7 +134,7 @@ func extractSingle(ctx context.Context, contextHeader string) (context.Context,
}

var (
scc = PropagationContext{}
prop = PropagationContext{}
sampling string
)

Expand Down Expand Up @@ -159,15 +164,15 @@ func extractSingle(ctx context.Context, contextHeader string) (context.Context,
if err != nil {
return ctx, empty, errInvalidTraceIDValue
}
scc.TraceID = tID.String()
prop.TraceID = tID.String()

pos += separatorWidth // {traceID}-

spanID, err := spanIDFromHex(contextHeader[pos : pos+spanIDWidth])
if err != nil {
return ctx, empty, errInvalidSpanIDValue
}
scc.ParentID = spanID.String()
prop.ParentID = spanID.String()
pos += spanIDWidth // {traceID}-{spanID}

if headerLen > pos {
Expand Down Expand Up @@ -204,16 +209,16 @@ func extractSingle(ctx context.Context, contextHeader string) (context.Context,
ctx = withDeferred(ctx, true)
case "d":
ctx = withDebug(ctx, true)
scc.TraceFlags = FlagsSampled
prop.TraceFlags = FlagsSampled
case "1":
scc.TraceFlags = FlagsSampled
prop.TraceFlags = FlagsSampled
case "0":
// Zero value for TraceFlags sample bit is unset.
default:
return ctx, empty, errInvalidSampledByte
}

return ctx, scc, nil
return ctx, prop, nil
}

type b3KeyType int
Expand Down
22 changes: 6 additions & 16 deletions propagation/trace.go
Original file line number Diff line number Diff line change
@@ -1,25 +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 propagation // import "go.opentelemetry.io/otel/trace"
package propagation

import (
"bytes"
"encoding/hex"
"encoding/json"
)

// this file contains definitions of types used in propagation between OpenTelemetry and
// beeline instrumented applications. Many of the types have been lifted from the
// opentelemetry-go sdk found here:
// https://github.com/open-telemetry/opentelemetry-go/blob/c912b179fd595cc7c6eec0b22e6c1371e31241d7/trace/trace.go

const (
// FlagsSampled is a bitmask with the sampled bit set. A SpanContext
// with the sampling bit set means the span is sampled.
Expand All @@ -41,7 +32,6 @@ func (e errorConst) Error() string {
}

// TraceID is a unique identity of a trace.
// nolint:revive // revive complains about stutter of `trace.TraceID`.
type TraceID [16]byte

var nilTraceID TraceID
Expand Down
19 changes: 5 additions & 14 deletions propagation/tracestate.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// 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 propagation

import (
Expand All @@ -21,6 +7,11 @@ import (
"strings"
)

// tracestate contains types and methods for constructing and parsing trace state
// which is included in W3C trace context headers. Most of this code has been lifted
// almost verbatim from:
// https://github.com/open-telemetry/opentelemetry-go/blob/c912b179fd595cc7c6eec0b22e6c1371e31241d7/trace/tracestate.go

var (
maxListMembers = 32

Expand Down

0 comments on commit 126bd33

Please sign in to comment.