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

Commit

Permalink
Allow overriding the DisplayName prefix in stackdriver metric descrip…
Browse files Browse the repository at this point in the history
…tors (#583)

Closes #582
  • Loading branch information
groob authored and Ramon Nogueira committed Mar 14, 2018
1 parent 137758e commit 6891f95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exporter/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ type Options struct {
// with type global and no resource labels will be used.
// Optional.
Resource *monitoredrespb.MonitoredResource

// MetricPrefix overrides the OpenCensus prefix of a stackdriver metric.
// Optional.
MetricPrefix string
}

// Exporter is a stats.Exporter and trace.Exporter
Expand Down
7 changes: 6 additions & 1 deletion exporter/stackdriver/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
const maxTimeSeriesPerUpload = 200
const opencensusTaskKey = "opencensus_task"
const opencensusTaskDescription = "Opencensus task identifier"
const defaultDisplayNamePrefix = "OpenCensus"

// statsExporter exports stats to the Stackdriver Monitoring.
type statsExporter struct {
Expand Down Expand Up @@ -278,11 +279,15 @@ func (e *statsExporter) createMeasure(ctx context.Context, vd *view.Data) error
}

metricKind = metricpb.MetricDescriptor_CUMULATIVE
displayNamePrefix := defaultDisplayNamePrefix
if e.o.MetricPrefix != "" {
displayNamePrefix = e.o.MetricPrefix
}

md, err = createMetricDescriptor(ctx, e.c, &monitoringpb.CreateMetricDescriptorRequest{
Name: monitoring.MetricProjectPath(e.o.ProjectID),
MetricDescriptor: &metricpb.MetricDescriptor{
DisplayName: path.Join("OpenCensus", viewName),
DisplayName: path.Join(displayNamePrefix, viewName),
Description: m.Description(),
Unit: m.Unit(),
Type: namespacedViewName(viewName, false),
Expand Down

0 comments on commit 6891f95

Please sign in to comment.