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

Named Tracers / Tracer Registry #582

Merged

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Dec 2, 2019

Initial spike of spec/#354

Do not merge until the spec is finalized.

Which problem is this PR solving?

Open questions from spec

  • Is name required or optional?
  • What happens if you try to get the same tracer twice with the same name/version but a different config
    • Currently, we do not overwrite
  • Are all configs managed by tracer or by tracer registry?
    • per-tracer configs may be desirable by some but the same can be achieved by creating a second tracer registry if required

Short description of the changes

There is now only 1 type of Tracer. BasicTracer/WebTracer/NodeTracer are gone. The platform specific logic is moved into their respective registries.

BasicTracerRegistry

This is the base class for web and node tracer registries. It maintains span processors and all created tracers. Calling getTracer(name, version) will get the tracer with the given name and version, creating it if required. The default name is the empty string. The default version is '*'

  • Calling getTracer('', '*') is equivalent to getTracer()
  • Calling getTracer('mysql', '*') is equivalent to getTracer('mysql')
  • Calling getTracer with the same inputs twice will return the same tracer
  • The 'wildcard' version of a tracer with a given name is a new tracer. It will not get a previously created versioned tracer. Calling getTracer('mysql') will return the same tracer as getTracer('mysql', '*') but NOT the same tracer as getTracer('mysql', '0.2.0')

NodeTracerRegistry

  • Inherits from BasicTracerRegistry
  • Loads plugins
  • Uses AsyncHooksScopeManager by default
  • Loads default plugins if not configured

WebTracerRegistry

  • Inherits from BasicTracerRegistry
  • Uses StackScopeManager by default

Plugins

Plugins are now expected to call super with a name and version. This is the name and version of the telemetry itself, NOT the name and version of the module being instrumented. For example, the mysql plugin calls super('opentelemetry.mysql', '0.2.0'). BasePlugin.enable now expects a TracerRegistry where it previously expected a Tracer. When a span is created by a tracer, it injects itself the same way it previously did, but delegates calls to getActiveSpanProcessor to the TracerRegistry that created it. In this way, span processors that are registered with a TracerRegistry after a plugin has been enabled are still called by new spans.

Core

initGlobalTracer has been replaced by initGlobalTracerRegistry. getGlobalTracerRegistry now exists to access the global tracer registry. getTracer still exists and returns a tracer from the current global tracer registry.

Tracer Options

The tracer registry is initialized with the same options that tracers were previously initialized with. It is possible to get a tracer with different options by passing an options object as a third argument to getTracer (const tracerWithLogger = registry.getTracer('mysql', '0.2.0', { logger });). The global getTracer function does not have a third tracer options parameter and you will need to call registry.getTracer if you want that functionality.

@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

Merging #582 into master will increase coverage by 0.08%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #582      +/-   ##
==========================================
+ Coverage   89.77%   89.85%   +0.08%     
==========================================
  Files         215      214       -1     
  Lines       10137    10183      +46     
  Branches      936      933       -3     
==========================================
+ Hits         9100     9150      +50     
+ Misses       1037     1033       -4
Impacted Files Coverage Δ
...ages/opentelemetry-plugin-http/test/utils/utils.ts 33.33% <0%> (-26.67%) ⬇️
packages/opentelemetry-plugin-mysql/src/utils.ts 90.9% <0%> (-4.55%) ⬇️
packages/opentelemetry-plugin-dns/src/version.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/src/config.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/src/utility.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-plugin-redis/src/version.ts 100% <0%> (ø) ⬆️
...telemetry-plugin-grpc/test/utils/assertionUtils.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/test/Span.test.ts 100% <0%> (ø) ⬆️
.../opentelemetry-plugin-dns/test/utils/assertSpan.ts 100% <0%> (ø) ⬆️
...ry-tracing/test/export/SimpleSpanProcessor.test.ts 100% <0%> (ø) ⬆️
... and 17 more

@dyladan dyladan changed the title Tracer registry Draft Named Tracers / Tracer Registry Dec 2, 2019
Copy link
Member

@bg451 bg451 left a comment

Choose a reason for hiding this comment

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

All of the comments I made during our essentially in person review were addressed, so ya went through this again and left a few comments but this LGTM. There's definitely a question of what to do with the tracer name and version but that's a separate issue.

@dyladan
Copy link
Member Author

dyladan commented Dec 17, 2019

Updated to be up-to-date with current spec https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-tracing.md#obtaining-a-tracer where name is required. When/if #345 merges we can revisit. It is easier to make name optional later than it is to make it required later.

I'm removing the draft tag from this so we can begin the formal review process but other SIGs have already merged their named tracer implementations.

@dyladan dyladan added Awaiting reviewer feedback enhancement New feature or request and removed Draft labels Dec 17, 2019
@dyladan dyladan marked this pull request as ready for review December 17, 2019 15:32
@mayurkale22
Copy link
Member

#651 is merged now, could you please make this PR ready for review. Thanks :)

@dyladan
Copy link
Member Author

dyladan commented Jan 3, 2020

#651 is merged now, could you please make this PR ready for review. Thanks :)

Should be good to review now

@dyladan
Copy link
Member Author

dyladan commented Jan 3, 2020

lint & docs is failing because david.dm is down again. It is not an actual failure.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

lgtm, great work!

@mayurkale22
Copy link
Member

Please, resolve the conflicts. @open-telemetry/javascript-approvers This is relatively big and important change, we need more reviews for this.

@dyladan
Copy link
Member Author

dyladan commented Jan 6, 2020

Please, resolve the conflicts.

@mayurkale22 done

@mayurkale22 mayurkale22 added needs-more-reviewers PRs with this label are ready for review and needs more people to review to move forward. size/XL and removed Awaiting reviewer feedback labels Jan 6, 2020
Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

There is one thing which confuses me a lot
.getTracer('default’)
is the name required or can I use
.getTracer()
Do I always have to provide the default name and if that is the case should the registry has the static value then. Or if I don’t need to provide the name then I would rather remove default from all examples. If the default is required I would still remove it and make it default name when nothing is provided.
Other than that looks fine

@@ -71,6 +71,7 @@ docs

#lerna
.changelog
package.json.lerna_backup
Copy link
Member

Choose a reason for hiding this comment

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

is this intentional ?

@mayurkale22
Copy link
Member

If the default is required I would still remove it and make it default name when nothing is provided.

+1 I agreed. As per the specs: In case an invalid name (null or empty string) is specified, a working default Tracer implementation as a fallback is returned. With this, we can remove default from all the examples - much simpler and easier to understand.

@mayurkale22 mayurkale22 removed the needs-more-reviewers PRs with this label are ready for review and needs more people to review to move forward. label Jan 8, 2020
@mayurkale22
Copy link
Member

As @dyladan is on vacation for a week, I was thinking to merge this one and handle @obecny's recommendation/suggestion (#582 (review)) in the separate PR. @obecny WDYT?

@obecny
Copy link
Member

obecny commented Jan 9, 2020

@mayurkale22 fine for me

@mayurkale22 mayurkale22 added the Merge:LGTM This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.) label Jan 9, 2020
@mayurkale22 mayurkale22 merged commit 18c6aa4 into open-telemetry:master Jan 9, 2020
@dyladan dyladan deleted the tracer-registry branch January 13, 2020 13:54
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
* feat: spike of named tracer registry

* chore: mysql/mongo tracer registry support

* fix: lint

* chore: add getTracer back

* chore: change default tracer name to empty string

* fix: lint

* chore: update examples for registry

* chore(tracer-registry): make name required

* chore: lint

* chore: update examples for required tracer name

* chore: remove unused tracer delegate

* chore: remove references to basic tracer

* chore: remove references to NodeTracer

* chore: update xhr for tracer registry

* chore: update tracer names to match package names

* chore: add version script to all packages

* chore: update plugins to use version script

* chore: add jsdoc to noop tracer registry

* chore: update ioredis for tracer registry

* chore: update pg pool for tracer registry

* fix: lint

* chore: fix tests

* chore: lint

* chore: lint

Co-authored-by: Mayur Kale <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Merge:LGTM This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants