github.com/SaurabhDubey-Groww/go-cloud@v0.0.0-20221124105541-b26c29285fd8/internal/oc/metrics.go (about) 1 // Copyright 2019 The Go Cloud Development Kit Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package oc supports OpenCensus tracing and metrics for the Go Cloud Development Kit. 16 package oc 17 18 import ( 19 "go.opencensus.io/plugin/ocgrpc" 20 "go.opencensus.io/stats" 21 "go.opencensus.io/stats/view" 22 "go.opencensus.io/tag" 23 ) 24 25 // LatencyMeasure returns the measure for method call latency used 26 // by Go CDK APIs. 27 func LatencyMeasure(pkg string) *stats.Float64Measure { 28 return stats.Float64( 29 pkg+"/latency", 30 "Latency of method call", 31 stats.UnitMilliseconds) 32 } 33 34 // Tag keys used for the standard Go CDK views. 35 var ( 36 MethodKey = tag.MustNewKey("gocdk_method") 37 StatusKey = tag.MustNewKey("gocdk_status") 38 ProviderKey = tag.MustNewKey("gocdk_provider") 39 ) 40 41 // Views returns the views supported by Go CDK APIs. 42 func Views(pkg string, latencyMeasure *stats.Float64Measure) []*view.View { 43 return []*view.View{ 44 { 45 Name: pkg + "/completed_calls", 46 Measure: latencyMeasure, 47 Description: "Count of method calls by provider, method and status.", 48 TagKeys: []tag.Key{ProviderKey, MethodKey, StatusKey}, 49 Aggregation: view.Count(), 50 }, 51 { 52 Name: pkg + "/latency", 53 Measure: latencyMeasure, 54 Description: "Distribution of method latency, by provider and method.", 55 TagKeys: []tag.Key{ProviderKey, MethodKey}, 56 Aggregation: ocgrpc.DefaultMillisecondsDistribution, 57 }, 58 } 59 }