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

Simplify SDK registration #837

Merged
merged 7 commits into from
Mar 10, 2020

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Mar 3, 2020

Which problem is this PR solving?

Short description of the changes

  • Add a register method to the TracerProvider which registers all configured SDK components with the API.

New register method on TracerProvider

Defaults

Propagator

Tracer Provider Default Value
Basic Trace Context
Node Trace Context
Web Trace Context

Context Manager

Tracer Provider Default Value
Basic Noop Scope Manager (manual context propagation)
Node Async Hooks Scope Manager
Web Zone Scope Manager
import { NodeTracerProvider } from '@opentelemetry/node';

const tracerProvider = new NodeTracerProvider();
tracerProvider.register();

Override Scope Manager or Propagator

import { NodeTracerProvider } from '@opentelemetry/node';
import { AsyncHooksScopeManager } from '@opentelemetry/scope-async-hooks';
import { HttpTraceContext } from '@opentelemetry/core';

const tracerProvider = new NodeTracerProvider();

tracerProvider.register({
  contextManager: new AsyncHooksScopeManager(),
  propagator: new HttpTraceContext(),
});

Use null to skip a default

import { NodeTracerProvider } from '@opentelemetry/node';

const tracerProvider = new NodeTracerProvider();

tracerProvider.register({
  propagator: null, // no propagator will be initialized
});

@codecov-io
Copy link

codecov-io commented Mar 3, 2020

Codecov Report

Merging #837 into master will decrease coverage by 1.01%.
The diff coverage is 47.29%.

@@            Coverage Diff             @@
##           master     #837      +/-   ##
==========================================
- Coverage   92.63%   91.62%   -1.02%     
==========================================
  Files         251      192      -59     
  Lines       11057     7310    -3747     
  Branches     1079      646     -433     
==========================================
- Hits        10243     6698    -3545     
+ Misses        814      612     -202
Impacted Files Coverage Δ
...ckages/opentelemetry-web/test/registration.test.ts 0% <0%> (ø)
...kages/opentelemetry-node/test/registration.test.ts 100% <100%> (ø)
...ackages/opentelemetry-web/src/WebTracerProvider.ts 100% <100%> (ø) ⬆️
...kages/opentelemetry-node/src/NodeTracerProvider.ts 100% <100%> (ø) ⬆️
...s/opentelemetry-tracing/src/BasicTracerProvider.ts 73.33% <27.27%> (-26.67%) ⬇️
...ges/opentelemetry-plugin-https/test/utils/utils.ts 33.33% <0%> (-26.67%) ⬇️
...ntelemetry-tracing/test/MultiSpanProcessor.test.ts 97.43% <0%> (-2.57%) ⬇️
...s/opentelemetry-metrics/test/MeterProvider.test.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-resources/src/constants.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/src/config.ts 100% <0%> (ø) ⬆️
... and 88 more

@dyladan dyladan added the enhancement New feature or request label Mar 3, 2020
@dyladan dyladan added this to the Beta milestone Mar 3, 2020
Copy link
Member

@OlivierAlbertini OlivierAlbertini left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -15,7 +15,12 @@
*/

import { BasePlugin } from '@opentelemetry/core';
import { BasicTracerProvider, TracerConfig } from '@opentelemetry/tracing';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';
Copy link
Member Author

Choose a reason for hiding this comment

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

Switch to stack

Copy link
Member

Choose a reason for hiding this comment

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

Is there any specific reason to use the stack scope manager by default ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Zone scope manager depends on zone.js which may not be available. If we have it as a dependency, then we may have a different zone.js than the end user. If we have it as a peer dependency, the scope manager would be broken for any user that doesn't have zone.js.

@mayurkale22 mayurkale22 mentioned this pull request Mar 4, 2020
@dyladan
Copy link
Member Author

dyladan commented Mar 5, 2020

@mayurkale22 when this looks good to you I think it is ok to merge. Just waiting on last resolution confirmation from @obecny

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, are you planning to update the examples in separate PR?

@dyladan
Copy link
Member Author

dyladan commented Mar 6, 2020

The old registration method still works so I think a separate pr makes sense here

@mayurkale22 mayurkale22 added the Merge:LGTM This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.) label Mar 6, 2020
@dyladan dyladan merged commit 5883e4e into open-telemetry:master Mar 10, 2020
@dyladan dyladan deleted the simple-setup branch March 10, 2020 12:39
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
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.

Simplify initialization
7 participants