Skip to content

Commit acf7146

Browse files
authored
Opencensus bridge: migrate from README to Go docs (open-telemetry#4561)
1 parent d3e31c3 commit acf7146

File tree

4 files changed

+87
-96
lines changed

4 files changed

+87
-96
lines changed

bridge/opencensus/README.md

Lines changed: 0 additions & 81 deletions
This file was deleted.

bridge/opencensus/doc.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,51 @@
1313
// limitations under the License.
1414

1515
// Package opencensus provides a migration bridge from OpenCensus to
16-
// OpenTelemetry. The NewTracer function should be used to create an
17-
// OpenCensus Tracer from an OpenTelemetry Tracer. This Tracer can be use in
18-
// place of any existing OpenCensus Tracer and will generate OpenTelemetry
19-
// spans for traces. These spans will be exported by the OpenTelemetry
20-
// TracerProvider the original OpenTelemetry Tracer came from.
16+
// OpenTelemetry for metrics and traces. The bridge incorporates metrics and
17+
// traces from OpenCensus into the OpenTelemetry SDK, combining them with
18+
// metrics and traces from OpenTelemetry instrumentation.
2119
//
22-
// There are known limitations to this bridge:
20+
// # Migration Guide
2321
//
24-
// - The AddLink method for OpenCensus Spans is not compatible with the
25-
// OpenTelemetry Span. No link can be added to an OpenTelemetry Span once it
26-
// is started. Any calls to this method for the OpenCensus Span will result
27-
// in an error being sent to the OpenTelemetry default ErrorHandler.
22+
// For most applications, it would be difficult to migrate an application
23+
// from OpenCensus to OpenTelemetry all-at-once. Libraries used by the
24+
// application may still be using OpenCensus, and the application itself may
25+
// have many lines of instrumentation.
2826
//
29-
// - The NewContext method of the OpenCensus Tracer cannot embed an OpenCensus
30-
// Span in a context unless that Span was created by that Tracer.
27+
// Bridges help in this situation by allowing your application to have "mixed"
28+
// instrumentation, while incorporating all instrumentation into a single
29+
// export path. To migrate with bridges, a user would:
3130
//
32-
// - Conversion of custom OpenCensus Samplers to OpenTelemetry is not
33-
// implemented. An error will be sent to the OpenTelemetry default
34-
// ErrorHandler if this is attempted.
31+
// 1. Configure the OpenTelemetry SDK for metrics and traces, with the OpenTelemetry exporters matching to your current OpenCensus exporters.
32+
// 2. Install this OpenCensus bridge, which sends OpenCensus telemetry to your new OpenTelemetry exporters.
33+
// 3. Over time, migrate your instrumentation from OpenCensus to OpenTelemetry.
34+
// 4. Once all instrumentation is migrated, remove the OpenCensus bridge.
35+
//
36+
// With this approach, you can migrate your telemetry, including in dependent
37+
// libraries over time without disruption.
38+
//
39+
// # Warnings
40+
//
41+
// Installing a metric or tracing bridge will cause OpenCensus telemetry to be
42+
// exported by OpenTelemetry exporters. Since OpenCensus telemetry uses globals,
43+
// installing a bridge will result in telemetry collection from _all_ libraries
44+
// that use OpenCensus, including some you may not expect, such as the
45+
// telemetry exporter itself.
46+
//
47+
// # Limitations
48+
//
49+
// There are known limitations to the trace bridge:
50+
//
51+
// - The AddLink method for OpenCensus Spans is ignored, and an error is sent
52+
// to the OpenTelemetry ErrorHandler.
53+
// - The NewContext method of the OpenCensus Tracer cannot embed an OpenCensus
54+
// Span in a context unless that Span was created by that Tracer.
55+
// - Conversion of custom OpenCensus Samplers to OpenTelemetry is not
56+
// implemented, and An error will be sent to the OpenTelemetry ErrorHandler.
57+
//
58+
// There are known limitations to the metric bridge:
59+
// - Summary-typed metrics are dropped
60+
// - GaugeDistribution-typed metrics are dropped
61+
// - Histogram's SumOfSquaredDeviation field is dropped
62+
// - Exemplars on Histograms are dropped
3563
package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus"

bridge/opencensus/example_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package opencensus_test
16+
17+
import (
18+
octrace "go.opencensus.io/trace"
19+
20+
"go.opentelemetry.io/otel"
21+
"go.opentelemetry.io/otel/bridge/opencensus"
22+
"go.opentelemetry.io/otel/sdk/metric"
23+
)
24+
25+
func ExampleNewTracer() {
26+
// Create an OpenTelemetry Tracer to use to record spans.
27+
tracer := otel.GetTracerProvider().Tracer("go.opentelemetry.io/otel/bridge/opencensus")
28+
// Overwrite the OpenCensus DefaultTracer so that it uses OpenTelemetry
29+
// rather than OpenCensus.
30+
octrace.DefaultTracer = opencensus.NewTracer(tracer)
31+
}
32+
33+
func ExampleNewMetricProducer() {
34+
// Create the OpenCensus Metric bridge.
35+
bridge := opencensus.NewMetricProducer()
36+
// Add the bridge as a producer to your reader.
37+
// If using a push exporter, such as OTLP exporter,
38+
// use metric.NewPeriodicReader with metric.WithProducer option.
39+
// If using a pull exporter which acts as a reader, such as prometheus exporter,
40+
// use a dedicated option like prometheus.WithProducer.
41+
reader := metric.NewManualReader(metric.WithProducer(bridge))
42+
// Add the reader to your MeterProvider.
43+
_ = metric.NewMeterProvider(metric.WithReader(reader))
44+
}
File renamed without changes.

0 commit comments

Comments
 (0)