(config *config)
| 80 | var newExporter = newStackdriverExporter |
| 81 | |
| 82 | func 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 |
nothing calls this directly
no test coverage detected