Skip to content

Commit

Permalink
Merge branch 'main' into dep-oc-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 9, 2021
2 parents 8cb533d + b1d1d52 commit dbf1599
Show file tree
Hide file tree
Showing 37 changed files with 853 additions and 61 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ updates:
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /bridge/opencensus/test
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /example/prom-collector
Expand Down
3 changes: 2 additions & 1 deletion bridge/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
go.opencensus.io v0.22.6-0.20201102222123-380f4078db9f
go.opentelemetry.io/otel v1.0.0-RC2
go.opentelemetry.io/otel/metric v0.22.0
go.opentelemetry.io/otel/oteltest v1.0.0-RC2
go.opentelemetry.io/otel/sdk v1.0.0-RC2
go.opentelemetry.io/otel/sdk/export/metric v0.22.0
go.opentelemetry.io/otel/trace v1.0.0-RC2
Expand Down Expand Up @@ -71,3 +70,5 @@ replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporter
replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace

replace go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp => ../../exporters/otlp/otlpmetric/otlpmetrichttp

replace go.opentelemetry.io/otel/bridge/opencensus/test => ./test
56 changes: 56 additions & 0 deletions bridge/opencensus/internal/oc2otel/attributes_test.go
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 bridge/opencensus/internal/oc2otel/tracer_start_options_test.go
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")
}
}
Loading

0 comments on commit dbf1599

Please sign in to comment.