diff --git a/stackdriver.go b/stackdriver.go index 7524b44..7477bf5 100644 --- a/stackdriver.go +++ b/stackdriver.go @@ -344,8 +344,12 @@ func NewExporter(o Options) (*Exporter, error) { if err != nil { return nil, fmt.Errorf("stackdriver: detect resource: %s", err) } + // Populate internal resource labels for defaulting project_id, location, and // generic resource labels of applicable monitored resources. + if res.Labels == nil { + res.Labels = make(map[string]string) + } res.Labels[stackdriverProjectID] = o.ProjectID res.Labels[resourcekeys.CloudKeyZone] = o.Location res.Labels[stackdriverGenericTaskNamespace] = "default"