1 /* 2 * 3 * Copyright 2024 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // Package stats provides internal stats related functionality. 20 package stats 21 22 import "context" 23 24 // Labels are the labels for metrics. 25 type Labels struct { 26 // TelemetryLabels are the telemetry labels to record. 27 TelemetryLabels map[string]string 28 } 29 30 type labelsKey struct{} 31 32 // GetLabels returns the Labels stored in the context, or nil if there is one. 33 func GetLabels(ctx context.Context) *Labels { 34 labels, _ := ctx.Value(labelsKey{}).(*Labels) 35 return labels 36 } 37 38 // SetLabels sets the Labels in the context. 39 func SetLabels(ctx context.Context, labels *Labels) context.Context { 40 // could also append 41 return context.WithValue(ctx, labelsKey{}, labels) 42 } 43