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

feat(proto): add @opentelemetry/otlp-transformer package with hand-rolled transformation #2746

Merged
merged 12 commits into from
Mar 23, 2022

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Jan 28, 2022

related: #2665

This is an alternative to #2691 which includes only the types and hand-rolled transformation functions to convert traces and metrics into otlp json. Skipping protobufjs drastically reduces the complexity and size of the final binary, which will be important in the browser context.

It also includes a descriptor.json file in the root of the package which can be loaded by protobufjs and used to serialize messages into protobuf.

todo:

  • add an option to export traces in a protobuf-compatible way (the JSON representation requires trace and span IDs to be in hex, instead of the base64 format expected by the library)
  • update README to reflect the changes

@dyladan dyladan requested a review from a team January 28, 2022 20:49
@codecov
Copy link

codecov bot commented Jan 28, 2022

Codecov Report

Merging #2746 (b6b7c40) into main (b0f8a2d) will not change coverage.
The diff coverage is n/a.

❗ Current head b6b7c40 differs from pull request most recent head 5be5d87. Consider uploading reports for the commit 5be5d87 to get more accurate results

@@           Coverage Diff           @@
##             main    #2746   +/-   ##
=======================================
  Coverage   93.19%   93.19%           
=======================================
  Files         157      157           
  Lines        5117     5117           
  Branches     1097     1097           
=======================================
  Hits         4769     4769           
  Misses        348      348           

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

LGTM % nits.

experimental/tsconfig.json Outdated Show resolved Hide resolved
experimental/packages/proto/src/metrics/types.ts Outdated Show resolved Hide resolved
@legendecas legendecas linked an issue Feb 14, 2022 that may be closed by this pull request
@morigs
Copy link
Contributor

morigs commented Feb 21, 2022

Hi, sorry for disturbing, are there any plans to merge this in near future? I am concerned about #2675

@dyladan
Copy link
Member Author

dyladan commented Feb 22, 2022

Hi, sorry for disturbing, are there any plans to merge this in near future? I am concerned about #2675

This currently on hold waiting on #2775

I will update the proto in the existing implementations to get #2675 unblocked so we don't need to rush this one.

@dyladan
Copy link
Member Author

dyladan commented Feb 23, 2022

Converting to draft while we wait on #2775

@dyladan
Copy link
Member Author

dyladan commented Feb 25, 2022

I think we have 2 final questions to resolve before merging this @open-telemetry/javascript-maintainers @open-telemetry/javascript-approvers

  1. What should this package be named?

Right now I have it as @opentelemetry/proto but it actually doesn't return protobuf, only an object which uses the OTLP types. Maybe @opentelemetry/otlp-transformer? I'm open to suggestions. I don't expect this package to be used directly by users so a short friendly name isn't probably important.

  1. How can it be stabilized?

The return type of each serialization function depends on the field names in the proto which are unstable. For example, createExportTraceServiceRequest returns IExportTraceServiceRequest which uses the name instrumentationLibrary. That name is currently being considered to be changed to InstrumentationScope in open-telemetry/opentelemetry-proto#362 (review)

@dyladan
Copy link
Member Author

dyladan commented Feb 25, 2022

Marking as ready for review again as it is higher priority due to #2804

@vmarchaud
Copy link
Member

What should this package be named?

I agree that it shouldn't refer to proto directly and more to the protocol itself so i'm fine with @opentelemetry/otlp-transformer, maybe use otlp-json-encoder since it only encode to json for now ?

How can it be stabilized?

I'm not really sure but could we just have optional option that specify which proto version we encode to ? Once it get merged we could add a if that changes the generated representation ?

@dyladan
Copy link
Member Author

dyladan commented Feb 28, 2022

What should this package be named?

I agree that it shouldn't refer to proto directly and more to the protocol itself so i'm fine with @opentelemetry/otlp-transformer, maybe use otlp-json-encoder since it only encode to json for now ?

How can it be stabilized?

I'm not really sure but could we just have optional option that specify which proto version we encode to ? Once it get merged we could add a if that changes the generated representation ?

I would prefer not to do that if possible. I don't want to commit to maintaining all proto versions in parallel forever.

@legendecas
Copy link
Member

legendecas commented Feb 28, 2022

How can it be stabilized?

It sounds to me that the problem here is similar to the JSON representation of the OTLP protocol since the names of the fields/types have to be part of the stabilized API. Are there any roadmaps on the stabilization of JSON representation?

What should this package be named?

@opentelemetry/otlp-transformer or just @opentelemetry/otlp? Both sound cool to me.

Marking as ready for review again as it is higher priority due to #2804

Did you forget to hit the button? The PR is still a draft.

@dyladan dyladan marked this pull request as ready for review February 28, 2022 18:06
@legendecas
Copy link
Member

CI failure could be fixed by #2768

@vmarchaud
Copy link
Member

I would prefer not to do that if possible. I don't want to commit to maintaining all proto versions in parallel forever.

I don't personaly think another way to do this expect waiting for stabilization :/

@dyladan
Copy link
Member Author

dyladan commented Mar 1, 2022

I was thinking we could document in the tsdocs explicitly that we are generating protos of a certain version and that future minor versions may generate another version.

@dyladan
Copy link
Member Author

dyladan commented Mar 1, 2022

We could also independently version the package because we know it will need to be versioned each time something like this happens

@legendecas
Copy link
Member

We could also independently version the package because we know it will need to be versioned each time something like this happens

This sounds very similar to the experimental packages in the repo to me.

@dyladan
Copy link
Member Author

dyladan commented Mar 1, 2022

This sounds very similar to the experimental packages in the repo to me.

In the past we've had a requirement that stable packages don't depend on experimental packages, but maybe we can make a documented exception here in order to avoid leaking the implementation details of the OTLP transformation?

One other option would be to make this package a private package and bundle it as a bundled dependency in the OTLP exporters https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bundleddependencies. This might be a way to share this code without deploying it to NPM.

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Overall LGTM, great work!

@dyladan
Copy link
Member Author

dyladan commented Mar 15, 2022

Sorry for force push i had the wrong email in the history

Copy link
Contributor

@seemk seemk left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

const instrumentationLibraryMetrics = ilmEntry.value;
if (instrumentationLibraryMetrics.length > 0) {
const lib = instrumentationLibraryMetrics[0].instrumentationLibrary;
resourceMetrics.push({ instrumentationLibrary: lib, instrumentationLibraryMetrics, schemaUrl: lib.schemaUrl });
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed 1 thing - the instrumentation library schema URL is converted to the resource schema URL. Is it supposed to be like this? See the comment here: https://github.com/open-telemetry/opentelemetry-proto/blob/v0.14.0/opentelemetry/proto/metrics/v1/metrics.proto#L55-L58

Just need clarification, noticed while prepping a followup to this PR to use the new SDK metric types and can rectify it there.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the current types don't provide a schema url for the resource. I'll remove it and leave a TODO in the code.

Copy link
Member Author

@dyladan dyladan Mar 22, 2022

Choose a reason for hiding this comment

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

actually it doesn't work like you're thinking. The resource schema url would live next to the resourcemetrics array, not within it. In any case, the types in this particular function are not otlp types so I renamed them to make it more obvious what they represent. You can look at the tests to see that the output is correct.

@legendecas
Copy link
Member

The CI failures for sdk-node resource detectors should have been fixed by #2844.

@dyladan
Copy link
Member Author

dyladan commented Mar 23, 2022

Browser test failure seems unrelated

@dyladan dyladan changed the title feat(proto): add @opentelemetry/proto package with hand-rolled transformation feat(proto): add @opentelemetry/otlp-transformer package with hand-rolled transformation Mar 23, 2022
@dyladan dyladan added the enhancement New feature or request label Mar 23, 2022
@dyladan dyladan merged commit 549bd5b into open-telemetry:main Mar 23, 2022
@dyladan dyladan deleted the proto-json branch March 23, 2022 17:51
@legendecas
Copy link
Member

Browser test failure seems unrelated

@dyladan I've created an issue to track that #2852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants