-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
732 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
// This package implements the ot-tracer-* propagator used by Basic Tracer implementation from the OpenTracing project | ||
package ot // import "go.opentelemetry.io/contrib/propagators/ot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
// 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 ot_test | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/label" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
const ( | ||
traceID16Str = "a3ce929d0e0e4736" | ||
traceID32Str = "a1ce929d0e0e4736a3ce929d0e0e4736" | ||
spanIDStr = "00f067aa0ba902b7" | ||
traceIDHeader = "ot-tracer-traceid" | ||
spanIDHeader = "ot-tracer-spanid" | ||
sampledHeader = "ot-tracer-sampled" | ||
baggageKey = "test" | ||
baggageValue = "value123" | ||
baggageHeader = "ot-baggage-test" | ||
baggageKey2 = "test2" | ||
baggageValue2 = "value456" | ||
baggageHeader2 = "ot-baggage-test2" | ||
) | ||
|
||
var ( | ||
traceID16 = trace.TraceID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa3, 0xce, 0x92, 0x9d, 0x0e, 0x0e, 0x47, 0x36} | ||
traceID32 = trace.TraceID{0xa1, 0xce, 0x92, 0x9d, 0x0e, 0x0e, 0x47, 0x36, 0xa3, 0xce, 0x92, 0x9d, 0x0e, 0x0e, 0x47, 0x36} | ||
spanID = trace.SpanID{0x00, 0xf0, 0x67, 0xaa, 0x0b, 0xa9, 0x02, 0xb7} | ||
emptyBaggage = &label.Set{} | ||
// TODO: once baggage extraction is supported, re-enable this | ||
// baggageSet = label.NewSet( | ||
// label.String(baggageKey, baggageValue), | ||
// label.String(baggageKey2, baggageValue2), | ||
// ) | ||
) | ||
|
||
type extractTest struct { | ||
name string | ||
headers map[string]string | ||
expected trace.SpanContext | ||
baggage *label.Set | ||
} | ||
|
||
var extractHeaders = []extractTest{ | ||
{ | ||
"empty", | ||
map[string]string{}, | ||
trace.SpanContext{}, | ||
emptyBaggage, | ||
}, | ||
{ | ||
"sampling state not sample", | ||
map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "0", | ||
}, | ||
trace.SpanContext{ | ||
TraceID: traceID32, | ||
SpanID: spanID, | ||
}, | ||
emptyBaggage, | ||
}, | ||
{ | ||
"sampling state sampled", | ||
map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
baggageHeader: baggageValue, | ||
}, | ||
trace.SpanContext{ | ||
TraceID: traceID32, | ||
SpanID: spanID, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
emptyBaggage, | ||
// TODO: once baggage extraction is supported, re-enable this | ||
// &baggageSet, | ||
}, | ||
{ | ||
"left padding 64 bit trace ID", | ||
map[string]string{ | ||
traceIDHeader: traceID16Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
trace.SpanContext{ | ||
TraceID: traceID16, | ||
SpanID: spanID, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
emptyBaggage, | ||
}, | ||
{ | ||
"128 bit trace ID", | ||
map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
trace.SpanContext{ | ||
TraceID: traceID32, | ||
SpanID: spanID, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
emptyBaggage, | ||
}, | ||
} | ||
|
||
var invalidExtractHeaders = []extractTest{ | ||
{ | ||
name: "trace ID length > 32", | ||
headers: map[string]string{ | ||
traceIDHeader: traceID32Str + "0000", | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "trace ID length is not 32 or 16", | ||
headers: map[string]string{ | ||
traceIDHeader: "1234567890abcd01234", | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "span ID length is not 16 or 32", | ||
headers: map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: spanIDStr + "0000", | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "invalid trace ID", | ||
headers: map[string]string{ | ||
traceIDHeader: "zcd00v0000000000a3ce929d0e0e4736", | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "invalid span ID", | ||
headers: map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: "00f0wiredba902b7", | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "invalid sampled", | ||
headers: map[string]string{ | ||
traceIDHeader: traceID32Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "wired", | ||
}, | ||
}, | ||
{ | ||
name: "missing headers", | ||
headers: map[string]string{}, | ||
}, | ||
{ | ||
name: "empty header value", | ||
headers: map[string]string{ | ||
traceIDHeader: "", | ||
}, | ||
}, | ||
} | ||
|
||
type injectTest struct { | ||
name string | ||
sc trace.SpanContext | ||
wantHeaders map[string]string | ||
baggage []label.KeyValue | ||
} | ||
|
||
var injectHeaders = []injectTest{ | ||
{ | ||
name: "sampled", | ||
sc: trace.SpanContext{ | ||
TraceID: traceID32, | ||
SpanID: spanID, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
wantHeaders: map[string]string{ | ||
traceIDHeader: traceID16Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "1", | ||
}, | ||
}, | ||
{ | ||
name: "not sampled", | ||
sc: trace.SpanContext{ | ||
TraceID: traceID32, | ||
SpanID: spanID, | ||
}, | ||
baggage: []label.KeyValue{ | ||
label.String(baggageKey, baggageValue), | ||
label.String(baggageKey2, baggageValue2), | ||
}, | ||
wantHeaders: map[string]string{ | ||
traceIDHeader: traceID16Str, | ||
spanIDHeader: spanIDStr, | ||
sampledHeader: "0", | ||
baggageHeader: baggageValue, | ||
baggageHeader2: baggageValue2, | ||
}, | ||
}, | ||
} | ||
|
||
var invalidInjectHeaders = []injectTest{ | ||
{ | ||
name: "empty", | ||
sc: trace.SpanContext{}, | ||
}, | ||
{ | ||
name: "missing traceID", | ||
sc: trace.SpanContext{ | ||
SpanID: spanID, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
}, | ||
{ | ||
name: "missing spanID", | ||
sc: trace.SpanContext{ | ||
TraceID: traceID32, | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
}, | ||
{ | ||
name: "missing both traceID and spanID", | ||
sc: trace.SpanContext{ | ||
TraceFlags: trace.FlagsSampled, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 ot_test | ||
|
||
import ( | ||
"go.opentelemetry.io/contrib/propagators/ot" | ||
"go.opentelemetry.io/otel" | ||
) | ||
|
||
func ExampleOT() { | ||
otPropagator := ot.OT{} | ||
// register ot propagator | ||
otel.SetTextMapPropagator(otPropagator) | ||
} |
Oops, something went wrong.