Search in sources :

Example 6 with Span

use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.

the class TransactionPayloadJsonSchemaTest method createTransactionWithRequiredValues.

private Transaction createTransactionWithRequiredValues() {
    Transaction t = new Transaction();
    t.start(mock(ElasticApmTracer.class), 0, ConstantSampler.of(true));
    t.setType("type");
    t.getContext().getRequest().withMethod("GET");
    Span s = new Span();
    s.start(mock(ElasticApmTracer.class), t, null, 0, false).withType("type").withName("name");
    t.addSpan(s);
    return t;
}
Also used : Transaction(co.elastic.apm.impl.transaction.Transaction) ElasticApmTracer(co.elastic.apm.impl.ElasticApmTracer) Span(co.elastic.apm.impl.transaction.Span)

Example 7 with Span

use of co.elastic.apm.impl.transaction.Span in project apm-agent-java by elastic.

the class TransactionUtils method fillTransaction.

public static 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"));
}
Also used : Context(co.elastic.apm.impl.context.Context) Request(co.elastic.apm.impl.context.Request) Span(co.elastic.apm.impl.transaction.Span)

Aggregations

Span (co.elastic.apm.impl.transaction.Span)7 Context (co.elastic.apm.impl.context.Context)2 Request (co.elastic.apm.impl.context.Request)2 Transaction (co.elastic.apm.impl.transaction.Transaction)2 ElasticApmTracer (co.elastic.apm.impl.ElasticApmTracer)1 Db (co.elastic.apm.impl.transaction.Db)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.jupiter.api.Test)1