Skip to content

Commit

Permalink
add resource and scope to opencensus metric bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Sep 19, 2022
1 parent 164fcb4 commit 8d8ac9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bridge/opencensus/go.mod
Expand Up @@ -6,7 +6,7 @@ require (
go.opencensus.io v0.23.0
go.opentelemetry.io/otel v1.10.0
go.opentelemetry.io/otel/metric v0.32.0
go.opentelemetry.io/otel/sdk v0.0.0-00010101000000-000000000000
go.opentelemetry.io/otel/sdk v1.10.0
go.opentelemetry.io/otel/sdk/metric v0.32.0
go.opentelemetry.io/otel/trace v1.10.0
)
Expand Down
13 changes: 10 additions & 3 deletions bridge/opencensus/metric.go
Expand Up @@ -24,6 +24,7 @@ import (
"go.opencensus.io/metric/metricexport"

internal "go.opentelemetry.io/otel/bridge/opencensus/internal/ocmetric"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
Expand All @@ -33,11 +34,12 @@ import (
// OpenTelemetry base exporter.
type exporter struct {
base metric.Exporter
res *resource.Resource
}

// NewMetricExporter returns an OpenCensus exporter that exports to an
// OpenTelemetry exporter.
func NewMetricExporter(base metric.Exporter) metricexport.Exporter {
func NewMetricExporter(base metric.Exporter, res *resource.Resource) metricexport.Exporter {
return &exporter{base: base}
}

Expand All @@ -49,8 +51,13 @@ func (e *exporter) ExportMetrics(ctx context.Context, ocmetrics []*ocmetricdata.
return err
}
return e.base.Export(ctx, metricdata.ResourceMetrics{
Resource: resource.NewSchemaless(),
Resource: e.res,
ScopeMetrics: []metricdata.ScopeMetrics{
{Metrics: otelmetrics},
{
Scope: instrumentation.Scope{
Name: "go.opentelemetry.io/otel/bridge/opencensus",
},
Metrics: otelmetrics,
},
}})
}

0 comments on commit 8d8ac9f

Please sign in to comment.