Skip to content

Commit 4e8387d

Browse files
committed
Start adding a demo for opencensus-contrib-log-correlation-stackdriver (Java).
This commit adds a demo for log correlation using OpenCensus, Logback, and Stackdriver. It is very similar to the demo that was originally contained in census-instrumentation/opencensus-java#1212. The demo can be run with the following command in the `java/log_correlation/stackdriver/logback/` directory: `./gradlew clean installDist && ./build/install/logback/bin/OpenCensusTraceLoggingEnhancerDemo`
1 parent d16eef7 commit 4e8387d

8 files changed

Lines changed: 419 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# OpenCensus/Logback/Stackdriver Log Correlation Demo
2+
3+
An application that demonstrates log correlation in Stackdriver with
4+
`opencensus-contrib-log-correlation-stackdriver`. The application contains SLF4J log statements and
5+
OpenCensus tracing instrumentation. It configures logging with a Logback XML configuration and
6+
exports logs using the
7+
[Stackdriver Logging Logback appender](https://cloud.google.com/logging/docs/setup/java#logback_appender).
8+
It also exports traces using `opencensus-exporter-trace-stackdriver`, so that Stackdriver can show
9+
the log entries associated with each trace.
10+
11+
The application requires a Google Cloud project with Stackdriver Logging enabled. It can be run with
12+
13+
`./gradlew clean installDist && ./build/install/logback/bin/OpenCensusTraceLoggingEnhancerDemo`
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
description = 'OpenCensus/Logback/Stackdriver Log Correlation Demo'
2+
3+
apply plugin: 'java'
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
group = "io.opencensus"
10+
version = "0.16.0-SNAPSHOT"
11+
12+
def opencensusVersion = "0.15.0"
13+
14+
tasks.withType(JavaCompile) {
15+
sourceCompatibility = '1.7'
16+
targetCompatibility = '1.7'
17+
}
18+
19+
dependencies {
20+
compile "io.opencensus:opencensus-api:${opencensusVersion}",
21+
"io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusVersion}",
22+
"org.slf4j:slf4j-api:1.7.25"
23+
24+
runtime "io.opencensus:opencensus-contrib-log-correlation-stackdriver:${opencensusVersion}",
25+
"io.opencensus:opencensus-impl-lite:${opencensusVersion}",
26+
"com.google.cloud:google-cloud-logging-logback:0.48.0-alpha"
27+
}
28+
29+
apply plugin: 'application'
30+
31+
startScripts.enabled = false
32+
33+
task openCensusLogCorrelationStackdriverDemo(type: CreateStartScripts) {
34+
mainClassName =
35+
'io.opencensus.demo.logcorrelation.stackdriver.logback.OpenCensusTraceLoggingEnhancerDemo'
36+
applicationName = 'OpenCensusTraceLoggingEnhancerDemo'
37+
outputDir = new File(project.buildDir, 'tmp')
38+
classpath = jar.outputs.files + project.configurations.runtime
39+
}
40+
41+
applicationDistribution.into('bin') {
42+
from(openCensusLogCorrelationStackdriverDemo)
43+
fileMode = 0755
44+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

java/log_correlation/stackdriver/logback/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/log_correlation/stackdriver/logback/gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)