internal/dcensus: add env and app labels
Add labels to the trace and stats exporters to identify
the deployment environment and application name.
These aren't strictly necessary because they can be inferred from
ServiceID, but they should make it easier to group and filter.
@@ -137,6 +137,7 @@ func exportToStackdriver(ctx context.Context, cfg *config.Config) {
ProjectID: cfg.ProjectID,
MonitoredResource: (*monitoredResource)(cfg.MonitoredResource),
TraceSpansBufferMaxBytes: 32 * 1024 * 1024, // 32 MiB
+ DefaultMonitoringLabels: stackdriverLabels(cfg),
})
if err != nil {
log.Fatalf(ctx, "error creating trace exporter: %v", err)
@@ -148,9 +149,6 @@ func exportToStackdriver(ctx context.Context, cfg *config.Config) {
func NewViewExporter(cfg *config.Config) (_ *stackdriver.Exporter, err error) {
defer derrors.Wrap(&err, "NewViewExporter()")
- labels := &stackdriver.Labels{}
- labels.Set("version", cfg.AppVersionLabel(), "Version label of the running binary")
-
// Views must be associated with the instance, else we run into overlapping
// timeseries problems. Note that generic_task is used because the
// gae_instance resource type is not supported for metrics:
@@ -167,10 +165,18 @@ func NewViewExporter(cfg *config.Config) (_ *stackdriver.Exporter, err error) {
"task_id": cfg.InstanceID,
},
},
- DefaultMonitoringLabels: labels,
+ DefaultMonitoringLabels: stackdriverLabels(cfg),
})
}
+func stackdriverLabels(cfg *config.Config) *stackdriver.Labels {
+ labels := &stackdriver.Labels{}
+ labels.Set("version", cfg.AppVersionLabel(), "Version label of the running binary")
+ labels.Set("env", cfg.DeploymentEnvironment(), "deployment environment")
+ labels.Set("app", cfg.Application(), "application name")
+ return labels
+}
+
// Customizations of ochttp views. Views are updated as follows:
// + ClientHost and ServerRoute are added to resp. client and server metrics.
// Since these are bounded cardinality in our metrics, they are useful to
