ProxyTracer.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 { NoopTracer } from './NoopTracer';
  17. const NOOP_TRACER = new NoopTracer();
  18. /**
  19. * Proxy tracer provided by the proxy tracer provider
  20. */
  21. export class ProxyTracer {
  22. constructor(_provider, name, version, options) {
  23. this._provider = _provider;
  24. this.name = name;
  25. this.version = version;
  26. this.options = options;
  27. }
  28. startSpan(name, options, context) {
  29. return this._getTracer().startSpan(name, options, context);
  30. }
  31. startActiveSpan(_name, _options, _context, _fn) {
  32. const tracer = this._getTracer();
  33. return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
  34. }
  35. /**
  36. * Try to get a tracer from the proxy tracer provider.
  37. * If the proxy tracer provider has no delegate, return a noop tracer.
  38. */
  39. _getTracer() {
  40. if (this._delegate) {
  41. return this._delegate;
  42. }
  43. const tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
  44. if (!tracer) {
  45. return NOOP_TRACER;
  46. }
  47. this._delegate = tracer;
  48. return this._delegate;
  49. }
  50. }
  51. //# sourceMappingURL=ProxyTracer.js.map