Skip to content
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

[serverless] Filter out spans from Lambda Library and runtime #11687

Merged
merged 23 commits into from
Apr 29, 2022

Conversation

nhinsch
Copy link
Contributor

@nhinsch nhinsch commented Apr 15, 2022

What does this PR do?

  • Adds a mechanism to the trace agent to filter out (i.e. delete) spans before processing
  • Uses this mechanism to filter out spans generated by the Datadog Lambda Library and the Lambda runtime
  • Removes the previous attempt to filter out these spans, which did not always work
  • Migrates Serverless integration tests to .NET 6. The reason this is included in the same PR is that these tests prove the new filter mechanism works, as without it the test will fail.

Motivation

Sometimes dd-trace can generate spans reflecting HTTP requests made by the Datadog Lambda Library or the Lambda runtime itself. These spans should be excluded from traces in all circumstances because they do not come from customer code. Several customers have complained about seeing these spans.

Previously, we implemented a blocklist to exclude these spans using the ignore_resources configuration option. This did not fully work because the resource of the span was not always consistent (sometimes it included the URL, but sometimes it did not), and also this mechanism only applies to the root span of a trace.

This PR removes the old blocklist mechanism and checks every span individually (in the Serverless agent only).

Possible Drawbacks / Trade-offs

  • This does add a function call to the critical path of processing a trace, but outside of the Serverless agent it's a no-op.

Describe how to test/QA your changes

The included integration tests for .NET 6 show that the filtering mechanism works. To reproduce the bug, disable the filtering function and run the integration tests.

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • At least one team/.. label has been applied, indicating the team(s) that should QA this change.

@nhinsch nhinsch added changelog/no-changelog [deprecated] qa/skip-qa - use other qa/ labels [DEPRECATED] Please use qa/done or qa/no-code-change to skip creating a QA card team/serverless labels Apr 15, 2022
@nhinsch nhinsch added this to the Triage milestone Apr 15, 2022
@nhinsch nhinsch requested review from a team as code owners April 15, 2022 15:19
Copy link
Contributor

@hghotra hghotra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
@bits-bot
Copy link
Collaborator

bits-bot commented Apr 25, 2022

CLA assistant check
All committers have signed the CLA.

pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
Base automatically changed from sls-wip-apr-22 to main April 27, 2022 12:45
@maxday maxday requested a review from a team as a code owner April 27, 2022 12:45
return
}
for _, chunk := range p.Chunks() {
out := make([]*pb.Span, 0, len(chunk.Spans))
Copy link
Contributor

@gbbr gbbr Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can avoid creating this array each and every time and only do it if an actual span is discarded. Alternatively, we can even use the same array and just move discarded items (by swapping them) to the last element and keeping track of the new length, slicing chunks.Spans at the very end.

Either of the two solutions above will be much better, latter being preferred.

Since you've now added a new feature to the trace-agent, we should make sure it works as best as it can from the first go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I see what you're saying now. For some reason I thought that this PR only affects serverless but I see it's a change to the trace agent in general which can be leveraged by other teams if they provide a discardFunction. I'm going to go ahead and implement the swap-and-resize way to remove the element as you suggested which will avoid a slice resize operation as well as avoid allocating a new struct. I'm assuming the order doesn't matter?

@@ -349,6 +355,22 @@ func newChunksArray(chunks []*pb.TraceChunk) []*pb.TraceChunk {

var _ api.StatsProcessor = (*Agent)(nil)

// filterSpans removes all spans for which the provided FilterSpan function returns true
func (a *Agent) filterSpans(p *api.Payload) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a unit test for this individual function too, and ideally a benchmark too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this function already have a unit test? Maybe I'm misunderstanding something.

Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better. Thanks.

pkg/trace/agent/agent.go Outdated Show resolved Hide resolved
Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience!

n := 0
for _, span := range chunk.Spans {
if !a.DiscardSpan(span) {
chunk.Spans[n] = span
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this method. I wouldn't have thought of it 🙂 👏🏻 TIL!

@maxday
Copy link
Contributor

maxday commented Apr 29, 2022

I think we should remove script/.cache + script/.src folders from this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog [deprecated] qa/skip-qa - use other qa/ labels [DEPRECATED] Please use qa/done or qa/no-code-change to skip creating a QA card team/serverless
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants