Skip to content

Commit

Permalink
add more properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Jul 20, 2023
1 parent defc166 commit 80ddb5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
35 changes: 31 additions & 4 deletions go/adapter/datadog/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (d *DatadogAdapter) HandleTraceEvent(te observe.TraceEvent) {

if meta, ok := te.AdapterMeta.(DatadogMetadata); ok {
topSpan := allSpans[0]
if topSpan.Meta == nil {
topSpan.Meta = make(map[string]string)
}
if meta.ResourceName != nil {
topSpan.Resource = *meta.ResourceName
}
Expand All @@ -88,6 +91,24 @@ func (d *DatadogAdapter) HandleTraceEvent(te observe.TraceEvent) {
if meta.HttpStatusCode != nil {
topSpan.Meta["http.status_code"] = fmt.Sprintf("%d", *meta.HttpStatusCode)
}
if meta.HttpClientIp != nil {
topSpan.Meta["http.client_ip"] = *meta.HttpClientIp
}
if meta.HttpRequestContentLength != nil {
topSpan.Meta["http.request.content_length"] = fmt.Sprintf("%d", *meta.HttpRequestContentLength)
}
if meta.HttpRequestContentLengthUncompressed != nil {
topSpan.Meta["http.request.content_length_uncompressed"] = fmt.Sprintf("%d", *meta.HttpRequestContentLengthUncompressed)
}
if meta.HttpResponseContentLength != nil {
topSpan.Meta["http.response.content_length"] = fmt.Sprintf("%d", *meta.HttpResponseContentLength)
}
if meta.HttpResponseContentLengthUncompressed != nil {
topSpan.Meta["http.response.content_length_uncompressed"] = fmt.Sprintf("%d", *meta.HttpResponseContentLengthUncompressed)
}
if meta.SpanKind != nil {
topSpan.Meta["span.kind"] = meta.SpanKind.String()
}
}

tt := d.Config.TraceType.String()
Expand Down Expand Up @@ -139,10 +160,16 @@ func (d *DatadogAdapter) makeCallSpans(event observe.CallEvent, parentId *uint64
}

type DatadogMetadata struct {
HttpUrl *string
HttpMethod *string
HttpStatusCode *int
ResourceName *string
HttpUrl *string
HttpMethod *string
HttpStatusCode *int
ResourceName *string
HttpClientIp *string
HttpRequestContentLength *int
HttpRequestContentLengthUncompressed *int
HttpResponseContentLength *int
HttpResponseContentLengthUncompressed *int
SpanKind *DatadogSpanKind
}

type DatadogSpanKind int
Expand Down
1 change: 0 additions & 1 deletion go/adapter/datadog_formatter/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func NewSpan(service string, traceId uint64, parentId *uint64, name string, star
Duration: uint64(end.Sub(start).Nanoseconds()),
Service: service,
Resource: name,
Meta: make(map[string]string),
}
return &span
}
Expand Down
4 changes: 4 additions & 0 deletions go/bin/datadog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ func main() {
resourceName := "my-resource"
httpUrl := "https://example.com/my-endpoint"
httpStatusCode := 200
spanKind := datadog.Server
clientIp := "66.210.227.34"

meta := datadog.DatadogMetadata{
ResourceName: &resourceName,
HttpUrl: &httpUrl,
HttpStatusCode: &httpStatusCode,
SpanKind: &spanKind,
HttpClientIp: &clientIp,
}
traceCtx.Metadata(meta)

Expand Down

0 comments on commit 80ddb5b

Please sign in to comment.