Skip to content

Commit

Permalink
Added otel-logback appender
Browse files Browse the repository at this point in the history
  • Loading branch information
ff-sdesai committed Jan 23, 2023
1 parent 3ae88d5 commit ee36dcd
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# distributed-tracing-spring
# spring-cloud-sleuth-otel-slf4j

##Run the Example

cd /home/sdesai/Uplight/code/open-telemetry/spring-cloud-sleuth-otel-slf4j
mvn clean install
sudo docker build -f DockerFile -t spring-cloud-sleuth-otel-slf4j .
sudo docker compose up
Once application is up, hit http://localhost:8181/?testCount=1 from web browser to generate traces and logs


## view the signals
View the `trace signal` in Datadog:
[Datadog APM Traces](https://app.datadoghq.com/apm/traces?query=%40_top_level%3A1%20service%3Aspring-cloud-sleuth-otel-slf4j&cols=core_service%2Ccore_resource_name%2Clog_duration%2Clog_http.method%2Clog_http.status_code&env=none&historicalData=false&messageDisplay=inline&sort=desc&spanType=all&spanViewType=metadata&start=1669976026075&end=1669976926075&paused=false)
6 changes: 0 additions & 6 deletions spring-cloud-sleuth-otel-slf4j/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
3 changes: 2 additions & 1 deletion spring-cloud-sleuth-otel-slf4j/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

##Run the Example

cd distributed-tracing-spring/spring-cloud-sleuth-otel-slf4j
cd /home/sdesai/Uplight/code/open-telemetry/spring-cloud-sleuth-otel-slf4j
mvn clean install
sudo docker build -f DockerFile -t spring-cloud-sleuth-otel-slf4j .
sudo docker compose up
Once application is up, hit http://localhost:8181/?testCount=1 from web browser to generate traces and logs


## view the signals
Expand Down
23 changes: 15 additions & 8 deletions spring-cloud-sleuth-otel-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand Down Expand Up @@ -92,14 +92,21 @@
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>1.22.1</version>
</dependency>


<!-- https://mvnrepository.com/artifact/io.opentelemetry.instrumentation/opentelemetry-logback-appender-1.0 -->
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-logback-appender-1.0</artifactId>
<version>1.19.2-alpha</version>
<scope>runtime</scope>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-logback-appender-1.0</artifactId>
<version>1.19.2-alpha</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-logback-1.0</artifactId>
<version>1.9.2-alpha</version>
<scope>runtime</scope>
</dependency>


Expand All @@ -122,4 +129,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package com.uplight.service;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.annotation.NewSpan;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class TestServiceImpl
implements TestService {

private static final Logger LOGGER = LoggerFactory.getLogger( TestServiceImpl.class );

@Autowired
private RestTemplate restTemplate;

@PostConstruct
public void init() {
System.out.println( "TestServiceImpl initalized.........................................." );
Expand All @@ -17,8 +29,15 @@ public void init() {
@Override
@NewSpan
public void test() {
System.out.println( "In test method" );

Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();
// LOGGER.error( "copyOfContextMap=" + copyOfContextMap );
// Map<String, BaggageEntry> baggageAsMap = Baggage.current().asMap();
// System.out.println( "baggageAsMap=" + baggageAsMap );
// System.out.println( "calling another web application" );
//
//
// ResponseEntity<String> responseEntity = restTemplate.getForEntity( "http://172.22.0.1:8282/", String.class );
// System.out.println( "Response received=" + responseEntity.getBody() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;

@ComponentScan(basePackages = {
"com.uplight.web", "com.uplight.service", "com.uplight.aspect"
Expand All @@ -15,7 +17,10 @@ public static void main( String[] args ) {
SpringApplication.run( ApplicationStarter.class, args );
}


@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
// @Bean
// ScopeDecorator mdcScopeDecorator() {
// return MDCScopeDecorator.newBuilder().clear().add( SingleCorrelationField.newBuilder( countryCodeField() ).flushOnUpdate().build() ).build();
Expand Down
6 changes: 6 additions & 0 deletions spring-cloud-sleuth-otel-slf4j/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<configuration>



<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} serviceName: %X{serviceName} requestId: %X{requestId} trace_id: %X{traceId} span_id: %X{spanId} - %msg%n</pattern>
</encoder>
</appender>

<appender name="OTEL" class="io.opentelemetry.instrumentation.logback.v1_0.OpenTelemetryAppender">
<appender-ref ref="STDOUT" />
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
Expand Down

0 comments on commit ee36dcd

Please sign in to comment.