-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: add datadog trace translation helpers and tests #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0f8a489
feat: add datadog trace translation helpers and tests
ericmustin de34c9e
tests: add more unit tests for code cov
ericmustin d350872
tests: additional unit tests for codecov
ericmustin a39c4e5
Merge branch 'master' into trace_translation
ericmustin b355df1
dont modify go.sum since ddog exporter is not enabled
ericmustin 7179cb1
test trace state and nil cases better
ericmustin e81a052
Merge branch 'master' into trace_translation
ericmustin 4210fbf
Merge branch 'master' into trace_translation
ericmustin a9141ab
exporter/datadog: update version and implement feedback
ericmustin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
| // 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. | ||
|
|
||
| package datadogexporter | ||
|
|
||
| import ( | ||
| "github.com/DataDog/datadog-agent/pkg/trace/event" | ||
| "github.com/DataDog/datadog-agent/pkg/trace/obfuscate" | ||
| "github.com/DataDog/datadog-agent/pkg/trace/pb" | ||
| "github.com/DataDog/datadog-agent/pkg/trace/sampler" | ||
| "github.com/DataDog/datadog-agent/pkg/trace/stats" | ||
| "github.com/DataDog/datadog-agent/pkg/trace/traceutil" | ||
| ) | ||
|
|
||
| // ObfuscatePayload applies obfuscator rules to the trace payloads | ||
| func ObfuscatePayload(obfuscator *obfuscate.Obfuscator, tracePayloads []*pb.TracePayload) { | ||
| for _, tracePayload := range tracePayloads { | ||
|
|
||
| // Obfuscate the traces in the payload | ||
| for _, trace := range tracePayload.Traces { | ||
| for _, span := range trace.Spans { | ||
| obfuscator.Obfuscate(span) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // GetAnalyzedSpans finds all the analyzed spans in a trace, including top level spans | ||
| // and spans marked as analyzed by the tracer. | ||
| // A span is considered top-level if: | ||
| // - it's a root span | ||
| // - its parent is unknown (other part of the code, distributed trace) | ||
| // - its parent belongs to another service (in that case it's a "local root" | ||
| // being the highest ancestor of other spans belonging to this service and | ||
| // attached to it). | ||
| func GetAnalyzedSpans(sps []*pb.Span) []*pb.Span { | ||
| // build a lookup map | ||
| spanIDToIdx := make(map[uint64]int, len(sps)) | ||
| for i, span := range sps { | ||
| spanIDToIdx[span.SpanID] = i | ||
| } | ||
|
|
||
| top := []*pb.Span{} | ||
|
|
||
| extractor := event.NewMetricBasedExtractor() | ||
|
|
||
| // iterate on each span and mark them as top-level if relevant | ||
| for _, span := range sps { | ||
| // The tracer can mark a span to be analyzed, with a value 0-1, where 1 is always keep, and 0 is always reject. | ||
| // Values between 0-1 are used by the agent to prioritize which spans are sampled or not. Since we can't | ||
| // reliably apply sampling decisions in a serverless environment, we keep any analyzed span with a priority | ||
| // greater than 0, and let the backend make the sampling decision instead. | ||
| priority, extracted := extractor.Extract(span, sampler.PriorityUserKeep) | ||
| shouldExtract := priority > 0 && extracted | ||
|
|
||
| if span.ParentID != 0 { | ||
| if parentIdx, ok := spanIDToIdx[span.ParentID]; ok && sps[parentIdx].Service == span.Service && !shouldExtract { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| top = append(top, span) | ||
| } | ||
| return top | ||
| } | ||
|
|
||
| // Compute Sublayers updates a spans metrics with relevant metadata so that it's duration and breakdown between different services can | ||
| // be accurately displayed in the Datadog UI | ||
| func ComputeSublayerMetrics(t pb.Trace) { | ||
| root := traceutil.GetRoot(t) | ||
| traceutil.ComputeTopLevel(t) | ||
|
|
||
| subtraces := stats.ExtractSubtraces(t, root) | ||
| sublayers := make(map[*pb.Span][]stats.SublayerValue) | ||
| for _, subtrace := range subtraces { | ||
| subtraceSublayers := stats.ComputeSublayers(subtrace.Trace) | ||
| sublayers[subtrace.Root] = subtraceSublayers | ||
| stats.SetSublayersOnSpan(subtrace.Root, subtraceSublayers) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.