-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datadog trace flushing/export (#1266)
This PR adds flushing+export of traces and trace-related statistics to the `datadogexporter`, as well as some very minor changes to the translation of internal traces into Datadog format. It represents the second of two PRs for the work contained in #1203. It builds on top of current master branch, and follows up to the work [done here](#1208). The final PR explicitly enabling The Datadog exporter will follow, and will allow users to export traces to Datadog's API Intake. This PR Split was requested by @tigrannajaryan and hopefully should make code review a bit less cumbersome. However if there are any questions or changes to the PR format needed, please let me know. **Testing:** There are unit tests for the different methods and helper methods within the export code. **Documentation:** Appropriate usage, including best practices for which processors to also enable, has been documented in the README, `testdata/config.yaml` and `example/config.yaml` samples. **Notes**: This PR includes a trace exporter for non-windows environments only (metrics are fine in windows, just traces that are the issue), due to reasons explained in this pr #1274 . tl;dr is our trace export code for windows env would rely on CGO for now, which is not permitted in the collector
- Loading branch information
1 parent
3113db5
commit 6a410f0
Showing
12 changed files
with
856 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build !windows | ||
|
||
package datadogexporter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/trace/pb" | ||
"github.com/DataDog/datadog-agent/pkg/trace/stats" | ||
) | ||
|
||
const ( | ||
statsBucketDuration int64 = int64(10 * time.Second) | ||
) | ||
|
||
// ComputeAPMStats calculates the stats that should be submitted to APM about a given trace | ||
func ComputeAPMStats(tracePayload *pb.TracePayload, pushTime int64) *stats.Payload { | ||
|
||
statsRawBuckets := make(map[int64]*stats.RawBucket) | ||
|
||
bucketTS := pushTime - statsBucketDuration | ||
|
||
for _, trace := range tracePayload.Traces { | ||
spans := GetAnalyzedSpans(trace.Spans) | ||
sublayers := stats.ComputeSublayers(trace.Spans) | ||
for _, span := range spans { | ||
|
||
// TODO: While this is hardcoded to assume a single 10s buckets for now, | ||
// An improvement would be to support keeping multiple 10s buckets in buffer | ||
// ala, [0-10][10-20][20-30], only flushing the oldest bucket, to allow traces that | ||
// get reported late to still be counted in the correct bucket. This is how the | ||
// datadog- agent handles stats buckets, but would be non trivial to add. | ||
|
||
var statsRawBucket *stats.RawBucket | ||
if existingBucket, ok := statsRawBuckets[bucketTS]; ok { | ||
statsRawBucket = existingBucket | ||
} else { | ||
statsRawBucket = stats.NewRawBucket(bucketTS, statsBucketDuration) | ||
statsRawBuckets[bucketTS] = statsRawBucket | ||
} | ||
|
||
// Use weight 1, as sampling in opentelemetry would occur upstream in a processor. | ||
// Generally we want to ship 100% of traces to the backend where more accurate tail based sampling can be performed. | ||
// TopLevel is always "true" since we only compute stats for top-level spans. | ||
weightedSpan := &stats.WeightedSpan{ | ||
Span: span, | ||
Weight: 1, | ||
TopLevel: true, | ||
} | ||
statsRawBucket.HandleSpan(weightedSpan, tracePayload.Env, []string{}, sublayers) | ||
} | ||
} | ||
|
||
// Export statsRawBuckets to statsBuckets | ||
statsBuckets := make([]stats.Bucket, 0) | ||
for _, statsRawBucket := range statsRawBuckets { | ||
statsBuckets = append(statsBuckets, statsRawBucket.Export()) | ||
} | ||
|
||
return &stats.Payload{ | ||
HostName: tracePayload.HostName, | ||
Env: tracePayload.Env, | ||
Stats: statsBuckets, | ||
} | ||
} |
Oops, something went wrong.