Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Add a public method to convert OpenCensus View to MetricDescriptor. #277

Merged
Merged
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
10 changes: 10 additions & 0 deletions stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import (
"go.opencensus.io/trace"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
metricpb "google.golang.org/genproto/googleapis/api/metric"
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"

commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
Expand Down Expand Up @@ -469,6 +470,15 @@ func (e *Exporter) Flush() {
e.traceExporter.Flush()
}

// ViewToMetricDescriptor converts an OpenCensus view to a MetricDescriptor.
//
// This is useful for cases when you want to use your Go code as source of
// truth of metric descriptors. You can extract or define views in a central
// place, then call this method to generate MetricDescriptors.
func (e *Exporter) ViewToMetricDescriptor(ctx context.Context, v *view.View) (*metricpb.MetricDescriptor, error) {
return e.statsExporter.viewToMetricDescriptor(ctx, v)
}

func (o Options) handleError(err error) {
if o.OnError != nil {
o.OnError(err)
Expand Down