diff --git a/docs/docs/getting-started/configure-trace-ingestion.mdx b/docs/docs/getting-started/configure-trace-ingestion.mdx index 29a4c900c2..f29f51f61a 100644 --- a/docs/docs/getting-started/configure-trace-ingestion.mdx +++ b/docs/docs/getting-started/configure-trace-ingestion.mdx @@ -146,6 +146,10 @@ export OTEL_EXPORTER_OTLP_ENDPOINT="http://:4318" node -r ./tracing.js app.js ``` +:::note View a code sample +[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/nodejs) +::: + @@ -176,6 +180,10 @@ export OTEL_EXPORTER_OTLP_ENDPOINT="http://:4318" opentelemetry-instrument python app.py ``` +:::note View a code sample +[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/python) +::: + @@ -314,6 +322,34 @@ export OTEL_EXPORTER_OTLP_ENDPOINT="http://:4318" go run . ``` +:::note View a code sample +[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/go) +::: + + + + +1. Download OpenTelemetry Java Agent + +```bash title="Terminal" +curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar +``` + +2. Run with Jar and Include the OpenTelemetry Java Agent + +```bash +export OTEL_SERVICE_NAME=my-service-name +export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf +export OTEL_EXPORTER_OTLP_ENDPOINT="http://:4318" +# export OTEL_EXPORTER_OTLP_HEADERS="x-token=" + +java -javaagent:opentelemetry-javaagent.jar -jar /path/to/app.jar +``` + +:::note View a code sample +[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/java) +::: + diff --git a/examples/getting-started/go/readme.md b/examples/getting-started/go/readme.md index 91798f18a2..4050dbde6b 100644 --- a/examples/getting-started/go/readme.md +++ b/examples/getting-started/go/readme.md @@ -1,12 +1,25 @@ -# Dependencies - -```bash -go get \ - github.com/gorilla/mux v1.8.1 \ - go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.56.0 \ - go.opentelemetry.io/otel v1.31.0 \ - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 \ - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 \ - go.opentelemetry.io/otel/sdk v1.31.0 \ - go.opentelemetry.io/otel/trace v1.31.0 -``` +# Step-by-step + +1. Install Dependencies + + ```bash + go get \ + github.com/gorilla/mux v1.8.1 \ + go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.56.0 \ + go.opentelemetry.io/otel v1.31.0 \ + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 \ + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 \ + go.opentelemetry.io/otel/sdk v1.31.0 \ + go.opentelemetry.io/otel/trace v1.31.0 + ``` + +2. Start the App + + ```bash + export OTEL_SERVICE_NAME=my-service-name + export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf + export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" + export OTEL_EXPORTER_OTLP_HEADERS="x-tracetest-token=bla" + + go run . + ``` diff --git a/examples/getting-started/java/hello-world-api/dependency-reduced-pom.xml b/examples/getting-started/java/hello-world-api/dependency-reduced-pom.xml new file mode 100644 index 0000000000..287bb69ed7 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/dependency-reduced-pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + com.example + hello-world-api + 1.0-SNAPSHOT + + + + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + com.example.HelloWorldApi + + + + + + + + + + + junit + junit + 3.8.1 + test + + + diff --git a/examples/getting-started/java/hello-world-api/opentelemetry-javaagent.jar b/examples/getting-started/java/hello-world-api/opentelemetry-javaagent.jar new file mode 100644 index 0000000000..e5bcd85eef Binary files /dev/null and b/examples/getting-started/java/hello-world-api/opentelemetry-javaagent.jar differ diff --git a/examples/getting-started/java/hello-world-api/pom.xml b/examples/getting-started/java/hello-world-api/pom.xml new file mode 100644 index 0000000000..f57140ee47 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + com.example + hello-world-api + 1.0-SNAPSHOT + + + + junit + junit + 3.8.1 + test + + + + com.sparkjava + spark-core + 2.9.4 + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + com.example.HelloWorldApi + + + + + + + + + diff --git a/examples/getting-started/java/hello-world-api/src/main/java/com/example/HelloWorldApi.java b/examples/getting-started/java/hello-world-api/src/main/java/com/example/HelloWorldApi.java new file mode 100644 index 0000000000..f194e169a9 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/src/main/java/com/example/HelloWorldApi.java @@ -0,0 +1,13 @@ +package com.example; + +import static spark.Spark.*; + +public class HelloWorldApi { + public static void main(String[] args) { + // Start a basic HTTP server on port 4567 + port(4567); + + // Define a simple route that returns "Hello, World!" + get("/hello", (req, res) -> "Hello, World!"); + } +} diff --git a/examples/getting-started/java/hello-world-api/src/test/java/com/example/AppTest.java b/examples/getting-started/java/hello-world-api/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000000..474710ca19 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/src/test/java/com/example/AppTest.java @@ -0,0 +1,38 @@ +package com.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/examples/getting-started/java/hello-world-api/target/classes/com/example/HelloWorldApi.class b/examples/getting-started/java/hello-world-api/target/classes/com/example/HelloWorldApi.class new file mode 100644 index 0000000000..9d1f41bfcb Binary files /dev/null and b/examples/getting-started/java/hello-world-api/target/classes/com/example/HelloWorldApi.class differ diff --git a/examples/getting-started/java/hello-world-api/target/hello-world-api-1.0-SNAPSHOT.jar b/examples/getting-started/java/hello-world-api/target/hello-world-api-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000..2eaf44b95b Binary files /dev/null and b/examples/getting-started/java/hello-world-api/target/hello-world-api-1.0-SNAPSHOT.jar differ diff --git a/examples/getting-started/java/hello-world-api/target/maven-archiver/pom.properties b/examples/getting-started/java/hello-world-api/target/maven-archiver/pom.properties new file mode 100644 index 0000000000..cd5ca5c2b9 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=hello-world-api +groupId=com.example +version=1.0-SNAPSHOT diff --git a/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000..2d7f7a1a23 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +com/example/HelloWorldApi.class diff --git a/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000..08094c669a --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/Users/adnanrahic/Code/kubeshop/tracetest/examples/getting-started/java/hello-world-api/src/main/java/com/example/HelloWorldApi.java diff --git a/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000..5f400a6920 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/example/AppTest.class diff --git a/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000..04560d639c --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/Users/adnanrahic/Code/kubeshop/tracetest/examples/getting-started/java/hello-world-api/src/test/java/com/example/AppTest.java diff --git a/examples/getting-started/java/hello-world-api/target/original-hello-world-api-1.0-SNAPSHOT.jar b/examples/getting-started/java/hello-world-api/target/original-hello-world-api-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000..2131941d74 Binary files /dev/null and b/examples/getting-started/java/hello-world-api/target/original-hello-world-api-1.0-SNAPSHOT.jar differ diff --git a/examples/getting-started/java/hello-world-api/target/surefire-reports/TEST-com.example.AppTest.xml b/examples/getting-started/java/hello-world-api/target/surefire-reports/TEST-com.example.AppTest.xml new file mode 100644 index 0000000000..7bec9e5589 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/surefire-reports/TEST-com.example.AppTest.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/getting-started/java/hello-world-api/target/surefire-reports/com.example.AppTest.txt b/examples/getting-started/java/hello-world-api/target/surefire-reports/com.example.AppTest.txt new file mode 100644 index 0000000000..9fb6b6bc62 --- /dev/null +++ b/examples/getting-started/java/hello-world-api/target/surefire-reports/com.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.020 s -- in com.example.AppTest diff --git a/examples/getting-started/java/hello-world-api/target/test-classes/com/example/AppTest.class b/examples/getting-started/java/hello-world-api/target/test-classes/com/example/AppTest.class new file mode 100644 index 0000000000..9d5bd6ad89 Binary files /dev/null and b/examples/getting-started/java/hello-world-api/target/test-classes/com/example/AppTest.class differ diff --git a/examples/getting-started/java/readme.md b/examples/getting-started/java/readme.md new file mode 100644 index 0000000000..cb4b538ddf --- /dev/null +++ b/examples/getting-started/java/readme.md @@ -0,0 +1,61 @@ +# Step-by-step + +1. Create Maven Project + + ```bash + mvn archetype:generate -DgroupId=com.example -DartifactId=hello-world-api -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false + ``` + +2. Enter `hello-world-api` Directory + + ```bash + cd ./hello-world-api + ``` + +3. Add Spark Dependency in `pom.xml` + + ```xml + + com.sparkjava + spark-core + 2.9.4 + + ``` + +4. Install Maven Dependencies and Start App + + ```bash + mvn clean install + mvn exec:java -Dexec.mainClass="com.example.HelloWorldApi" + ``` + +5. Run with Jar + + ```bash + mvn clean package + ``` + + ```bash + java -jar target/hello-world-api-1.0-SNAPSHOT.jar + ``` + +6. Download OpenTelemetry Java Agent + + ```bash + curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar + ``` + +7. Run with Jar and Include the OpenTelemetry Java Agent + + ```bash + mvn clean package + ``` + + ```bash + export OTEL_SERVICE_NAME=my-service-name + export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf + export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" + export OTEL_EXPORTER_OTLP_HEADERS="x-token=bla" + + java -javaagent:opentelemetry-javaagent.jar -jar target/hello-world-api-1.0-SNAPSHOT.jar + ```