use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.
the class ElasticApmTracer method startSpan.
@Nonnull
@Override
public Span startSpan() {
Transaction transaction = currentTransaction();
final Span span;
// even when setting active=false mid-transaction
if (isNoop(transaction)) {
span = noopSpan;
} else {
span = createRealSpan(transaction);
}
currentSpan.set(span);
return span;
}
use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.
the class AbstractReporterBenchmark method fillTransaction.
private void fillTransaction(Transaction t) {
t.setName("GET /api/types");
t.setType("request");
t.withResult("success");
Context context = t.getContext();
Request request = context.getRequest();
request.withHttpVersion("1.1");
request.withMethod("POST");
request.withRawBody("Hello World");
request.getUrl().withProtocol("https").appendToFull("https://www.example.com/p/a/t/h?query=string#hash").withHostname("www.example.com").withPort("8080").withPathname("/p/a/t/h").withSearch("?query=string");
request.getSocket().withEncrypted(true).withRemoteAddress("12.53.12.1");
request.addHeader("user-agent", "Mozilla Chrome Edge");
request.addHeader("content-type", "text/html");
request.addHeader("cookie", "c1=v1; c2=v2");
request.addHeader("some-other-header", "foo");
request.addHeader("array", "foo, bar, baz");
request.getCookies().put("c1", "v1");
request.getCookies().put("c2", "v2");
context.getResponse().withStatusCode(200).withFinished(true).withHeadersSent(true).addHeader("content-type", "application/json");
context.getUser().withId("99").withUsername("foo").withEmail("foo@example.com");
context.getTags().put("organization_uuid", "9f0e9d64-c185-4d21-a6f4-4673ed561ec8");
context.getCustom().put("my_key", 1);
context.getCustom().put("some_other_value", "foo bar");
context.getCustom().put("and_objects", STRINGS);
Span span = new Span().withName("SELECT FROM product_types").withType("db.postgresql.query");
span.getContext().getDb().withInstance("customers").withStatement("SELECT * FROM product_types WHERE user_id=?").withType("sql").withUser("readonly_user");
t.getSpans().add(span);
t.getSpans().add(new Span().withName("GET /api/types").withType("request"));
t.getSpans().add(new Span().withName("GET /api/types").withType("request"));
t.getSpans().add(new Span().withName("GET /api/types").withType("request"));
}
use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.
the class ApmJdbcEventListener method onBeforeAnyExecute.
@Override
public void onBeforeAnyExecute(StatementInformation statementInformation) {
if (isNoop(elasticApmTracer.currentTransaction())) {
return;
}
Span span = elasticApmTracer.startSpan();
span.setName(getMethod(statementInformation.getStatementQuery()));
try {
String dbVendor = getDbVendor(statementInformation.getConnectionInformation().getConnection().getMetaData().getURL());
span.setType("db." + dbVendor + ".sql");
span.getContext().getDb().withUser(statementInformation.getConnectionInformation().getConnection().getMetaData().getUserName()).withStatement(statementInformation.getStatementQuery()).withType("sql");
} catch (SQLException e) {
logger.warn("Ignored exception", e);
}
}
use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.
the class ApmJdbcEventListenerTest method testJdbcSpan.
@Test
void testJdbcSpan() throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM ELASTIC_APM WHERE FOO=$1");
preparedStatement.setInt(1, 1);
ResultSet resultSet = preparedStatement.executeQuery();
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.getInt("foo")).isEqualTo(1);
assertThat(resultSet.getString("BAR")).isEqualTo("APM");
assertThat(transaction.getSpans()).hasSize(1);
Span jdbcSpan = transaction.getSpans().get(0);
assertThat(jdbcSpan.getName()).isEqualTo("SELECT");
assertThat(jdbcSpan.getType()).isEqualToIgnoringCase("db.h2.sql");
Db db = jdbcSpan.getContext().getDb();
assertThat(db.getStatement()).isEqualTo("SELECT * FROM ELASTIC_APM WHERE FOO=$1");
assertThat(db.getUser()).isEqualToIgnoringCase("user");
assertThat(db.getType()).isEqualToIgnoringCase("sql");
}
use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.
the class ElasticApmTracer method createRealSpan.
private Span createRealSpan(Transaction transaction) {
Span span;
span = spanPool.createInstance();
final boolean dropped;
if (isTransactionSpanLimitReached(transaction)) {
dropped = true;
transaction.getSpanCount().getDropped().increment();
} else {
dropped = false;
}
span.start(this, transaction, currentSpan(), System.nanoTime(), dropped);
return span;
}
Aggregations