1515// Package stackdriver contains the OpenCensus exporters for
1616// Stackdriver Monitoring and Stackdriver Tracing.
1717//
18- // Please note that the Stackdriver exporter is currently experimental.
18+ // This exporter can be used to send metrics to Stackdriver Monitoring and traces
19+ // to Stackdriver trace.
1920//
20- // The package uses Application Default Credentials to authenticate. See
21- // https://developers.google.com/identity/protocols/application-default-credentials
21+ // The package uses Application Default Credentials to authenticate by default.
22+ // See: https://developers.google.com/identity/protocols/application-default-credentials
23+ //
24+ // Alternatively, pass the authentication options in both the MonitoringClientOptions
25+ // and the TraceClientOptions fields of Options.
26+ //
27+ // Stackdriver Monitoring
28+ //
29+ // This exporter support exporting OpenCensus views to Stackdriver Monitoring.
30+ // Each registered view becomes a metric in Stackdriver Monitoring, with the
31+ // tags becoming labels.
32+ //
33+ // The aggregation function determines the metric kind: LastValue aggregations
34+ // generate Gauge metrics and all other aggregations generate Cumulative metrics.
35+ //
36+ // In order to be able to push your stats to Stackdriver Monitoring, you must:
37+ //
38+ // 1. Create a Cloud project: https://support.google.com/cloud/answer/6251787?hl=en
39+ // 2. Enable billing: https://support.google.com/cloud/answer/6288653#new-billing
40+ // 3. Enable the Stackdriver Monitoring API: https://console.cloud.google.com/apis/dashboard
41+ // 4. Make sure you have a Premium Stackdriver account: https://cloud.google.com/monitoring/accounts/tiers
42+ //
43+ // These steps enable the API but don't require that your app is hosted on Google Cloud Platform.
44+ //
45+ // Stackdriver Trace
46+ //
47+ // This exporter supports exporting Trace Spans to Stackdriver Trace. It also
48+ // supports the Google "Cloud Trace" propagation format header.
2249package stackdriver // import "contrib.go.opencensus.io/exporter/stackdriver"
2350
2451import (
@@ -71,19 +98,52 @@ type Options struct {
7198 // Optional.
7299 BundleCountThreshold int
73100
74- // Resource is an optional field that represents the Stackdriver
75- // MonitoredResource, a resource that can be used for monitoring.
76- // If no custom ResourceDescriptor is set, a default MonitoredResource
77- // with type global and no resource labels will be used.
78- // Optional.
101+ // Resource sets the MonitoredResource against which all views will be
102+ // recorded by this exporter.
103+ //
104+ // All Stackdriver metrics created by this exporter are custom metrics,
105+ // so only a limited number of MonitoredResource types are supported, see:
106+ // https://cloud.google.com/monitoring/custom-metrics/creating-metrics#which-resource
107+ //
108+ // An important consideration when setting the Resource here is that
109+ // Stackdriver Monitoring only allows a single writer per
110+ // TimeSeries, see: https://cloud.google.com/monitoring/api/v3/metrics-details#intro-time-series
111+ // A TimeSeries is uniquely defined by the metric type name
112+ // (constructed from the view name and the MetricPrefix), the Resource field,
113+ // and the set of label key/value pairs (in OpenCensus terminology: tag).
114+ //
115+ // If no custom Resource is set, a default MonitoredResource
116+ // with type global and no resource labels will be used. If you explicitly
117+ // set this field, you may also want to set custom DefaultMonitoringLabels.
118+ //
119+ // Optional, but encouraged.
79120 Resource * monitoredrespb.MonitoredResource
80121
81- // MetricPrefix overrides the OpenCensus prefix of a stackdriver metric.
82- // Optional.
122+ // MetricPrefix overrides the prefix of a Stackdriver metric type names .
123+ // Optional. If unset defaults to "OpenCensus".
83124 MetricPrefix string
84125
85- // DefaultTraceAttributes will be appended to every span that is exported.
126+ // DefaultTraceAttributes will be appended to every span that is exported to
127+ // Stackdriver Trace.
86128 DefaultTraceAttributes map [string ]interface {}
129+
130+ // DefaultMonitoringLabels are labels added to every metric created by this
131+ // exporter in Stackdriver Monitoring.
132+ //
133+ // If unset, this defaults to a single label with key "opencensus_task" and
134+ // value "go-<pid>@<hostname>". This default ensures that the set of labels
135+ // together with the default Resource (global) are unique to this
136+ // process, as required by Stackdriver Monitoring.
137+ //
138+ // If you set DefaultMonitoringLabels, make sure that the Resource field
139+ // together with these labels is unique to the
140+ // current process. This is to ensure that there is only a single writer to
141+ // each TimeSeries in Stackdriver.
142+ //
143+ // Set this to &Labels{} (a pointer to an empty Labels) to avoid getting the
144+ // default "opencensus_task" label. You should only do this if you know that
145+ // the Resource you set uniquely identifies this Go process.
146+ DefaultMonitoringLabels * Labels
87147}
88148
89149// Exporter is a stats.Exporter and trace.Exporter
@@ -106,7 +166,7 @@ func NewExporter(o Options) (*Exporter, error) {
106166 }
107167 o .ProjectID = creds .ProjectID
108168 }
109- se , err := newStatsExporter (o )
169+ se , err := newStatsExporter (o , true )
110170 if err != nil {
111171 return nil , err
112172 }
0 commit comments