Search in sources :

Example 1 with Context

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

Example 2 with Context

use of co.elastic.apm.impl.context.Context in project apm-agent-java by elastic.

the class ApmFilter method fillTransaction.

private void fillTransaction(Transaction transaction, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    Context context = transaction.getContext();
    fillRequest(transaction.getContext().getRequest(), httpServletRequest);
    fillResponse(context.getResponse(), httpServletResponse);
    fillUser(context.getUser(), httpServletRequest);
    // the HTTP method is not a good transaction name, but better than none...
    if (transaction.getName().length() == 0) {
        transaction.withName(httpServletRequest.getMethod());
    }
    transaction.withResult(getResult(httpServletResponse.getStatus()));
    transaction.withType("request");
}
Also used : Context(co.elastic.apm.impl.context.Context)

Example 3 with Context

use of co.elastic.apm.impl.context.Context 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

Context (co.elastic.apm.impl.context.Context)3 Request (co.elastic.apm.impl.context.Request)2 Span (co.elastic.apm.impl.transaction.Span)2