Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the otel opencensus bridge #7483

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/codeboten_oc-bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: use the otel opencensus bridge when telemetry.useOtelForInternalMetrics is enabled

# One or more tracking issues or pull requests related to the change
issues: [7483]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
1 change: 1 addition & 0 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ require (
go.opentelemetry.io/contrib/propagators/b3 v1.15.0 // indirect
go.opentelemetry.io/contrib/zpages v0.40.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/bridge/opencensus v0.37.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.37.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcorecol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ go.opentelemetry.io/contrib/zpages v0.40.0 h1:BDLYzPHju8GRJH2V+0CtF4WF/sDnylZnsp
go.opentelemetry.io/contrib/zpages v0.40.0/go.mod h1:hKOEjOa1AA8kbqQRWR5gSj4WrjWjHQMFv5jeRGDgVRM=
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
go.opentelemetry.io/otel/bridge/opencensus v0.37.0 h1:ieH3gw7b1eg90ARsFAlAsX5LKVZgnCYfaDwRrK6xLHU=
go.opentelemetry.io/otel/bridge/opencensus v0.37.0/go.mod h1:ddiK+1PE68l/Xk04BGTh9Y6WIcxcLrmcVxVlS0w5WZ0=
go.opentelemetry.io/otel/exporters/prometheus v0.37.0 h1:NQc0epfL0xItsmGgSXgfbH2C1fq2VLXkZoDFsfRNHpc=
go.opentelemetry.io/otel/exporters/prometheus v0.37.0/go.mod h1:hB8qWjsStK36t50/R0V2ULFb4u95X/Q6zupXLgvjTh8=
go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs=
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
go.opentelemetry.io/contrib/propagators/b3 v1.15.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/bridge/opencensus v0.37.0
go.opentelemetry.io/otel/exporters/prometheus v0.37.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/sdk v1.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ go.opentelemetry.io/contrib/zpages v0.40.0 h1:BDLYzPHju8GRJH2V+0CtF4WF/sDnylZnsp
go.opentelemetry.io/contrib/zpages v0.40.0/go.mod h1:hKOEjOa1AA8kbqQRWR5gSj4WrjWjHQMFv5jeRGDgVRM=
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
go.opentelemetry.io/otel/bridge/opencensus v0.37.0 h1:ieH3gw7b1eg90ARsFAlAsX5LKVZgnCYfaDwRrK6xLHU=
go.opentelemetry.io/otel/bridge/opencensus v0.37.0/go.mod h1:ddiK+1PE68l/Xk04BGTh9Y6WIcxcLrmcVxVlS0w5WZ0=
go.opentelemetry.io/otel/exporters/prometheus v0.37.0 h1:NQc0epfL0xItsmGgSXgfbH2C1fq2VLXkZoDFsfRNHpc=
go.opentelemetry.io/otel/exporters/prometheus v0.37.0/go.mod h1:hB8qWjsStK36t50/R0V2ULFb4u95X/Q6zupXLgvjTh8=
go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs=
Expand Down
11 changes: 7 additions & 4 deletions service/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opencensus"
otelprom "go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -107,10 +108,10 @@ func (tel *telemetryInitializer) init(buildInfo component.BuildInfo, logger *zap
if err := tel.initOpenTelemetry(telAttrs, promRegistry); err != nil {
return err
}
}

if err := tel.initOpenCensus(cfg, telAttrs, promRegistry); err != nil {
return err
} else {
if err := tel.initOpenCensus(cfg, telAttrs, promRegistry); err != nil {
return err
}
}

logger.Info(
Expand Down Expand Up @@ -200,6 +201,7 @@ func (tel *telemetryInitializer) initOpenCensus(cfg telemetry.Config, telAttrs m
func (tel *telemetryInitializer) initOpenTelemetry(attrs map[string]string, promRegistry prometheus.Registerer) error {
// Initialize the ocRegistry, still used by the process metrics.
tel.ocRegistry = ocmetric.NewRegistry()
metricproducer.GlobalManager().AddProducer(tel.ocRegistry)

var resAttrs []attribute.KeyValue
for k, v := range attrs {
Expand All @@ -223,6 +225,7 @@ func (tel *telemetryInitializer) initOpenTelemetry(attrs map[string]string, prom
if err != nil {
return fmt.Errorf("error creating otel prometheus exporter: %w", err)
}
exporter.RegisterProducer(opencensus.NewMetricProducer())
tel.mp = sdkmetric.NewMeterProvider(
sdkmetric.WithResource(res),
sdkmetric.WithReader(exporter),
Expand Down
10 changes: 3 additions & 7 deletions service/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,9 @@ func TestTelemetryInit(t *testing.T) {
name: "UseOpenTelemetryForInternalMetrics",
useOtel: true,
expectedMetrics: map[string]metricValue{
metricPrefix + ocPrefix + counterName: {
value: 13,
labels: map[string]string{
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
},
metricPrefix + ocPrefix + counterName + "_total": {
value: 13,
labels: map[string]string{},
},
metricPrefix + otelPrefix + counterName + "_total": {
value: 13,
Expand Down