From fab451a6494a0493b716bb973544f9f51525d8ae Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 14 Jan 2024 16:26:43 +0800 Subject: [PATCH] ready maybe Signed-off-by: Adrian Cole --- README.md | 2 ++ .../java/brave/example/TracingFactory.java | 9 ++++++-- armeria/src/main/resources/logback.xml | 2 +- docker-compose-eureka.yml | 21 +------------------ docker-compose.yml | 4 ++-- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bc2a8f9..8cfc81b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ Here are the example projects you can try: * Runtime: Armeria, SLF4J 1.7, JRE 21 * Trace Instrumentation: [Armeria](https://armeria.dev/), [SLF4J](https://github.com/openzipkin/brave/tree/master/context/slf4j) * Trace Configuration: [Brave API](https://github.com/openzipkin/brave/tree/master/brave#setup) [Java](armeria/src/main/java/brave/example/HttpTracingFactory.java) + * You can also use Eureka discovery like this: + * `BRAVE_EXAMPLE=armeria docker-compose -f docker-compose.yml -f docker-compose-eureka.yml up` * [armeria-kafka](armeria-kafka) `BRAVE_EXAMPLE=armeria-kafka docker-compose -f docker-compose.yml -f docker-compose-kafka.yml up` * Runtime: Armeria, Kafka Clients and Streams 2.7, SLF4J 1.7, JRE 21 diff --git a/armeria/src/main/java/brave/example/TracingFactory.java b/armeria/src/main/java/brave/example/TracingFactory.java index af3b7e4..221ac72 100644 --- a/armeria/src/main/java/brave/example/TracingFactory.java +++ b/armeria/src/main/java/brave/example/TracingFactory.java @@ -1,5 +1,7 @@ package brave.example; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import brave.Tracing; import brave.baggage.BaggageField; import brave.baggage.BaggagePropagation; @@ -15,12 +17,13 @@ import com.linecorp.armeria.client.eureka.EurekaEndpointGroup; import com.linecorp.armeria.common.SessionProtocol; import com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext; +import com.linecorp.armeria.common.logging.RequestLogLevelMapper; import java.io.IOException; -import java.util.logging.Logger; import zipkin2.reporter.BytesMessageSender; import zipkin2.reporter.brave.AsyncZipkinSpanHandler; final class HttpTracingFactory { + static final Logger LOGGER = LoggerFactory.getLogger(HttpTracingFactory.class); static final BaggageField USER_NAME = BaggageField.create("userName"); /** Decides how to name and tag spans. By default, they are named the same as the http method. */ @@ -69,11 +72,13 @@ static BytesMessageSender sender() { if (eurekaUri != null && !eurekaUri.isEmpty()) { EurekaEndpointGroup zipkin = EurekaEndpointGroup.builder(eurekaUri).appName("zipkin").build(); + LOGGER.info("Using eureka to discover zipkin: {}", eurekaUri); Runtime.getRuntime().addShutdownHook(new Thread(zipkin::close)); return new WebClientSender(WebClient.of(SessionProtocol.H2C, zipkin, postPath)); } String zipkinUri = System.getProperty("zipkin.baseUrl", "http://127.0.0.1:9411") + postPath; + LOGGER.info("Using zipkin URI: {}", zipkinUri); return new WebClientSender(WebClient.of(zipkinUri)); } @@ -86,7 +91,7 @@ static AsyncZipkinSpanHandler spanHandler(BytesMessageSender sender) { try { sender.close(); // Release any network resources used to send spans } catch (IOException e) { - Logger.getAnonymousLogger().warning("error closing trace sender: " + e.getMessage()); + LOGGER.warn("error closing trace sender: " + e.getMessage()); } })); diff --git a/armeria/src/main/resources/logback.xml b/armeria/src/main/resources/logback.xml index 714a3f4..13dde5f 100644 --- a/armeria/src/main/resources/logback.xml +++ b/armeria/src/main/resources/logback.xml @@ -8,7 +8,7 @@ - + diff --git a/docker-compose-eureka.yml b/docker-compose-eureka.yml index 154c48c..edd1a4e 100644 --- a/docker-compose-eureka.yml +++ b/docker-compose-eureka.yml @@ -1,23 +1,4 @@ -# -# Copyright 2015-2024 The OpenZipkin Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under the License -# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express -# or implied. See the License for the specific language governing permissions and limitations under -# the License. -# - -# This file uses the version 2 docker-compose file format, described here: -# https://docs.docker.com/compose/compose-file/#version-2 -# -# It extends the default configuration from docker-compose.yml to register -# zipkin into a test eureka server. - +# permit depends_on/condition: service_healthy version: '2.4' services: diff --git a/docker-compose.yml b/docker-compose.yml index a429f1a..22c47b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: # Generate traffic by hitting http://localhost:8081 frontend: container_name: frontend - image: openzipkin/brave-example:armeria-test + image: ghcr.io/openzipkin/brave-example:${BRAVE_EXAMPLE:-armeria} entrypoint: start-frontend ports: - 8081:8081 @@ -19,7 +19,7 @@ services: # Serves the /api endpoint the frontend uses backend: container_name: backend - image: openzipkin/brave-example:armeria-test + image: ghcr.io/openzipkin/brave-example:${BRAVE_EXAMPLE:-armeria} entrypoint: start-backend depends_on: zipkin: