ProxyTracerProvider.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { ProxyTracer } from './ProxyTracer';
  17. import { NoopTracerProvider } from './NoopTracerProvider';
  18. const NOOP_TRACER_PROVIDER = new NoopTracerProvider();
  19. /**
  20. * Tracer provider which provides {@link ProxyTracer}s.
  21. *
  22. * Before a delegate is set, tracers provided are NoOp.
  23. * When a delegate is set, traces are provided from the delegate.
  24. * When a delegate is set after tracers have already been provided,
  25. * all tracers already provided will use the provided delegate implementation.
  26. */
  27. export class ProxyTracerProvider {
  28. /**
  29. * Get a {@link ProxyTracer}
  30. */
  31. getTracer(name, version, options) {
  32. var _a;
  33. return ((_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options));
  34. }
  35. getDelegate() {
  36. var _a;
  37. return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
  38. }
  39. /**
  40. * Set the delegate tracer provider
  41. */
  42. setDelegate(delegate) {
  43. this._delegate = delegate;
  44. }
  45. getDelegateTracer(name, version, options) {
  46. var _a;
  47. return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
  48. }
  49. }
  50. //# sourceMappingURL=ProxyTracerProvider.js.map