func afterNewServiceInfoHolder()

in pkg/rules/nacos/service_holder/nacos_go_client_service_holder_setup.go [42:73]


func afterNewServiceInfoHolder(call api.CallContext, holder *naming_cache.ServiceInfoHolder) {
	if !experimental.NacosEnabler.Enable() {
		return
	}
	reg, err := experimental.GlobalMeter.RegisterCallback(func(ctx context.Context, observer metric.Observer) error {
		attrSet := attribute.NewSet(attribute.KeyValue{
			Key:   "namespace",
			Value: attribute.StringValue(call.GetKeyData("namespace").(string)),
		}, attribute.KeyValue{
			Key:   "cache.dir",
			Value: attribute.StringValue(call.GetKeyData("cacheDir").(string)),
		}, attribute.KeyValue{
			Key:   "update.cache.when.empty",
			Value: attribute.StringValue(call.GetKeyData("updateCacheWhenEmpty").(string)),
		}, attribute.KeyValue{
			Key:   "not.load.cache.at.start",
			Value: attribute.StringValue(call.GetKeyData("notLoadCacheAtStart").(string)),
		})
		count := 0
		holder.ServiceInfoMap.Range(func(k, v interface{}) bool {
			count++
			return true
		})
		observer.ObserveInt64(experimental.ClientServiceInfoMapSize, int64(count), metric.WithAttributeSet(attrSet))
		return nil
	}, experimental.ClientServiceInfoMapSize)
	if err != nil {
		log.Printf("[otel nacos] failed to register metrics for service info holder")
	} else {
		holder.OtelReg = reg
	}
}