3

I am new in Google PubSub. I am using GoLang for the client library.

How to see the opencensus metrics that recorded by the google-cloud-go library?

I already success publish a message to Google PubSub. And now I want to see this metrics, but I can not find these metrics in Google Stackdriver.

PublishLatency = stats.Float64(statsPrefix+"publish_roundtrip_latency", "The latency in milliseconds per publish batch", stats.UnitMilliseconds)

https://github.com/googleapis/google-cloud-go/blob/25803d86c6f5d3a315388d369bf6ddecfadfbfb5/pubsub/trace.go#L59

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

This is curious; I'm surprised to see these (machine-generated) APIs sprinkled with OpenCensus (Stats) integration.

I've not tried this but I'm familiar with OpenCensus.

One of OpenCensus' benefits is that it loosely-couples the generation of e.g. metrics from the consumption. So, while the code defines the metrics (and views), I expect (!?) the API leaves it to you to choose which Exporter(s) you'd like to use and to configure these.

In your code, you'll need to import the Stackdriver (and any other exporters you wish to use) and then follow these instructions:

https://opencensus.io/exporters/supported-exporters/go/stackdriver/#creating-the-exporter

NOTE I encourage you to look at the OpenCensus Agent too as this further decouples your code; you reference the generic Opencensus Agent in your code and configure the agent to route e.g. metrics to e.g. Stackdriver.

For Stackdriver, you will need to configure the exporter with a GCP Project ID and that project will need to have Stackdriver Monitor enabled (and configured). I've not used Stackdriver in some months but this used to require a manual step too. Easiest way to check is to visit:

https://console.cloud.google.com/monitoring/?project=[[YOUR-PROJECT]]

If I understand the intent (!) correctly, I expect API calls will then record stats at the metrics in the views defined in the code that you referenced.

Once you're confident that metrics are being shipped to Stackdriver, the easiest way to confirm this is to query a metric using Stackdriver's metrics explorer:

https://console.cloud.google.com/monitoring/metrics-explorer?project=[[YOUR-PROJECT]]

You may wish to test this approach using the Prometheus Exporter because it's simpler. After configuring the Prometheus Exporter, when you run your code, it will be create an HTTP server and you can curl the metrics that are being generated on:

http://localhost:8888/metrics

NOTE Opencensus is being (!?) deprecated in favor of a replacement solution called OpenTelemetry.

halfer
  • 19,824
  • 17
  • 99
  • 186
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • Hi Daz. As a long-standing policy we tend to remove "hope this helps" and other similar sign-offs. No-one posts hoping it doesn't help, so the phrase is rather redundant. There are several discussions in Meta and some documentation in the Help Centre about the general preference for technical writing here. I can supply some links on request. – halfer Jun 04 '20 at 10:39
  • I am sorry to hear you are unhappy, and I hope you are able to change your mind over the long term. No-one here edits out of malice - technical writing _is_ the preference, and is broadly supported by the editing mechanisms and established moderation processes. I assume that the Stackdriver docs don't have "Hiya" at the start, "Hope you're well in these trying times" in the intro, and "Let me know if you need more info :-)" in the summary. The same writing approach applies here. – halfer Jun 04 '20 at 16:49