@opentelemetry/exporter-trace-otlp-http 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -12
- package/build/esm/index.d.ts +0 -2
- package/build/esm/index.js +0 -3
- package/build/esm/index.js.map +1 -1
- package/build/esm/platform/browser/OTLPTraceExporter.d.ts +4 -5
- package/build/esm/platform/browser/OTLPTraceExporter.js +7 -7
- package/build/esm/platform/browser/OTLPTraceExporter.js.map +1 -1
- package/build/esm/platform/node/OTLPTraceExporter.d.ts +3 -3
- package/build/esm/platform/node/OTLPTraceExporter.js +7 -7
- package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/index.d.ts +0 -2
- package/build/esnext/index.js +0 -2
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +4 -5
- package/build/esnext/platform/browser/OTLPTraceExporter.js +7 -7
- package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -1
- package/build/esnext/platform/node/OTLPTraceExporter.d.ts +3 -3
- package/build/esnext/platform/node/OTLPTraceExporter.js +7 -7
- package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -1
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/src/index.d.ts +0 -2
- package/build/src/index.js +0 -5
- package/build/src/index.js.map +1 -1
- package/build/src/platform/browser/OTLPTraceExporter.d.ts +4 -5
- package/build/src/platform/browser/OTLPTraceExporter.js +7 -7
- package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
- package/build/src/platform/node/OTLPTraceExporter.d.ts +3 -3
- package/build/src/platform/node/OTLPTraceExporter.js +6 -6
- package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +8 -7
- package/build/esm/transform.d.ts +0 -80
- package/build/esm/transform.js +0 -287
- package/build/esm/transform.js.map +0 -1
- package/build/esm/types.d.ts +0 -209
- package/build/esm/types.js +0 -146
- package/build/esm/types.js.map +0 -1
- package/build/esnext/transform.d.ts +0 -80
- package/build/esnext/transform.js +0 -266
- package/build/esnext/transform.js.map +0 -1
- package/build/esnext/types.d.ts +0 -209
- package/build/esnext/types.js +0 -145
- package/build/esnext/types.js.map +0 -1
- package/build/src/transform.d.ts +0 -80
- package/build/src/transform.js +0 -282
- package/build/src/transform.js.map +0 -1
- package/build/src/types.d.ts +0 -209
- package/build/src/types.js +0 -148
- package/build/src/types.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
2
|
-
import * as otlpTypes from '../../types';
|
|
3
2
|
import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
|
|
4
3
|
import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
|
|
4
|
+
import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
|
|
5
5
|
/**
|
|
6
6
|
* Collector Trace Exporter for Node
|
|
7
7
|
*/
|
|
8
|
-
export declare class OTLPTraceExporter extends OTLPExporterNodeBase<ReadableSpan,
|
|
8
|
+
export declare class OTLPTraceExporter extends OTLPExporterNodeBase<ReadableSpan, IExportTraceServiceRequest> implements SpanExporter {
|
|
9
9
|
constructor(config?: OTLPExporterNodeConfigBase);
|
|
10
|
-
convert(spans: ReadableSpan[]):
|
|
10
|
+
convert(spans: ReadableSpan[]): IExportTraceServiceRequest;
|
|
11
11
|
getDefaultUrl(config: OTLPExporterNodeConfigBase): string;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=OTLPTraceExporter.d.ts.map
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.OTLPTraceExporter = void 0;
|
|
19
|
-
const transform_1 = require("../../transform");
|
|
20
19
|
const core_1 = require("@opentelemetry/core");
|
|
21
20
|
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
|
|
22
21
|
const otlp_exporter_base_2 = require("@opentelemetry/otlp-exporter-base");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
22
|
+
const otlp_transformer_1 = require("@opentelemetry/otlp-transformer");
|
|
23
|
+
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
|
|
24
|
+
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
|
|
25
25
|
/**
|
|
26
26
|
* Collector Trace Exporter for Node
|
|
27
27
|
*/
|
|
@@ -31,15 +31,15 @@ class OTLPTraceExporter extends otlp_exporter_base_1.OTLPExporterNodeBase {
|
|
|
31
31
|
this.headers = Object.assign(this.headers, core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
|
|
32
32
|
}
|
|
33
33
|
convert(spans) {
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, otlp_transformer_1.createExportTraceServiceRequest)(spans, true);
|
|
35
35
|
}
|
|
36
36
|
getDefaultUrl(config) {
|
|
37
37
|
return typeof config.url === 'string'
|
|
38
38
|
? config.url
|
|
39
39
|
: (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
|
|
40
|
-
? (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
|
|
40
|
+
? (0, otlp_exporter_base_2.appendRootPathToUrlIfNeeded)((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
|
|
41
41
|
: (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
|
|
42
|
-
? (0, otlp_exporter_base_2.
|
|
42
|
+
? (0, otlp_exporter_base_2.appendResourcePathToUrl)((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
|
|
43
43
|
: DEFAULT_COLLECTOR_URL;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPTraceExporter.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPTraceExporter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|
1
|
+
{"version":3,"file":"OTLPTraceExporter.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPTraceExporter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,8CAA2D;AAC3D,0EAAyE;AACzE,0EAI2C;AAC3C,sEAA8G;AAE9G,MAAM,+BAA+B,GAAG,WAAW,CAAC;AACpD,MAAM,qBAAqB,GAAG,yBAAyB,+BAA+B,EAAE,CAAC;AAEzF;;GAEG;AACH,MAAa,iBACX,SAAQ,yCACqB;IAE7B,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,OAAO,EACZ,mBAAY,CAAC,uBAAuB,CAClC,IAAA,aAAM,GAAE,CAAC,iCAAiC,CAC3C,CACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAqB;QAC3B,OAAO,IAAA,kDAA+B,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,aAAa,CAAC,MAAkC;QAC9C,OAAO,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YACnC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,IAAA,aAAM,GAAE,CAAC,kCAAkC,CAAC,MAAM,GAAG,CAAC;gBACtD,CAAC,CAAC,IAAA,gDAA2B,EAAC,IAAA,aAAM,GAAE,CAAC,kCAAkC,EAAE,+BAA+B,CAAC;gBAC3G,CAAC,CAAC,IAAA,aAAM,GAAE,CAAC,2BAA2B,CAAC,MAAM,GAAG,CAAC;oBAC/C,CAAC,CAAC,IAAA,4CAAuB,EAAC,IAAA,aAAM,GAAE,CAAC,2BAA2B,EAAE,+BAA+B,CAAC;oBAChG,CAAC,CAAC,qBAAqB,CAAC;IAChC,CAAC;CACF;AA3BD,8CA2BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';\nimport {\n OTLPExporterNodeConfigBase,\n appendResourcePathToUrl,\n appendRootPathToUrlIfNeeded\n} from '@opentelemetry/otlp-exporter-base';\nimport { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';\n\nconst DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';\nconst DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;\n\n/**\n * Collector Trace Exporter for Node\n */\nexport class OTLPTraceExporter\n extends OTLPExporterNodeBase<ReadableSpan,\n IExportTraceServiceRequest>\n implements SpanExporter {\n constructor(config: OTLPExporterNodeConfigBase = {}) {\n super(config);\n this.headers = Object.assign(\n this.headers,\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS\n )\n );\n }\n\n convert(spans: ReadableSpan[]): IExportTraceServiceRequest {\n return createExportTraceServiceRequest(spans, true);\n }\n\n getDefaultUrl(config: OTLPExporterNodeConfigBase): string {\n return typeof config.url === 'string'\n ? config.url\n : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0\n ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)\n : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0\n ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)\n : DEFAULT_COLLECTOR_URL;\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.29.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.29.0';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/exporter-trace-otlp-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "OpenTelemetry Collector Trace Exporter allows user to send collected traces to the OpenTelemetry Collector",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"rimraf": "3.0.2",
|
|
85
85
|
"sinon": "12.0.1",
|
|
86
86
|
"ts-loader": "8.3.0",
|
|
87
|
-
"ts-mocha": "
|
|
87
|
+
"ts-mocha": "9.0.2",
|
|
88
88
|
"typescript": "4.4.4",
|
|
89
89
|
"webpack": "4.46.0",
|
|
90
90
|
"webpack-cli": "4.9.1",
|
|
@@ -94,10 +94,11 @@
|
|
|
94
94
|
"@opentelemetry/api": "^1.0.0"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@opentelemetry/core": "1.
|
|
98
|
-
"@opentelemetry/otlp-exporter-base": "0.
|
|
99
|
-
"@opentelemetry/
|
|
100
|
-
"@opentelemetry/
|
|
97
|
+
"@opentelemetry/core": "1.3.0",
|
|
98
|
+
"@opentelemetry/otlp-exporter-base": "0.29.0",
|
|
99
|
+
"@opentelemetry/otlp-transformer": "0.29.0",
|
|
100
|
+
"@opentelemetry/resources": "1.3.0",
|
|
101
|
+
"@opentelemetry/sdk-trace-base": "1.3.0"
|
|
101
102
|
},
|
|
102
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "eda0b092db484855ded8b4837ba7fc19a377c5a7"
|
|
103
104
|
}
|
package/build/esm/transform.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { SpanAttributes, SpanKind, SpanStatus, TraceState } from '@opentelemetry/api';
|
|
2
|
-
import * as core from '@opentelemetry/core';
|
|
3
|
-
import { Resource } from '@opentelemetry/resources';
|
|
4
|
-
import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
|
|
5
|
-
import { opentelemetryProto } from './types';
|
|
6
|
-
import { OTLPExporterBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
|
|
7
|
-
/**
|
|
8
|
-
* Converts attributes to KeyValue array
|
|
9
|
-
* @param attributes
|
|
10
|
-
*/
|
|
11
|
-
export declare function toCollectorAttributes(attributes: SpanAttributes): opentelemetryProto.common.v1.KeyValue[];
|
|
12
|
-
/**
|
|
13
|
-
* Converts array of unknown value to ArrayValue
|
|
14
|
-
* @param values
|
|
15
|
-
*/
|
|
16
|
-
export declare function toCollectorArrayValue(values: unknown[]): opentelemetryProto.common.v1.ArrayValue;
|
|
17
|
-
/**
|
|
18
|
-
* Converts attributes to KeyValueList
|
|
19
|
-
* @param attributes
|
|
20
|
-
*/
|
|
21
|
-
export declare function toCollectorKeyValueList(attributes: SpanAttributes): opentelemetryProto.common.v1.KeyValueList;
|
|
22
|
-
/**
|
|
23
|
-
* Converts key and unknown value to KeyValue
|
|
24
|
-
* @param value event value
|
|
25
|
-
*/
|
|
26
|
-
export declare function toCollectorAttributeKeyValue(key: string, value: unknown): opentelemetryProto.common.v1.KeyValue;
|
|
27
|
-
/**
|
|
28
|
-
* Converts unknown value to AnyValue
|
|
29
|
-
* @param value
|
|
30
|
-
*/
|
|
31
|
-
export declare function toCollectorAnyValue(value: unknown): opentelemetryProto.common.v1.AnyValue;
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* Converts events
|
|
35
|
-
* @param events array of events
|
|
36
|
-
*/
|
|
37
|
-
export declare function toCollectorEvents(timedEvents: TimedEvent[]): opentelemetryProto.trace.v1.Span.Event[];
|
|
38
|
-
/**
|
|
39
|
-
* Converts span
|
|
40
|
-
* @param span
|
|
41
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
42
|
-
*/
|
|
43
|
-
export declare function toCollectorSpan(span: ReadableSpan, useHex?: boolean): opentelemetryProto.trace.v1.Span;
|
|
44
|
-
/**
|
|
45
|
-
* Converts status
|
|
46
|
-
* @param status
|
|
47
|
-
*/
|
|
48
|
-
export declare function toCollectorStatus(status: SpanStatus): opentelemetryProto.trace.v1.SpanStatus;
|
|
49
|
-
/**
|
|
50
|
-
* Converts resource
|
|
51
|
-
* @param resource
|
|
52
|
-
* @param additionalAttributes
|
|
53
|
-
*/
|
|
54
|
-
export declare function toCollectorResource(resource?: Resource, additionalAttributes?: {
|
|
55
|
-
[key: string]: unknown;
|
|
56
|
-
}): opentelemetryProto.resource.v1.Resource;
|
|
57
|
-
/**
|
|
58
|
-
* Converts span kind
|
|
59
|
-
* @param kind
|
|
60
|
-
*/
|
|
61
|
-
export declare function toCollectorKind(kind: SpanKind): opentelemetryProto.trace.v1.Span.SpanKind;
|
|
62
|
-
/**
|
|
63
|
-
* Converts traceState
|
|
64
|
-
* @param traceState
|
|
65
|
-
*/
|
|
66
|
-
export declare function toCollectorTraceState(traceState?: TraceState): opentelemetryProto.trace.v1.Span.TraceState | undefined;
|
|
67
|
-
/**
|
|
68
|
-
* Prepares trace service request to be sent to collector
|
|
69
|
-
* @param spans spans
|
|
70
|
-
* @param collectorExporterBase
|
|
71
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
72
|
-
*/
|
|
73
|
-
export declare function toOTLPExportTraceServiceRequest<T extends OTLPExporterConfigBase>(spans: ReadableSpan[], collectorTraceExporterBase: OTLPExporterBase<T, ReadableSpan, opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>, useHex?: boolean): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest;
|
|
74
|
-
/**
|
|
75
|
-
* Takes an array of spans and groups them by resource and instrumentation
|
|
76
|
-
* library
|
|
77
|
-
* @param spans spans
|
|
78
|
-
*/
|
|
79
|
-
export declare function groupSpansByResourceAndLibrary(spans: ReadableSpan[]): Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>;
|
|
80
|
-
//# sourceMappingURL=transform.d.ts.map
|
package/build/esm/transform.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
17
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18
|
-
if (!m) return o;
|
|
19
|
-
var i = m.call(o), r, ar = [], e;
|
|
20
|
-
try {
|
|
21
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
22
|
-
}
|
|
23
|
-
catch (error) { e = { error: error }; }
|
|
24
|
-
finally {
|
|
25
|
-
try {
|
|
26
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
27
|
-
}
|
|
28
|
-
finally { if (e) throw e.error; }
|
|
29
|
-
}
|
|
30
|
-
return ar;
|
|
31
|
-
};
|
|
32
|
-
import * as core from '@opentelemetry/core';
|
|
33
|
-
import { OTLP_SPAN_KIND_MAPPING, opentelemetryProto, } from './types';
|
|
34
|
-
var MAX_INTEGER_VALUE = 2147483647;
|
|
35
|
-
var MIN_INTEGER_VALUE = -2147483648;
|
|
36
|
-
/**
|
|
37
|
-
* Converts attributes to KeyValue array
|
|
38
|
-
* @param attributes
|
|
39
|
-
*/
|
|
40
|
-
export function toCollectorAttributes(attributes) {
|
|
41
|
-
return Object.keys(attributes).map(function (key) {
|
|
42
|
-
return toCollectorAttributeKeyValue(key, attributes[key]);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Converts array of unknown value to ArrayValue
|
|
47
|
-
* @param values
|
|
48
|
-
*/
|
|
49
|
-
export function toCollectorArrayValue(values) {
|
|
50
|
-
return {
|
|
51
|
-
values: values.map(function (value) { return toCollectorAnyValue(value); }),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Converts attributes to KeyValueList
|
|
56
|
-
* @param attributes
|
|
57
|
-
*/
|
|
58
|
-
export function toCollectorKeyValueList(attributes) {
|
|
59
|
-
return {
|
|
60
|
-
values: toCollectorAttributes(attributes),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Converts key and unknown value to KeyValue
|
|
65
|
-
* @param value event value
|
|
66
|
-
*/
|
|
67
|
-
export function toCollectorAttributeKeyValue(key, value) {
|
|
68
|
-
var anyValue = toCollectorAnyValue(value);
|
|
69
|
-
return {
|
|
70
|
-
key: key,
|
|
71
|
-
value: anyValue,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Converts unknown value to AnyValue
|
|
76
|
-
* @param value
|
|
77
|
-
*/
|
|
78
|
-
export function toCollectorAnyValue(value) {
|
|
79
|
-
var anyValue = {};
|
|
80
|
-
if (typeof value === 'string') {
|
|
81
|
-
anyValue.stringValue = value;
|
|
82
|
-
}
|
|
83
|
-
else if (typeof value === 'boolean') {
|
|
84
|
-
anyValue.boolValue = value;
|
|
85
|
-
}
|
|
86
|
-
else if (typeof value === 'number' &&
|
|
87
|
-
value <= MAX_INTEGER_VALUE &&
|
|
88
|
-
value >= MIN_INTEGER_VALUE &&
|
|
89
|
-
Number.isInteger(value)) {
|
|
90
|
-
anyValue.intValue = value;
|
|
91
|
-
}
|
|
92
|
-
else if (typeof value === 'number') {
|
|
93
|
-
anyValue.doubleValue = value;
|
|
94
|
-
}
|
|
95
|
-
else if (Array.isArray(value)) {
|
|
96
|
-
anyValue.arrayValue = toCollectorArrayValue(value);
|
|
97
|
-
}
|
|
98
|
-
else if (value) {
|
|
99
|
-
anyValue.kvlistValue = toCollectorKeyValueList(value);
|
|
100
|
-
}
|
|
101
|
-
return anyValue;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
* Converts events
|
|
106
|
-
* @param events array of events
|
|
107
|
-
*/
|
|
108
|
-
export function toCollectorEvents(timedEvents) {
|
|
109
|
-
return timedEvents.map(function (timedEvent) {
|
|
110
|
-
var timeUnixNano = core.hrTimeToNanoseconds(timedEvent.time);
|
|
111
|
-
var name = timedEvent.name;
|
|
112
|
-
var attributes = toCollectorAttributes(timedEvent.attributes || {});
|
|
113
|
-
var droppedAttributesCount = 0;
|
|
114
|
-
var protoEvent = {
|
|
115
|
-
timeUnixNano: timeUnixNano,
|
|
116
|
-
name: name,
|
|
117
|
-
attributes: attributes,
|
|
118
|
-
droppedAttributesCount: droppedAttributesCount,
|
|
119
|
-
};
|
|
120
|
-
return protoEvent;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Converts links
|
|
125
|
-
* @param span
|
|
126
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
127
|
-
*/
|
|
128
|
-
function toCollectorLinks(span, useHex) {
|
|
129
|
-
return span.links.map(function (link) {
|
|
130
|
-
var protoLink = {
|
|
131
|
-
traceId: useHex
|
|
132
|
-
? link.context.traceId
|
|
133
|
-
: core.hexToBase64(link.context.traceId),
|
|
134
|
-
spanId: useHex
|
|
135
|
-
? link.context.spanId
|
|
136
|
-
: core.hexToBase64(link.context.spanId),
|
|
137
|
-
attributes: toCollectorAttributes(link.attributes || {}),
|
|
138
|
-
droppedAttributesCount: 0,
|
|
139
|
-
};
|
|
140
|
-
return protoLink;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Converts span
|
|
145
|
-
* @param span
|
|
146
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
147
|
-
*/
|
|
148
|
-
export function toCollectorSpan(span, useHex) {
|
|
149
|
-
return {
|
|
150
|
-
traceId: useHex
|
|
151
|
-
? span.spanContext().traceId
|
|
152
|
-
: core.hexToBase64(span.spanContext().traceId),
|
|
153
|
-
spanId: useHex
|
|
154
|
-
? span.spanContext().spanId
|
|
155
|
-
: core.hexToBase64(span.spanContext().spanId),
|
|
156
|
-
parentSpanId: span.parentSpanId
|
|
157
|
-
? useHex
|
|
158
|
-
? span.parentSpanId
|
|
159
|
-
: core.hexToBase64(span.parentSpanId)
|
|
160
|
-
: undefined,
|
|
161
|
-
traceState: toCollectorTraceState(span.spanContext().traceState),
|
|
162
|
-
name: span.name,
|
|
163
|
-
kind: toCollectorKind(span.kind),
|
|
164
|
-
startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),
|
|
165
|
-
endTimeUnixNano: core.hrTimeToNanoseconds(span.endTime),
|
|
166
|
-
attributes: toCollectorAttributes(span.attributes),
|
|
167
|
-
droppedAttributesCount: 0,
|
|
168
|
-
events: toCollectorEvents(span.events),
|
|
169
|
-
droppedEventsCount: 0,
|
|
170
|
-
status: toCollectorStatus(span.status),
|
|
171
|
-
links: toCollectorLinks(span, useHex),
|
|
172
|
-
droppedLinksCount: 0,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Converts status
|
|
177
|
-
* @param status
|
|
178
|
-
*/
|
|
179
|
-
export function toCollectorStatus(status) {
|
|
180
|
-
var spanStatus = {
|
|
181
|
-
code: status.code,
|
|
182
|
-
};
|
|
183
|
-
if (typeof status.message !== 'undefined') {
|
|
184
|
-
spanStatus.message = status.message;
|
|
185
|
-
}
|
|
186
|
-
return spanStatus;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Converts resource
|
|
190
|
-
* @param resource
|
|
191
|
-
* @param additionalAttributes
|
|
192
|
-
*/
|
|
193
|
-
export function toCollectorResource(resource, additionalAttributes) {
|
|
194
|
-
if (additionalAttributes === void 0) { additionalAttributes = {}; }
|
|
195
|
-
var attr = Object.assign({}, additionalAttributes, resource ? resource.attributes : {});
|
|
196
|
-
var resourceProto = {
|
|
197
|
-
attributes: toCollectorAttributes(attr),
|
|
198
|
-
droppedAttributesCount: 0,
|
|
199
|
-
};
|
|
200
|
-
return resourceProto;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Converts span kind
|
|
204
|
-
* @param kind
|
|
205
|
-
*/
|
|
206
|
-
export function toCollectorKind(kind) {
|
|
207
|
-
var collectorKind = OTLP_SPAN_KIND_MAPPING[kind];
|
|
208
|
-
return typeof collectorKind === 'number'
|
|
209
|
-
? collectorKind
|
|
210
|
-
: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_UNSPECIFIED;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Converts traceState
|
|
214
|
-
* @param traceState
|
|
215
|
-
*/
|
|
216
|
-
export function toCollectorTraceState(traceState) {
|
|
217
|
-
if (!traceState)
|
|
218
|
-
return undefined;
|
|
219
|
-
return traceState.serialize();
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Prepares trace service request to be sent to collector
|
|
223
|
-
* @param spans spans
|
|
224
|
-
* @param collectorExporterBase
|
|
225
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
226
|
-
*/
|
|
227
|
-
export function toOTLPExportTraceServiceRequest(spans, collectorTraceExporterBase, useHex) {
|
|
228
|
-
var groupedSpans = groupSpansByResourceAndLibrary(spans);
|
|
229
|
-
var additionalAttributes = Object.assign({}, collectorTraceExporterBase.attributes);
|
|
230
|
-
return {
|
|
231
|
-
resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes, useHex),
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Takes an array of spans and groups them by resource and instrumentation
|
|
236
|
-
* library
|
|
237
|
-
* @param spans spans
|
|
238
|
-
*/
|
|
239
|
-
export function groupSpansByResourceAndLibrary(spans) {
|
|
240
|
-
return spans.reduce(function (spanMap, span) {
|
|
241
|
-
//group by resource
|
|
242
|
-
var resourceSpans = spanMap.get(span.resource);
|
|
243
|
-
if (!resourceSpans) {
|
|
244
|
-
resourceSpans = new Map();
|
|
245
|
-
spanMap.set(span.resource, resourceSpans);
|
|
246
|
-
}
|
|
247
|
-
//group by instrumentation library
|
|
248
|
-
var libSpans = resourceSpans.get(span.instrumentationLibrary);
|
|
249
|
-
if (!libSpans) {
|
|
250
|
-
libSpans = new Array();
|
|
251
|
-
resourceSpans.set(span.instrumentationLibrary, libSpans);
|
|
252
|
-
}
|
|
253
|
-
libSpans.push(span);
|
|
254
|
-
return spanMap;
|
|
255
|
-
}, new Map());
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Convert to InstrumentationLibrarySpans
|
|
259
|
-
* @param instrumentationLibrary
|
|
260
|
-
* @param spans
|
|
261
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
262
|
-
*/
|
|
263
|
-
function toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex) {
|
|
264
|
-
return {
|
|
265
|
-
spans: spans.map(function (span) { return toCollectorSpan(span, useHex); }),
|
|
266
|
-
instrumentationLibrary: instrumentationLibrary,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Returns a list of resource spans which will be exported to the collector
|
|
271
|
-
* @param groupedSpans
|
|
272
|
-
* @param baseAttributes
|
|
273
|
-
* @param useHex - if ids should be kept as hex without converting to base64
|
|
274
|
-
*/
|
|
275
|
-
function toCollectorResourceSpans(groupedSpans, baseAttributes, useHex) {
|
|
276
|
-
return Array.from(groupedSpans, function (_a) {
|
|
277
|
-
var _b = __read(_a, 2), resource = _b[0], libSpans = _b[1];
|
|
278
|
-
return {
|
|
279
|
-
resource: toCollectorResource(resource, baseAttributes),
|
|
280
|
-
instrumentationLibrarySpans: Array.from(libSpans, function (_a) {
|
|
281
|
-
var _b = __read(_a, 2), instrumentationLibrary = _b[0], spans = _b[1];
|
|
282
|
-
return toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex);
|
|
283
|
-
}),
|
|
284
|
-
};
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AASH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,IAAM,iBAAiB,GAAG,UAAU,CAAC;AACrC,IAAM,iBAAiB,GAAG,CAAC,UAAU,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAA0B;IAE1B,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QACpC,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAA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AAM,CAAC,EAA7B,CAA6B,CAAC;QACvD,sBAAsB,wBAAA;KACvB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAC/B,YAA6E,EAC7E,cAA8B,EAC9B,MAAgB;IAEhB,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,UAAC,EAAoB;YAApB,KAAA,aAAoB,EAAnB,QAAQ,QAAA,EAAE,QAAQ,QAAA;QAClD,OAAO;YACL,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE,cAAc,CAAC;YACvD,2BAA2B,EAAE,KAAK,CAAC,IAAI,CACrC,QAAQ,EACR,UAAC,EAA+B;oBAA/B,KAAA,aAA+B,EAA9B,sBAAsB,QAAA,EAAE,KAAK,QAAA;gBAC7B,OAAA,sCAAsC,CACpC,sBAAsB,EACtB,KAAK,EACL,MAAM,CACP;YAJD,CAIC,CACJ;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SpanAttributes,\n Link,\n SpanKind,\n SpanStatus,\n TraceState,\n} from '@opentelemetry/api';\nimport * as core from '@opentelemetry/core';\nimport { Resource } from '@opentelemetry/resources';\nimport { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';\nimport {\n OTLP_SPAN_KIND_MAPPING,\n opentelemetryProto,\n} from './types';\nimport { OTLPExporterBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';\n\nconst MAX_INTEGER_VALUE = 2147483647;\nconst MIN_INTEGER_VALUE = -2147483648;\n\n/**\n * Converts attributes to KeyValue array\n * @param attributes\n */\nexport function toCollectorAttributes(\n attributes: SpanAttributes\n): opentelemetryProto.common.v1.KeyValue[] {\n return Object.keys(attributes).map(key => {\n return toCollectorAttributeKeyValue(key, attributes[key]);\n });\n}\n\n/**\n * Converts array of unknown value to ArrayValue\n * @param values\n */\nexport function toCollectorArrayValue(\n values: unknown[]\n): opentelemetryProto.common.v1.ArrayValue {\n return {\n values: values.map(value => toCollectorAnyValue(value)),\n };\n}\n\n/**\n * Converts attributes to KeyValueList\n * @param attributes\n */\nexport function toCollectorKeyValueList(\n attributes: SpanAttributes\n): opentelemetryProto.common.v1.KeyValueList {\n return {\n values: toCollectorAttributes(attributes),\n };\n}\n\n/**\n * Converts key and unknown value to KeyValue\n * @param value event value\n */\nexport function toCollectorAttributeKeyValue(\n key: string,\n value: unknown\n): opentelemetryProto.common.v1.KeyValue {\n const anyValue = toCollectorAnyValue(value);\n return {\n key,\n value: anyValue,\n };\n}\n\n/**\n * Converts unknown value to AnyValue\n * @param value\n */\nexport function toCollectorAnyValue(\n value: unknown\n): opentelemetryProto.common.v1.AnyValue {\n const anyValue: opentelemetryProto.common.v1.AnyValue = {};\n if (typeof value === 'string') {\n anyValue.stringValue = value;\n } else if (typeof value === 'boolean') {\n anyValue.boolValue = value;\n } else if (\n typeof value === 'number' &&\n value <= MAX_INTEGER_VALUE &&\n value >= MIN_INTEGER_VALUE &&\n Number.isInteger(value)\n ) {\n anyValue.intValue = value;\n } else if (typeof value === 'number') {\n anyValue.doubleValue = value;\n } else if (Array.isArray(value)) {\n anyValue.arrayValue = toCollectorArrayValue(value);\n } else if (value) {\n anyValue.kvlistValue = toCollectorKeyValueList(value as SpanAttributes);\n }\n return anyValue;\n}\n\n/**\n *\n * Converts events\n * @param events array of events\n */\nexport function toCollectorEvents(\n timedEvents: TimedEvent[]\n): opentelemetryProto.trace.v1.Span.Event[] {\n return timedEvents.map(timedEvent => {\n const timeUnixNano = core.hrTimeToNanoseconds(timedEvent.time);\n const name = timedEvent.name;\n const attributes = toCollectorAttributes(timedEvent.attributes || {});\n const droppedAttributesCount = 0;\n\n const protoEvent: opentelemetryProto.trace.v1.Span.Event = {\n timeUnixNano,\n name,\n attributes,\n droppedAttributesCount,\n };\n\n return protoEvent;\n });\n}\n\n/**\n * Converts links\n * @param span\n * @param useHex - if ids should be kept as hex without converting to base64\n */\nfunction toCollectorLinks(\n span: ReadableSpan,\n useHex?: boolean\n): opentelemetryProto.trace.v1.Span.Link[] {\n return span.links.map((link: Link) => {\n const protoLink: opentelemetryProto.trace.v1.Span.Link = {\n traceId: useHex\n ? link.context.traceId\n : core.hexToBase64(link.context.traceId),\n spanId: useHex\n ? link.context.spanId\n : core.hexToBase64(link.context.spanId),\n attributes: toCollectorAttributes(link.attributes || {}),\n droppedAttributesCount: 0,\n };\n return protoLink;\n });\n}\n\n/**\n * Converts span\n * @param span\n * @param useHex - if ids should be kept as hex without converting to base64\n */\nexport function toCollectorSpan(\n span: ReadableSpan,\n useHex?: boolean\n): opentelemetryProto.trace.v1.Span {\n return {\n traceId: useHex\n ? span.spanContext().traceId\n : core.hexToBase64(span.spanContext().traceId),\n spanId: useHex\n ? span.spanContext().spanId\n : core.hexToBase64(span.spanContext().spanId),\n parentSpanId: span.parentSpanId\n ? useHex\n ? span.parentSpanId\n : core.hexToBase64(span.parentSpanId)\n : undefined,\n traceState: toCollectorTraceState(span.spanContext().traceState),\n name: span.name,\n kind: toCollectorKind(span.kind),\n startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),\n endTimeUnixNano: core.hrTimeToNanoseconds(span.endTime),\n attributes: toCollectorAttributes(span.attributes),\n droppedAttributesCount: 0,\n events: toCollectorEvents(span.events),\n droppedEventsCount: 0,\n status: toCollectorStatus(span.status),\n links: toCollectorLinks(span, useHex),\n droppedLinksCount: 0,\n };\n}\n\n/**\n * Converts status\n * @param status\n */\nexport function toCollectorStatus(\n status: SpanStatus\n): opentelemetryProto.trace.v1.SpanStatus {\n const spanStatus: opentelemetryProto.trace.v1.SpanStatus = {\n code: status.code,\n };\n if (typeof status.message !== 'undefined') {\n spanStatus.message = status.message;\n }\n return spanStatus;\n}\n\n/**\n * Converts resource\n * @param resource\n * @param additionalAttributes\n */\nexport function toCollectorResource(\n resource?: Resource,\n additionalAttributes: { [key: string]: unknown } = {}\n): opentelemetryProto.resource.v1.Resource {\n const attr = Object.assign(\n {},\n additionalAttributes,\n resource ? resource.attributes : {}\n );\n const resourceProto: opentelemetryProto.resource.v1.Resource = {\n attributes: toCollectorAttributes(attr),\n droppedAttributesCount: 0,\n };\n\n return resourceProto;\n}\n\n/**\n * Converts span kind\n * @param kind\n */\nexport function toCollectorKind(\n kind: SpanKind\n): opentelemetryProto.trace.v1.Span.SpanKind {\n const collectorKind = OTLP_SPAN_KIND_MAPPING[kind];\n return typeof collectorKind === 'number'\n ? collectorKind\n : opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_UNSPECIFIED;\n}\n\n/**\n * Converts traceState\n * @param traceState\n */\nexport function toCollectorTraceState(\n traceState?: TraceState\n): opentelemetryProto.trace.v1.Span.TraceState | undefined {\n if (!traceState) return undefined;\n return traceState.serialize();\n}\n\n/**\n * Prepares trace service request to be sent to collector\n * @param spans spans\n * @param collectorExporterBase\n * @param useHex - if ids should be kept as hex without converting to base64\n */\nexport function toOTLPExportTraceServiceRequest<\n T extends OTLPExporterConfigBase\n>(\n spans: ReadableSpan[],\n collectorTraceExporterBase: OTLPExporterBase<\n T,\n ReadableSpan,\n opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest\n >,\n useHex?: boolean\n): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {\n const groupedSpans: Map<\n Resource,\n Map<core.InstrumentationLibrary, ReadableSpan[]>\n > = groupSpansByResourceAndLibrary(spans);\n\n const additionalAttributes = Object.assign(\n {},\n collectorTraceExporterBase.attributes\n );\n\n return {\n resourceSpans: toCollectorResourceSpans(\n groupedSpans,\n additionalAttributes,\n useHex\n ),\n };\n}\n\n/**\n * Takes an array of spans and groups them by resource and instrumentation\n * library\n * @param spans spans\n */\nexport function groupSpansByResourceAndLibrary(\n spans: ReadableSpan[]\n): Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>> {\n return spans.reduce((spanMap, span) => {\n //group by resource\n let resourceSpans = spanMap.get(span.resource);\n if (!resourceSpans) {\n resourceSpans = new Map<core.InstrumentationLibrary, ReadableSpan[]>();\n spanMap.set(span.resource, resourceSpans);\n }\n //group by instrumentation library\n let libSpans = resourceSpans.get(span.instrumentationLibrary);\n if (!libSpans) {\n libSpans = new Array<ReadableSpan>();\n resourceSpans.set(span.instrumentationLibrary, libSpans);\n }\n libSpans.push(span);\n return spanMap;\n }, new Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>());\n}\n\n/**\n * Convert to InstrumentationLibrarySpans\n * @param instrumentationLibrary\n * @param spans\n * @param useHex - if ids should be kept as hex without converting to base64\n */\nfunction toCollectorInstrumentationLibrarySpans(\n instrumentationLibrary: core.InstrumentationLibrary,\n spans: ReadableSpan[],\n useHex?: boolean\n): opentelemetryProto.trace.v1.InstrumentationLibrarySpans {\n return {\n spans: spans.map(span => toCollectorSpan(span, useHex)),\n instrumentationLibrary,\n };\n}\n\n/**\n * Returns a list of resource spans which will be exported to the collector\n * @param groupedSpans\n * @param baseAttributes\n * @param useHex - if ids should be kept as hex without converting to base64\n */\nfunction toCollectorResourceSpans(\n groupedSpans: Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>,\n baseAttributes: SpanAttributes,\n useHex?: boolean\n): opentelemetryProto.trace.v1.ResourceSpans[] {\n return Array.from(groupedSpans, ([resource, libSpans]) => {\n return {\n resource: toCollectorResource(resource, baseAttributes),\n instrumentationLibrarySpans: Array.from(\n libSpans,\n ([instrumentationLibrary, spans]) =>\n toCollectorInstrumentationLibrarySpans(\n instrumentationLibrary,\n spans,\n useHex\n )\n ),\n };\n });\n}\n"]}
|