DataDog / schema

Datadog JSON Schemas
Apache License 2.0
22 stars 18 forks source link

[semantic-core] Simplify Intake tag definitions #43

Closed ichinaski closed 10 months ago

ichinaski commented 10 months ago

Prefixing intake span tags with 'meta.' and 'metrics.' allows us to reduce the burden on the dd-go validations side, and using this schema repo as the main definition system.

In dd-go, Instead of mapping every single field to its internal counterpart, we can rely on the meta (string) and metrics (number) maps, removing the extra indirection on every conversion.

For example, instead of having this definition in dd-go:

// ToIntakeResolvedHttpSpan takes a SemanticValidationSpan and converts it to an ToIntakeResolvedHttpSpan
func ToIntakeResolvedHttpSpan(s *tracepb.SemanticValidationSpan) *IntakeResolvedHttpSpan {
    res := &IntakeResolvedHttpSpan{
        HttpStatusCode: s.Span.Meta["http.status_code"],
        HttpUrl:        s.Span.Meta["http.url"],
        HttpMethod:     s.Span.Meta["http.method"],
        HttpVersion:    s.Span.Meta["http.version"],
        HttpRoute:      s.Span.Meta["http.route"],
        HttpClientIp:   s.Span.Meta["http.client_ip"],
        HttpUserAgent:  s.Span.Meta["http.useragent"],
    }

    reqCntLen, err := strconv.ParseUint(s.Span.Meta["http.request.content_length"], 10, 64)
    if err == nil {
        res.HttpRequestContentLength = reqCntLen
    }

    resCntLen, err := strconv.ParseUint(s.Span.Meta["http.response.content_length"], 10, 64)
    if err == nil {
        res.HttpResponseContentLength = resCntLen
    }

    reqCntLenUn, err := strconv.ParseUint(s.Span.Meta["http.request.content_length_uncompressed"], 10, 64)
    if err == nil {
        res.HttpRequestContentLengthUncompressed = reqCntLenUn
    }

    resCntLenUn, err := strconv.ParseUint(s.Span.Meta["http.response.content_length_uncompressed"], 10, 64)
    if err == nil {
        res.HttpResponseContentLengthUncompressed = resCntLenUn
    }

    return res
}

we will have:

// ToIntakeResolvedHttpSpan takes a SemanticValidationSpan and converts it to an ToIntakeResolvedHttpSpan
func ToIntakeResolvedHttpSpan(s *tracepb.SemanticValidationSpan) *IntakeResolvedHttpSpan {
    return &IntakeResolvedHttpSpan{
                Meta: s.Span.Meta,
                Metrics: s.Span.Metrics,
        }
}

and new fields addition will be much simpler and possibly just scoped to the schema definition.