Skip to content

Commit

Permalink
ready maybe
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Jan 14, 2024
1 parent 16b3789 commit fab451a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions armeria/src/main/java/brave/example/TracingFactory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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. */
Expand Down Expand Up @@ -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));
}

Expand All @@ -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());
}
}));

Expand Down
2 changes: 1 addition & 1 deletion armeria/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</encoder>
</appender>

<logger name="com.linecorp.armeria" level="debug"/>
<logger name="com.linecorp.armeria" level="info"/>

<root level="info">
<appender-ref ref="STDOUT" />
Expand Down
21 changes: 1 addition & 20 deletions docker-compose-eureka.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit fab451a

Please sign in to comment.