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

Add unmarshalling for pdata.Traces #1948

Merged

Conversation

pkositsyn
Copy link
Contributor

Description:
Adding a feature - allow to unmarshal pdata.Traces from protobuf

Link to tracking Issue: #1939

Testing: unmarshal(marshal(trace)) = trace

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 13, 2020

CLA Check
The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Oct 13, 2020

Codecov Report

Merging #1948 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1948   +/-   ##
=======================================
  Coverage   91.41%   91.41%           
=======================================
  Files         284      284           
  Lines       16788    16793    +5     
=======================================
+ Hits        15347    15352    +5     
  Misses       1009     1009           
  Partials      432      432           
Impacted Files Coverage Δ
consumer/pdata/trace.go 100.00% <100.00%> (ø)

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 4016b2b...9ea120e. Read the comment docs.

@tigrannajaryan tigrannajaryan self-assigned this Oct 14, 2020
if err := proto.Unmarshal(data, traces); err != nil {
return err
}
*td.orig = traces.ResourceSpans
Copy link
Member

Choose a reason for hiding this comment

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

This won't work for zero-initialized td. Instead I suggest to change FromOtlpProtoBytes to take a pointer receiver and here do

td.orig = &traces.ResourceSpans

Copy link
Contributor Author

@pkositsyn pkositsyn Oct 14, 2020

Choose a reason for hiding this comment

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

If you look at similar ToOtlpProtoBytes - it has the same problem (actually I see no problem, no one guarantees zero-initialized structure to work properly). I cannot change abovementioned function, because this would break compatibility, and in my opinion it's better to be consistent in this case. Or even return to the first solution where function wasn't on the structure

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, it is unfortunate that we used value receivers on Traces, but it is too late now, so you are right, we need to use value receivers for consistency now. Please add a comment to FromOtlpProtoBytes to tell that NewTraces must be used to create the instance before calling this function. It is easy to make the mistake since one will probably try this first and will fail:

var td pdata.Traces
td.FromOtlpProtoBytes(someData)

@pkositsyn
Copy link
Contributor Author

@tigrannajaryan Added comment. Should be good to go

@tigrannajaryan tigrannajaryan merged commit ac26601 into open-telemetry:master Oct 15, 2020
@tigrannajaryan
Copy link
Member

Thanks @Vemmy124

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.

4 participants