[Java Agent] - apm-server replies with http400 - Problem validating JSON document

Hello,

I'm trying to send a custom transaction to apm through the Java Agent.
However I'm experiencing problems and for every transaction I close, the server replies http400 with this error on console:

ERROR [request] beater/handlers.go:384 error handling request {"request_id": "3be3e112-466c-463a-b011-61284ed52d31", "error": "Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"transaction#\"\n I[#/transactions/0/context/request] S[#/properties/transactions/items/properties/context/properties/request/required] missing properties: \"method\""}

this is how I'm instrumenting and starting the Agent:

private static ElasticApm elasticApm;

...

Transaction apmTransaction = elasticApm.startTransaction();
apmTransaction.setName("testTransaction");
apmTransaction.setType("test");
apmTransaction.setUser("auto", "auto@example.com", "auto");

//Business Code

apmTransaction.close();

while elasticapm.properties looks like this:

service_name=kpicalculator
service_version=1.0.0
application_packages=a.b.c
environment=sand
server_url=http://xxx.xxx.xxx.xxx:8200

Now I'm using apm-server v6.2.4 with docker, however the same issue happens with all the server versions (I've tried from 6.0.0 to 6.2.4)

Am I missing something with the configuration?

Thanks a lot for your help!

Best
Marco

This is fixed in master, which contains a complete overhaul of the JSON serialization.

The problem is that the Java agent pre-allocates the Transaction.context.request object. But if this object is not null, the JSON schema requires the method to be set. In the current version on master, Transaction.context.request is only serialized if it actually hasContent.

Are you ok with building the Java agent from source?

FYI: when you enable TRACE logs for co.elastic.apm, you can see the actual JSON sent to the APM-server.

Thanks Felix for your help.
I've tried to build from source but I'm experiencing problems due to Java 9.
I'll have time to deal with it during the next days.

Thanks again!
Marco

I'd suggest installing Java 10 as it will soon be required to build the agent. The agent itself is still Java 7 compatible btw.

Installed Java 10 & built master.
Now works perfectly.
Thanks a lot!

That's great news :slight_smile:
Just tell me if there is anything else I can help you with.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.