|
| 1 | +/* |
| 2 | + * Copyright 2012-present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.data.redis.autoconfigure; |
| 18 | + |
| 19 | +import io.lettuce.core.RedisClient; |
| 20 | +import io.lettuce.core.tracing.MicrometerTracing; |
| 21 | +import io.micrometer.observation.ObservationRegistry; |
| 22 | +import org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration; |
| 23 | +import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 24 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| 25 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 26 | +import org.springframework.boot.autoconfigure.data.redis.ClientResourcesBuilderCustomizer; |
| 27 | +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; |
| 28 | +import org.springframework.context.annotation.Bean; |
| 29 | + |
| 30 | +/** |
| 31 | + * Auto-configuration for Lettuce tracing. |
| 32 | + * |
| 33 | + * @author Dũng Đăng Minh |
| 34 | + * @since 4.0.0 |
| 35 | + */ |
| 36 | +@AutoConfiguration( |
| 37 | + before = RedisAutoConfiguration.class, |
| 38 | + after = ObservationAutoConfiguration.class |
| 39 | +) |
| 40 | +@ConditionalOnClass({RedisClient.class, MicrometerTracing.class, ObservationRegistry.class}) |
| 41 | +@ConditionalOnBean(ObservationRegistry.class) |
| 42 | +public final class LettuceTracingAutoConfiguration { |
| 43 | + /// [lettuce doc](https://redis.github.io/lettuce/advanced-usage/#tracing) |
| 44 | + @Bean |
| 45 | + public ClientResourcesBuilderCustomizer lettuceTracing(ObservationRegistry observationRegistry) { |
| 46 | + return (client) -> client.tracing(new MicrometerTracing(observationRegistry, "Redis")); |
| 47 | + } |
| 48 | +} |
0 commit comments