Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/env bash

java -version

cd opbeans

./mvnw clean package

export ELASTIC_APM_SERVICE_NAME=opbeans-debug
export ELASTIC_APM_SERVER_URL=http://localhost:8200
export ELASTIC_APM_APPLICATION_PACKAGES=co.elastic.apm.opbeans
export ELASTIC_APM_ENABLE_LOG_CORRELATION=true
export ELASTIC_APM_ENABLE_EXPERIMENTAL_INSTRUMENTATIONS=true
export ELASTIC_APM_ENVIRONMENT=debug

# get released agent
dl_agent_version=1.31.0
curl -s -o elastic-apm-agent.jar "https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${dl_agent_version}/elastic-apm-agent-${dl_agent_version}.jar"

# get latest snapshot
curl -s -o elastic-apm-agent.jar --location 'https://apm-ci.elastic.co/job/apm-agent-java/job/apm-agent-java-mbp/job/main/lastSuccessfulBuild/artifact/src/github.com/elastic/apm-agent-java/elastic-apm-agent/target/elastic-apm-agent-1.31.1-SNAPSHOT.jar'

agent_jar=elastic-apm-agent.jar
app_jar=target/opbeans-0.0.1-SNAPSHOT.jar
agent_opts=-javaagent:${agent_jar}

#debug_opts='-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y'

java \
${debug_opts:-} \
${agent_opts:-} \
-jar ${app_jar}

cd -
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,51 @@
*/
package co.elastic.apm.opbeans;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OpbeansApplication {

public static void main(String[] args) {

Thread t = new Thread(){
@Override
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
// ignored
}

Tracer tracer = GlobalOpenTelemetry.get().getTracer("co.elastic.apm:opbeans");

Span span = tracer.spanBuilder("fake HTTP transaction")
.setSpanKind(SpanKind.SERVER)
.startSpan()
.setAttribute("http.url", "http://localhost:8080/")
.setAttribute("http.method", "GET")
.setAttribute("http.status_code", 200);

try {
sleep(100);
} catch (InterruptedException e) {
// ignored
}

span.setStatus(StatusCode.OK)
.end();

}
};

t.start();

SpringApplication.run(OpbeansApplication.class, args);
}
}