text: "use strict";
  /*
   * Copyright The OpenTelemetry Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      https://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.BasicTracerProvider = void 0;
  const api = require("@opentelemetry/api");
  const core_1 = require("@opentelemetry/core");
  const _1 = require(".");
  const config_1 = require("./config");
  const MultiSpanProcessor_1 = require("./MultiSpanProcessor");
  const NoopSpanProcessor_1 = require("./NoopSpanProcessor");
  const resources_1 = require("@opentelemetry/resources");
  /**
   * This class represents a basic tracer provider which platform libraries can extend
   */
  class BasicTracerProvider {
      constructor(config = config_1.DEFAULT_CONFIG) {
          var _a, _b;
          this._registeredSpanProcessors = [];
          this._tracers = new Map();
          this.activeSpanProcessor = new NoopSpanProcessor_1.NoopSpanProcessor();
          this.logger = (_a = config.logger) !== null && _a !== void 0 ? _a : new core_1.ConsoleLogger(config.logLevel);
          this.resource = (_b = config.resource) !== null && _b !== void 0 ? _b : resources_1.Resource.createTelemetrySDKResource();
          this._config = Object.assign({}, config, {
              logger: this.logger,
              resource: this.resource,
          });
      }
      getTracer(name, version = '*', config) {
          const key = `${name}@${version}`;
          if (!this._tracers.has(key)) {
              this._tracers.set(key, new _1.Tracer({ name, version }, config || this._config, this));
          }
          return this._tracers.get(key);
      }
      /**
       * Adds a new {@link SpanProcessor} to this tracer.
       * @param spanProcessor the new SpanProcessor to be added.
       */
      addSpanProcessor(spanProcessor) {
          this._registeredSpanProcessors.push(spanProcessor);
          this.activeSpanProcessor = new MultiSpanProcessor_1.MultiSpanProcessor(this._registeredSpanProcessors);
      }
      getActiveSpanProcessor() {
          return this.activeSpanProcessor;
      }
      /**
       * Register this TracerProvider for use with the OpenTelemetry API.
       * Undefined values may be replaced with defaults, and
       * null values will be skipped.
       *
       * @param config Configuration object for SDK registration
       */
      register(config = {}) {
          api.trace.setGlobalTracerProvider(this);
          if (config.propagator === undefined) {
              config.propagator = new core_1.CompositePropagator({
                  propagators: [new core_1.HttpCorrelationContext(), new core_1.HttpTraceContext()],
              });
          }
          if (config.contextManager) {
              api.context.setGlobalContextManager(config.contextManager);
          }
          if (config.propagator) {
              api.propagation.setGlobalPropagator(config.propagator);
          }
      }
      shutdown() {
          return this.activeSpanProcessor.shutdown();
      }
  }
  exports.BasicTracerProvider = BasicTracerProvider;
  //# sourceMappingURL=BasicTracerProvider.js.map