11use axum:: { body:: Bytes , extract:: State , http:: StatusCode , Json } ;
2- use datadog_protos:: traces:: AgentPayload ;
2+ use datadog_protos:: traces:: { AgentPayload , StatsPayload } ;
33use protobuf:: Message as _;
4- use stele:: Span ;
5- use tracing:: { debug , error } ;
4+ use stele:: { ClientStatisticsAggregator , Span } ;
5+ use tracing:: { error , info } ;
66
77use super :: TracesState ;
88
9- pub async fn handle_traces_dump ( State ( state) : State < TracesState > ) -> Json < Vec < Span > > {
10- Json ( state. dump ( ) )
9+ pub async fn handle_trace_spans_dump ( State ( state) : State < TracesState > ) -> Json < Vec < Span > > {
10+ info ! ( "Got request to dump trace spans." ) ;
11+ Json ( state. dump_spans ( ) )
12+ }
13+
14+ pub async fn handle_trace_stats_dump ( State ( state) : State < TracesState > ) -> Json < ClientStatisticsAggregator > {
15+ info ! ( "Got request to dump trace stats." ) ;
16+ Json ( state. dump_stats ( ) )
1117}
1218
1319pub async fn handle_v02_traces ( State ( state) : State < TracesState > , body : Bytes ) -> StatusCode {
14- debug ! ( "Received v0.2 traces payload." ) ;
20+ info ! ( "Received v0.2 traces payload." ) ;
1521
1622 let payload = match AgentPayload :: parse_from_bytes ( & body[ ..] ) {
1723 Ok ( payload) => payload,
@@ -23,7 +29,7 @@ pub async fn handle_v02_traces(State(state): State<TracesState>, body: Bytes) ->
2329
2430 match state. merge_agent_payload ( payload) {
2531 Ok ( ( ) ) => {
26- debug ! ( "Processed trace payload." ) ;
32+ info ! ( "Processed trace payload." ) ;
2733 StatusCode :: ACCEPTED
2834 }
2935 Err ( e) => {
@@ -32,3 +38,26 @@ pub async fn handle_v02_traces(State(state): State<TracesState>, body: Bytes) ->
3238 }
3339 }
3440}
41+
42+ pub async fn handle_v02_stats ( State ( state) : State < TracesState > , body : Bytes ) -> StatusCode {
43+ info ! ( "Received v0.2 stats payload." ) ;
44+
45+ let payload = match rmp_serde:: from_slice :: < StatsPayload > ( & body[ ..] ) {
46+ Ok ( payload) => payload,
47+ Err ( e) => {
48+ error ! ( error = ?e, "Failed to parse stats payload." ) ;
49+ return StatusCode :: BAD_REQUEST ;
50+ }
51+ } ;
52+
53+ match state. merge_stats_payload ( payload) {
54+ Ok ( ( ) ) => {
55+ info ! ( "Processed stats payload." ) ;
56+ StatusCode :: ACCEPTED
57+ }
58+ Err ( e) => {
59+ error ! ( error = %e, "Failed to merge stats payload." ) ;
60+ StatusCode :: BAD_REQUEST
61+ }
62+ }
63+ }
0 commit comments