UNPKG

2.63 kBJavaScriptView Raw
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 */
16import { globalErrorHandler } from '@opentelemetry/core';
17/**
18 * Implementation of the {@link SpanProcessor} that simply forwards all
19 * received events to a list of {@link SpanProcessor}s.
20 */
21var MultiSpanProcessor = /** @class */ (function () {
22 function MultiSpanProcessor(_spanProcessors) {
23 this._spanProcessors = _spanProcessors;
24 }
25 MultiSpanProcessor.prototype.forceFlush = function () {
26 var promises = [];
27 for (var _i = 0, _a = this._spanProcessors; _i < _a.length; _i++) {
28 var spanProcessor = _a[_i];
29 promises.push(spanProcessor.forceFlush());
30 }
31 return new Promise(function (resolve) {
32 Promise.all(promises)
33 .then(function () {
34 resolve();
35 })
36 .catch(function (error) {
37 globalErrorHandler(error || new Error('MultiSpanProcessor: forceFlush failed'));
38 resolve();
39 });
40 });
41 };
42 MultiSpanProcessor.prototype.onStart = function (span, context) {
43 for (var _i = 0, _a = this._spanProcessors; _i < _a.length; _i++) {
44 var spanProcessor = _a[_i];
45 spanProcessor.onStart(span, context);
46 }
47 };
48 MultiSpanProcessor.prototype.onEnd = function (span) {
49 for (var _i = 0, _a = this._spanProcessors; _i < _a.length; _i++) {
50 var spanProcessor = _a[_i];
51 spanProcessor.onEnd(span);
52 }
53 };
54 MultiSpanProcessor.prototype.shutdown = function () {
55 var promises = [];
56 for (var _i = 0, _a = this._spanProcessors; _i < _a.length; _i++) {
57 var spanProcessor = _a[_i];
58 promises.push(spanProcessor.shutdown());
59 }
60 return new Promise(function (resolve, reject) {
61 Promise.all(promises).then(function () {
62 resolve();
63 }, reject);
64 });
65 };
66 return MultiSpanProcessor;
67}());
68export { MultiSpanProcessor };
69//# sourceMappingURL=MultiSpanProcessor.js.map
\No newline at end of file