Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

GetMetricDisplayName option does not work #318

Open
kaoet opened this issue Mar 16, 2023 · 1 comment
Open

GetMetricDisplayName option does not work #318

kaoet opened this issue Mar 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@kaoet
Copy link

kaoet commented Mar 16, 2023

Please answer these questions before submitting a bug report.

What version of the Exporter are you using?

v0.13.4

What version of OpenCensus are you using?

v0.23.0

What version of Go are you using?

1.21

What did you do?

If possible, provide a recipe for reproducing the error.

I created a exporter with custom GetMetricDisplayName option:

exporter, err := stackdriver.NewExporter(stackdriver.Options{
	MetricPrefix: "custom.googleapis.com/myapp/",
	GetMetricDisplayName: func(view *view.View) string {
		return path.Join("My App", view.Name)
	},
})

What did you expect to see?

I want the display name of the metric displayed in Cloud Monitoring to be My App/my_metric.

What did you see instead?

The display name is still OpenCensus/my_metric.

Additional context

Add any other context about the problem here.

I found there are two places a MetricDescriptor was built.

  • displayName := se.displayName(metric.Descriptor.Name)
    metricKind, valueType := metricDescriptorTypeToMetricKind(metric)
    sdm := &googlemetricpb.MetricDescriptor{
    Name: fmt.Sprintf("projects/%s/metricDescriptors/%s", se.o.ProjectID, metricType),
    DisplayName: displayName,
    Description: metric.Descriptor.Description,
    Unit: string(metric.Descriptor.Unit),
    Type: metricType,
    MetricKind: metricKind,
    ValueType: valueType,
    Labels: metricLableKeysToLabels(se.defaultLabels, metric.Descriptor.LabelKeys),
    }
  • var displayName string
    if e.o.GetMetricDisplayName == nil {
    displayName = e.displayName(viewName)
    } else {
    displayName = e.o.GetMetricDisplayName(v)
    }
    res := &metricpb.MetricDescriptor{
    Name: fmt.Sprintf("projects/%s/metricDescriptors/%s", e.o.ProjectID, metricType),
    DisplayName: displayName,
    Description: v.Description,
    Unit: unit,
    Type: metricType,
    MetricKind: metricKind,
    ValueType: valueType,
    Labels: newLabelDescriptors(e.defaultLabels, v.TagKeys),
    }

As you can see in the first place, GetMetricDisplayName was not used, and it directly constructs the display name with the default display name prefix. But in the second place, GetMetricDisplayName was used if it's not nil.

I suspect that's the reason it's not working.

@kaoet kaoet added the bug Something isn't working label Mar 16, 2023
@dashpole
Copy link
Contributor

Sorry for the slow response. That does look like a bug. Feel free to open a PR with a fix, and we can get it merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants