-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dep-oc-utils
- Loading branch information
Showing
37 changed files
with
853 additions
and
61 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
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,56 @@ | ||
// 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 oc2otel | ||
|
||
import ( | ||
"testing" | ||
|
||
octrace "go.opencensus.io/trace" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
func TestAttributes(t *testing.T) { | ||
in := []octrace.Attribute{ | ||
octrace.BoolAttribute("bool", true), | ||
octrace.Int64Attribute("int64", 49), | ||
octrace.Float64Attribute("float64", 1.618), | ||
octrace.StringAttribute("key", "val"), | ||
} | ||
|
||
want := []attribute.KeyValue{ | ||
attribute.Bool("bool", true), | ||
attribute.Int64("int64", 49), | ||
attribute.Float64("float64", 1.618), | ||
attribute.String("key", "val"), | ||
} | ||
got := Attributes(in) | ||
|
||
if len(got) != len(want) { | ||
t.Errorf("Attributes conversion failed: want %#v, got %#v", want, got) | ||
} | ||
for i := range got { | ||
if g, w := got[i], want[i]; g != w { | ||
t.Errorf("Attributes conversion: want %#v, got %#v", w, g) | ||
} | ||
} | ||
} | ||
|
||
func TestAttributeValueUnknown(t *testing.T) { | ||
got := AttributeValue([]byte{}) | ||
if got != attribute.StringValue("unknown") { | ||
t.Errorf("AttributeValue of unknown wrong: %#v", got) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
bridge/opencensus/internal/oc2otel/tracer_start_options_test.go
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,52 @@ | ||
// 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 oc2otel | ||
|
||
import ( | ||
"testing" | ||
|
||
octrace "go.opencensus.io/trace" | ||
|
||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
func TestStartOptionsSpanKind(t *testing.T) { | ||
conv := map[int]trace.SpanKind{ | ||
octrace.SpanKindClient: trace.SpanKindClient, | ||
octrace.SpanKindServer: trace.SpanKindServer, | ||
octrace.SpanKindUnspecified: trace.SpanKindUnspecified, | ||
} | ||
|
||
for oc, otel := range conv { | ||
ocOpts := []octrace.StartOption{octrace.WithSpanKind(oc)} | ||
otelOpts, err := StartOptions(ocOpts) | ||
if err != nil { | ||
t.Errorf("StartOptions errored: %v", err) | ||
continue | ||
} | ||
c := trace.NewSpanStartConfig(otelOpts...) | ||
if c.SpanKind() != otel { | ||
t.Errorf("conversion of SpanKind start option: got %v, want %v", c.SpanKind(), otel) | ||
} | ||
} | ||
} | ||
|
||
func TestStartOptionsSamplerErrors(t *testing.T) { | ||
ocOpts := []octrace.StartOption{octrace.WithSampler(octrace.AlwaysSample())} | ||
_, err := StartOptions(ocOpts) | ||
if err == nil { | ||
t.Error("StartOptions should error Sampler option") | ||
} | ||
} |
Oops, something went wrong.