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

fix: added support for Opentelemetry 0.18 #1234

Merged
merged 47 commits into from Apr 14, 2021
Merged

fix: added support for Opentelemetry 0.18 #1234

merged 47 commits into from Apr 14, 2021

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Mar 17, 2021

Introduces support for Opentelemetry 0.18 API which implements the
Tracing 1.0 specification.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1233 🦕

Introduces support for Opentelemetry 0.18 API which implements the
Tracing 1.0 specification.
@weyert weyert requested review from a team as code owners March 17, 2021 22:58
@google-cla
Copy link

google-cla bot commented Mar 17, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Mar 17, 2021
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Mar 17, 2021
@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #1234 (4f360e4) into master (e85b34c) will increase coverage by 0.04%.
The diff coverage is 99.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1234      +/-   ##
==========================================
+ Coverage   97.80%   97.84%   +0.04%     
==========================================
  Files          26       26              
  Lines       12642    12700      +58     
  Branches      611      607       -4     
==========================================
+ Hits        12364    12426      +62     
+ Misses        273      268       -5     
- Partials        5        6       +1     
Impacted Files Coverage Δ
src/publisher/index.ts 97.40% <96.66%> (-0.22%) ⬇️
src/opentelemetry-tracing.ts 100.00% <100.00%> (ø)
src/subscriber.ts 99.82% <100.00%> (+0.94%) ⬆️

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 e85b34c...4f360e4. Read the comment docs.

@google-cla
Copy link

google-cla bot commented Mar 17, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@weyert
Copy link
Contributor Author

weyert commented Mar 17, 2021

@googlebot I consent

@google-cla
Copy link

google-cla bot commented Mar 17, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@tapico-weyert
Copy link
Contributor

@googlebot I consent

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Mar 17, 2021
package.json Show resolved Hide resolved
Copy link
Contributor

@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

Question to the maintainers here, can we remove enableOpenTelemetryTracing option altogether?

Enabling instrumentation in OpenTelemetry should be done by

  1. User adding a dependency on the SDK (instead of just the API) @opentelemetry/tracing (which is why @weyert has moved it out of dependencies)
  2. User configuring the global tracer provider to the SDK TracerProvider as is done here:
    provider.register();

    An alternative is the user can pass a tracer provider instance as an option, otherwise we get the global one.

If the user doesn't take those steps, the @opentelemetry/api package will give no-op implementations that don't do anything. It should be implicit

src/opentelemetry-tracing.ts Outdated Show resolved Hide resolved
@@ -223,7 +192,15 @@ describe('Publisher', () => {
opentelemetry.trace.setGlobalTracerProvider(provider);

tracingPublisher.publish(buffer);
assert.ok(exporter.getFinishedSpans());
const spans = exporter.getFinishedSpans();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice this looks better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the problem is that it wasn't checking if it had a span so it always was successful (even now in master) if I change this to check the length >= 1 it will fail.

Only I am not well versed in this library or its tests to see were the issue is. It does like that _constructSpan always exits early due the first if-statement.

Copy link
Contributor

@aabmass aabmass Mar 19, 2021

Choose a reason for hiding this comment

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

So its still not creating a span with the current code?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I tried it a minute ago and it looks like it's still not getting any spans. I thought maybe it's because you have to add a tracer, but that doesn't seem to have changed it. I don't know much about OT either :)

Slightly unrelated: assert.equal shows up as deprecated for me, and it suggests assert.strictEqual.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take a look

Copy link
Contributor

Choose a reason for hiding this comment

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

@weyert I'll open a PR to your fork. I think my original suggestions were too lofty, I want to sync up with the pubsub folks before changing things too much.

test/subscriber.ts Outdated Show resolved Hide resolved
Small refactor to ensure no new tracer gets created for each call to the
`createSpan`-functio by initiating the `libraryTracer`-variable
@feywind
Copy link
Collaborator

feywind commented Mar 18, 2021

Thanks for all the code and comments, I appreciate it... I haven't really known what to do with the OT support since the APIs changed. It was an outside contribution, so none of us know that API too well. So to answer @aabmass 's comment, I'm open to guidance on where to take it over time.

Busy day today, I'll look at this in a bit! :)

@weyert
Copy link
Contributor Author

weyert commented Mar 19, 2021

Thanks for all the code and comments, I appreciate it... I haven't really known what to do with the OT support since the APIs changed. It was an outside contribution, so none of us know that API too well. So to answer @aabmass 's comment, I'm open to guidance on where to take it over time.

Busy day today, I'll look at this in a bit! :)

Yes, the API shouldn't really happen anymore as the API is 1.0.0 now and it shouldn't change much anymore and I think only backward compatible changes are allowed and 1.0.0 will be supported for a few years. The opentelemetry-js team is planning to release 1.0.0 rc of the SDK and API soon but not much has changed between 0.18 and 1.0.0-rc. I think migrating to 0.18 is a good start in the right direction.

Currently, I have upgraded to 0.18 and tried to remove the dependency to the tracing SDK package which isn't met to be used by libraries. Only during my changes I am have found a broken test which even occurs in the master-branch when improving the assert.ok to actually check that a span is being created. Until now it looks it only checks it was a thruthly value

@aabmass
Copy link
Contributor

aabmass commented Mar 22, 2021

@weyert the test failure looks to be related to globals and things running before this test. If I only run that case with npm run test -- -g 'export created spans' it passes. Might be related to the change I requested for the module level tracer.

I think depending when @feywind wants to make more changes, we should change things a bit. If we alter the configuration here and remove enableOpentelemetryTracing, it is a breaking change and would require a major release.

So for now @weyert, lets maybe leave the config in and just upgrade the library to 0.18?

@weyert
Copy link
Contributor Author

weyert commented Mar 22, 2021

@weyert the test failure looks to be related to globals and things running before this test. If I only run that case with npm run test -- -g 'export created spans' it passes. Might be related to the change I requested for the module level tracer.

Thanks for trying this out! I didn't think about trying this out!

I think depending when @feywind wants to make more changes, we should change things a bit. If we alter the configuration here and remove enableOpentelemetryTracing, it is a breaking change and would require a major release.

So for now @weyert, lets maybe leave the config in and just upgrade the library to 0.18?

Sounds good, so the change to startSpan and revert back to using the class?

Sorry, I haven't had a change yet to look into it today.

@aabmass
Copy link
Contributor

aabmass commented Mar 22, 2021

Sounds good, so the change to startSpan and revert back to using the class?

Hmm you mentioned it was broken before this PR too so maybe that won't fix it :/ but its worth a try

@feywind
Copy link
Collaborator

feywind commented Apr 9, 2021

We talked over the package.json thing, I think that's probably not going to change for now, but we might do something to make it more abstracted/standardized. I'd like to do it separately if we can get a clean build on this, though.

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 9, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 9, 2021
@weyert
Copy link
Contributor Author

weyert commented Apr 9, 2021

We talked over the package.json thing, I think that's probably not going to change for now, but we might do something to make it more abstracted/standardized. I'd like to do it separately if we can get a clean build on this, though.

That makes totally sense! :)

package.json Outdated
@@ -38,7 +38,7 @@
"clean": "gts clean",
"compile": "tsc -p . && cp -r protos build/",
"compile-protos": "compileProtos src",
"prepare": "npm run compile-protos && npm run compile && rm ./build/package.json",
"prepare": "npm run compile-protos && npm run compile",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you would need to revert the change from require to import approach for loading package.json. I don't think removing this is enough

@feywind
Copy link
Collaborator

feywind commented Apr 9, 2021

I'm a little bit confused, this branch now works and builds for me just fine locally. Actually removing the package.json in build broke some things for me. It's getting late here though, I'm going to look more next week.

@weyert
Copy link
Contributor Author

weyert commented Apr 10, 2021

I'm a little bit confused, this branch now works and builds for me just fine locally. Actually removing the package.json in build broke some things for me. It's getting late here though, I'm going to look more next week.

Most important that it works now :D Yeah confusing indeed.

@weyert
Copy link
Contributor Author

weyert commented Apr 13, 2021

Any news?

@feywind
Copy link
Collaborator

feywind commented Apr 13, 2021

Not yet, sorry. I'm going to just retry it again for good measure, in case it was a (long lasting) transient error. I don't think anything is wrong with the code at this point.

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2021
@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2021
@feywind
Copy link
Collaborator

feywind commented Apr 13, 2021

@weyert On my local machine, I did manage to get this part of the process to fail, but it was a different failure. I'm not sure why package.json would be required in files now, when it wasn't before. But I still don't get the Kokoro error, and I'm starting to wonder if someone tweaked settings somewhere. I'm asking others to see if they have any ideas.

@weyert
Copy link
Contributor Author

weyert commented Apr 13, 2021

@weyert On my local machine, I did manage to get this part of the process to fail, but it was a different failure. I'm not sure why package.json would be required in files now, when it wasn't before. But I still don't get the Kokoro error, and I'm starting to wonder if someone tweaked settings somewhere. I'm asking others to see if they have any ideas.

If you run it locally, what kind of output does the issues npm pack-command give you? The problem I had last week that something caused it not to bundle all files, see the problematic output below. If you look closely it's not including the whole build-directory only build/package.json is included. That's why it can't find the type definitions. Does this happen to you too?

npm notice 
npm notice 📦  @google-cloud/pubsub@2.10.0
npm notice === Tarball Contents === 
npm notice 11.4kB LICENSE           
npm notice 3.6kB  build/package.json
npm notice 3.2kB  package.json      
npm notice 57.5kB CHANGELOG.md      
npm notice 20.2kB README.md         
npm notice === Tarball Details === 
npm notice name:          @google-cloud/pubsub                    
npm notice version:       2.10.0                                  
npm notice filename:      google-cloud-pubsub-2.10.0.tgz          
npm notice package size:  22.0 kB                                 
npm notice unpacked size: 95.8 kB                                 
npm notice shasum:        3c77e1e46cfcbccb3cbd2de732d81a6fc5ff7823
npm notice integrity:     sha512-3H4qqXZWOSogu[...]6ERB1uWfewv2g==
npm notice total files:   5                                       
npm notice 
google-cloud-pubsub-2.10.0.tgz

@weyert
Copy link
Contributor Author

weyert commented Apr 13, 2021

What we could try @feywind is to revert basically this change: 0c2c76f and see what Kokoro things of it all.

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 14, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 14, 2021
@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 14, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 14, 2021
@feywind
Copy link
Collaborator

feywind commented Apr 14, 2021

!! 🎉
@weyert @aabmass Thank you both for all the work on this.

@feywind feywind merged commit aedc36c into googleapis:master Apr 14, 2021
@weyert
Copy link
Contributor Author

weyert commented Apr 15, 2021

Awesome! Thank you for merging :D

@weyert weyert deleted the remove-tracing-dependency branch April 15, 2021 03:45
gcf-merge-on-green bot pushed a commit that referenced this pull request Apr 15, 2021
🤖 I have created a release \*beep\* \*boop\*
---
## [2.11.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v2.10.0...v2.11.0) (2021-04-14)


### ⚠ BREAKING CHANGES

* fix: added support for Opentelemetry 0.18 - makes significant changes to OpenTelemetry support in order to unblock its usage again; the main user-visible change is that you will need to use 0.18+ versions of OpenTelemetry, and different items are passed to the server in spans.

### Bug Fixes

* added support for Opentelemetry 0.18 ([#1234](https://www.github.com/googleapis/nodejs-pubsub/issues/1234)) ([aedc36c](https://www.github.com/googleapis/nodejs-pubsub/commit/aedc36c3f8736eff1cb781b9e05457463481b3d6))
* follow-on proto updates from the removal of the common protos ([#1229](https://www.github.com/googleapis/nodejs-pubsub/issues/1229)) ([cb627d5](https://www.github.com/googleapis/nodejs-pubsub/commit/cb627d5555c617eb025181c9f9aaf1d2c9621a86))
* prevent attempt to publish 0 messages ([#1218](https://www.github.com/googleapis/nodejs-pubsub/issues/1218)) ([96e6535](https://www.github.com/googleapis/nodejs-pubsub/commit/96e653514b35d61f74ba2d5d6fa96e19bc45bf8c))
* remove common protos ([#1232](https://www.github.com/googleapis/nodejs-pubsub/issues/1232)) ([8838288](https://www.github.com/googleapis/nodejs-pubsub/commit/883828800c94f7ea21c8306d272b70b4576c664c))
* reverting the major from the OpenTelemetry change (it was already broken) ([#1257](https://www.github.com/googleapis/nodejs-pubsub/issues/1257)) ([09c428a](https://www.github.com/googleapis/nodejs-pubsub/commit/09c428a17eb20fcd0fc45301addb48d2bebc56a3))
* temporarily pin sinon at 10.0.0 ([#1252](https://www.github.com/googleapis/nodejs-pubsub/issues/1252)) ([0922164](https://www.github.com/googleapis/nodejs-pubsub/commit/09221643be0693463ed4e5d56efd0f1ebfbe78b7))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stops working when project is using opentelemetry-js 0.18+ packages
5 participants