~shabbyrobe/dogdump

e8bb9c30562f31c540a5008f816e43e37f167cce — Blake Williams 5 months ago f9e041a
Document discovery
2 files changed, 36 insertions(+), 1 deletions(-)

M dogproto/traceproto.go
M dogtrace/handler.go
M dogproto/traceproto.go => dogproto/traceproto.go +22 -0
@@ 30,3 30,25 @@ type Span struct {
	ParentID      uint64             `msg:"parent_id" json:"parentId"`
	Error         int32              `msg:"error" json:"error"`
}

// JSON response to 'GET /v0.7/config', sponged out of DDAgentFeaturesDiscovery.java
// in https://github.com/DataDog/dd-trace-java/
type ConfigResponse struct {
	Version string `json:"version"`
	Config  Config `json:"config"`

	// Must not be nil.
	// These are just paths, not hosts:
	// - https://github.com/DataDog/dd-trace-java/blob/0f986a71765d0bad85ed4e5c3bc6ef44b8cb78fe/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java#L39
	// - https://github.com/DataDog/dd-trace-java/blob/0f986a71765d0bad85ed4e5c3bc6ef44b8cb78fe/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java#L59C46-L59C65
	// In the java version, whether or not metrics or tracing are enabled is contingent on
	// whether those paths are found in here.
	Endpoints []string `json:"endpoints"`

	ClientDropP0s bool `json:"client_drop_p0s,omitempty"`
}

type Config struct {
	// A port <= 0 should instruct Java to skip this and use an internal default
	StatsDPort int `json:"statsd_port"`
}

M dogtrace/handler.go => dogtrace/handler.go +14 -1
@@ 1,7 1,9 @@
package dogtrace

import (
	"bytes"
	"context"
	"io"
	"net/http"
	"slices"



@@ 25,11 27,22 @@ func HTTPHandler(
		}
	}

	// FIXME: we see this error a lot:
	// '{"_type":"error","msg":"msgp: attempted to decode type \"int\" with method for \"array\""}'
	// It's happening because we're handling /v0.7/config as a trace, when really it should return
	// a dogproto.ConfigResponse.

	return func(rs http.ResponseWriter, rq *http.Request) {
		defer rq.Body.Close()

		var spanLists dogproto.SpanLists
		if err := msgp.Decode(rq.Body, &spanLists); err != nil {

		body, err := io.ReadAll(rq.Body)
		if err != nil {
			panic(err)
		}

		if err := msgp.Decode(bytes.NewReader(body), &spanLists); err != nil {
			if handleErr := errHandler(err); handleErr != nil {
				panic(handleErr)
			}