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

[exporter/datadog]: add max tag length #3185

Merged

Conversation

ericmustin
Copy link
Contributor

Description:

This PR is part of work to address Payload size errors reported here: #2676

Combined with batching of spans/traces, spans with very large attribute values such as stacktraces can cause payload sizes to become excessive. This PR adds a max tag (a datadog span attribute, basically), value helper function, and truncates tag values when they're too large, which brings this in line with Datadog-Agent limits: https://github.com/DataDog/datadog-agent/blob/140a4ee164261ef2245340c50371ba989fbeb038/pkg/trace/traceutil/truncate.go#L23

Additionally, worth noting that work being done to directly import and re-use portions of the datadog-agent codebase will make this sort of thing much easier, and work being done within datadog to permit shorter batching times should also help resolve the Payload size errors being seen. However for now this PR can help.

Link to tracking Issue:

#2676

Testing:

Add unit tests

Documentation:
n/a

@ericmustin ericmustin requested a review from a team as a code owner April 20, 2021 22:05
@codecov
Copy link

codecov bot commented Apr 20, 2021

Codecov Report

Merging #3185 (54a02c3) into main (17399fa) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 54a02c3 differs from pull request most recent head 784d2b1. Consider uploading reports for the commit 784d2b1 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3185      +/-   ##
==========================================
+ Coverage   91.91%   91.92%   +0.01%     
==========================================
  Files         494      494              
  Lines       23939    23956      +17     
==========================================
+ Hits        22003    22022      +19     
+ Misses       1429     1428       -1     
+ Partials      507      506       -1     
Flag Coverage Δ
integration 63.68% <ø> (ø)
unit 90.94% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
exporter/datadogexporter/translate_traces.go 89.47% <100.00%> (+0.08%) ⬆️
exporter/datadogexporter/utils/trace_helpers.go 12.96% <100.00%> (+12.96%) ⬆️
exporter/signalfxexporter/config.go 83.67% <0.00%> (-2.38%) ⬇️
...porter/awsprometheusremotewriteexporter/factory.go 100.00% <0.00%> (ø)
receiver/k8sclusterreceiver/watcher.go 97.64% <0.00%> (+2.35%) ⬆️
exporter/awsprometheusremotewriteexporter/auth.go 86.66% <0.00%> (+4.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b747cdc...784d2b1. Read the comment docs.

// TruncateUTF8 truncates the given string to make sure it uses less than limit bytes.
// If the last character is an utf8 character that would be splitten, it removes it
// entirely to make sure the resulting string is not broken.
func TruncateUTF8(s string, limit int) string {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add some tests for this function (just so that Collector maintainers have an accurate coverage measure)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

exporter/datadogexporter/translate_traces.go Outdated Show resolved Hide resolved
Comment on lines 385 to 388
if len(v) > MaxMetaValLen {
v = utils.TruncateUTF8(v, MaxMetaValLen) + "..."
}

Copy link
Member

Choose a reason for hiding this comment

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

Why do we want to do this only when it's not a service name/span type/analytics event? Some of those can have arbitrary values, right? Why not do this every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, idk, i rushed things. should be for everything, i'll update

// ensure that truncation helperr function truncates strings as expected
// and accounts for the limit and multi byte ending characters
// from https://github.com/DataDog/datadog-agent/blob/140a4ee164261ef2245340c50371ba989fbeb038/pkg/trace/traceutil/truncate_test.go#L15
func TestTruncateUTF8Strings(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I think codecov doesn't see this test because it's not on the utils package (where it arguably should be). Can you move it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated (along with other pr), I think codecov found it?

@ericmustin
Copy link
Contributor Author

@bogdandrutu Could i get a quick review here when u have a moment? 🙇

@tigrannajaryan
Copy link
Member

Please resolve the conflicts.

@ericmustin
Copy link
Contributor Author

@tigrannajaryan resolved!

@tigrannajaryan tigrannajaryan merged commit 8443c7f into open-telemetry:main Apr 28, 2021
mstumpfx pushed a commit to mstumpfx/opentelemetry-collector-contrib that referenced this pull request Aug 31, 2021
This PR is part of work to address Payload size errors reported here: open-telemetry#2676

Combined with batching of spans/traces, spans with very large attribute values such as stacktraces can cause payload sizes to become excessive. This PR adds a max tag (a datadog span attribute, basically), value helper function, and truncates tag values when they're too  large, which brings this in line with Datadog-Agent limits: https://github.com/DataDog/datadog-agent/blob/140a4ee164261ef2245340c50371ba989fbeb038/pkg/trace/traceutil/truncate.go#L23

Additionally, worth noting that work being done to directly import and re-use portions of the datadog-agent codebase will make this sort of thing much easier, and work being done within datadog to permit shorter batching times should also help resolve the Payload size errors being seen. However for now this PR can help.

**Link to tracking Issue:** <Issue number if applicable> 

open-telemetry#2676
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants