UNPKG

2.26 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright The OpenTelemetry Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.MultiSpanProcessor = void 0;
19const core_1 = require("@opentelemetry/core");
20/**
21 * Implementation of the {@link SpanProcessor} that simply forwards all
22 * received events to a list of {@link SpanProcessor}s.
23 */
24class MultiSpanProcessor {
25 constructor(_spanProcessors) {
26 this._spanProcessors = _spanProcessors;
27 }
28 forceFlush() {
29 const promises = [];
30 for (const spanProcessor of this._spanProcessors) {
31 promises.push(spanProcessor.forceFlush());
32 }
33 return new Promise(resolve => {
34 Promise.all(promises)
35 .then(() => {
36 resolve();
37 })
38 .catch(error => {
39 core_1.globalErrorHandler(error || new Error('MultiSpanProcessor: forceFlush failed'));
40 resolve();
41 });
42 });
43 }
44 onStart(span, context) {
45 for (const spanProcessor of this._spanProcessors) {
46 spanProcessor.onStart(span, context);
47 }
48 }
49 onEnd(span) {
50 for (const spanProcessor of this._spanProcessors) {
51 spanProcessor.onEnd(span);
52 }
53 }
54 shutdown() {
55 const promises = [];
56 for (const spanProcessor of this._spanProcessors) {
57 promises.push(spanProcessor.shutdown());
58 }
59 return new Promise((resolve, reject) => {
60 Promise.all(promises).then(() => {
61 resolve();
62 }, reject);
63 });
64 }
65}
66exports.MultiSpanProcessor = MultiSpanProcessor;
67//# sourceMappingURL=MultiSpanProcessor.js.map
\No newline at end of file