mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-30 21:20:04 +02:00
Add scope version to opencensus trace and metric bridges (#4584)
This commit is contained in:
parent
3f17bcb6c3
commit
1074d64d04
@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
### Added
|
||||
|
||||
- Add `go.opentelemetry.io/otel/bridge/opencensus.InstallTraceBridge`, which installs the OpenCensus trace bridge, and replaces `opencensus.NewTracer`. (#4567)
|
||||
- Add scope version to trace and metric bridges in `go.opentelemetry.io/otel/bridge/opencensus`. (#4584)
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
@ -56,7 +56,8 @@ func (p *MetricProducer) Produce(context.Context) ([]metricdata.ScopeMetrics, er
|
||||
}
|
||||
return []metricdata.ScopeMetrics{{
|
||||
Scope: instrumentation.Scope{
|
||||
Name: scopeName,
|
||||
Name: scopeName,
|
||||
Version: Version(),
|
||||
},
|
||||
Metrics: otelmetrics,
|
||||
}}, err
|
||||
|
@ -64,7 +64,8 @@ func TestMetricProducer(t *testing.T) {
|
||||
},
|
||||
expected: []metricdata.ScopeMetrics{{
|
||||
Scope: instrumentation.Scope{
|
||||
Name: scopeName,
|
||||
Name: scopeName,
|
||||
Version: Version(),
|
||||
},
|
||||
Metrics: []metricdata.Metrics{
|
||||
{
|
||||
@ -112,7 +113,8 @@ func TestMetricProducer(t *testing.T) {
|
||||
},
|
||||
expected: []metricdata.ScopeMetrics{{
|
||||
Scope: instrumentation.Scope{
|
||||
Name: scopeName,
|
||||
Name: scopeName,
|
||||
Version: Version(),
|
||||
},
|
||||
Metrics: []metricdata.Metrics{
|
||||
{
|
||||
|
@ -36,9 +36,14 @@ func NewTracer(tracer trace.Tracer) octrace.Tracer {
|
||||
// the global OpenCensus tracer implementation. Once the bridge is installed,
|
||||
// spans recorded using OpenCensus are redirected to the OpenTelemetry SDK.
|
||||
func InstallTraceBridge(opts ...TraceOption) {
|
||||
octrace.DefaultTracer = newTraceBridge(opts)
|
||||
}
|
||||
|
||||
func newTraceBridge(opts []TraceOption) octrace.Tracer {
|
||||
cfg := newTraceConfig(opts)
|
||||
tracer := cfg.tp.Tracer(scopeName)
|
||||
octrace.DefaultTracer = internal.NewTracer(tracer)
|
||||
return internal.NewTracer(
|
||||
cfg.tp.Tracer(scopeName, trace.WithInstrumentationVersion(Version())),
|
||||
)
|
||||
}
|
||||
|
||||
// OTelSpanContextToOC converts from an OpenTelemetry SpanContext to an
|
||||
|
39
bridge/opencensus/trace_test.go
Normal file
39
bridge/opencensus/trace_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
// 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 opencensus // import "go.opentelemetry.io/otel/bridge/opencensus"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
)
|
||||
|
||||
func TestNewTraceBridge(t *testing.T) {
|
||||
exporter := tracetest.NewInMemoryExporter()
|
||||
tp := trace.NewTracerProvider(trace.WithSyncer(exporter))
|
||||
bridge := newTraceBridge([]TraceOption{WithTracerProvider(tp)})
|
||||
_, span := bridge.StartSpan(context.Background(), "foo")
|
||||
span.End()
|
||||
gotSpans := exporter.GetSpans()
|
||||
require.Len(t, gotSpans, 1)
|
||||
gotSpan := gotSpans[0]
|
||||
assert.Equal(t, gotSpan.InstrumentationLibrary.Name, scopeName)
|
||||
assert.Equal(t, gotSpan.InstrumentationLibrary.Version, Version())
|
||||
}
|
20
bridge/opencensus/version.go
Normal file
20
bridge/opencensus/version.go
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 opencensus // import "go.opentelemetry.io/otel/bridge/opencensus"
|
||||
|
||||
// Version is the current release version of the opencensus bridge.
|
||||
func Version() string {
|
||||
return "0.42.0"
|
||||
}
|
Loading…
Reference in New Issue
Block a user