MCPcopy
hub / github.com/grpc/grpc-go / newStackdriverExporter

Function newStackdriverExporter

gcp/observability/opencensus.go:82–108  ·  view source on GitHub ↗
(config *config)

Source from the content-addressed store, hash-verified

80var newExporter = newStackdriverExporter
81
82func newStackdriverExporter(config *config) (tracingMetricsExporter, error) {
83 // Create the Stackdriver exporter, which is shared between tracing and stats
84 mr := monitoredresource.Autodetect()
85 logger.Infof("Detected MonitoredResource:: %+v", mr)
86 var err error
87 // Custom labels completely overwrite any labels generated in the OpenCensus
88 // library, including their label that uniquely identifies the process.
89 // Thus, generate a unique process identifier here to uniquely identify
90 // process for metrics exporting to function correctly.
91 metricsLabels := make(map[string]string, len(config.Labels)+1)
92 for k, v := range config.Labels {
93 metricsLabels[k] = v
94 }
95 metricsLabels["opencensus_task"] = generateUniqueProcessIdentifier()
96 exporter, err := stackdriver.NewExporter(stackdriver.Options{
97 ProjectID: config.ProjectID,
98 MonitoredResource: mr,
99 DefaultMonitoringLabels: labelsToMonitoringLabels(metricsLabels),
100 DefaultTraceAttributes: labelsToTraceAttributes(config.Labels),
101 MonitoringClientOptions: cOptsDisableLogTrace,
102 TraceClientOptions: cOptsDisableLogTrace,
103 })
104 if err != nil {
105 return nil, fmt.Errorf("failed to create Stackdriver exporter: %v", err)
106 }
107 return exporter, nil
108}
109
110// generateUniqueProcessIdentifier returns a unique process identifier for the
111// process this code is running in. This is the same way the OpenCensus library

Callers

nothing calls this directly

Calls 5

labelsToMonitoringLabelsFunction · 0.85
labelsToTraceAttributesFunction · 0.85
InfofMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected