domstolene / da-otel-agent

This project delivers an OpenTelemetry Java Agent extension with a dynamically configurable sampler, along with the optional REST service for configuring it.
Apache License 2.0
12 stars 1 forks source link

Return a better error message when JSON parsing fails #32

Closed turesheim closed 1 year ago

turesheim commented 1 year ago

Calling for example:

❯ curl -X PUT 'http://localhost:8080/agent-configuration/app-service' \
-H 'Content-Type: application/json' \
-d '{"serviceName":"app-service","sampler":"parentbased_alwaysoff","readOnly":false}'

Returns:

{"timestamp":"2023-10-06T08:05:03.130+00:00","status":400,"error":"Bad Request","path":"/agent-configuration/app-service"}%

The problem here is that parentbased_alwaysoff is not a legal sampler. The service actually logs this, but the message is not relayed to the client, which should include the actual JSON Parse error: JSON parse error: Cannot deserialize value of type "no.domstol.otel.agent.service.AgentConfiguration$SamplerType" from String "parentbased_alwaysoff": not one of the values accepted for Enum class: [parentbased_traceidratio, parentbased_always_off, parentbased_always_on, traceidratio, always_on, always_off]]