@opentelemetry/exporter-trace-otlp-http 0.27.0 → 0.28.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.
Files changed (124) hide show
  1. package/README.md +3 -9
  2. package/build/esm/index.d.ts +0 -2
  3. package/build/esm/index.js +0 -2
  4. package/build/esm/index.js.map +1 -1
  5. package/build/esm/platform/browser/OTLPTraceExporter.d.ts +2 -2
  6. package/build/esm/platform/browser/OTLPTraceExporter.js +2 -3
  7. package/build/esm/platform/browser/OTLPTraceExporter.js.map +1 -1
  8. package/build/esm/platform/browser/index.d.ts +0 -1
  9. package/build/esm/platform/browser/index.js +0 -1
  10. package/build/esm/platform/browser/index.js.map +1 -1
  11. package/build/esm/platform/index.d.ts +0 -1
  12. package/build/esm/platform/index.js +0 -1
  13. package/build/esm/platform/index.js.map +1 -1
  14. package/build/esm/platform/node/OTLPTraceExporter.d.ts +2 -2
  15. package/build/esm/platform/node/OTLPTraceExporter.js +3 -3
  16. package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
  17. package/build/esm/platform/node/index.d.ts +0 -3
  18. package/build/esm/platform/node/index.js +0 -3
  19. package/build/esm/platform/node/index.js.map +1 -1
  20. package/build/esm/transform.d.ts +2 -2
  21. package/build/esm/transform.js +18 -2
  22. package/build/esm/transform.js.map +1 -1
  23. package/build/esm/types.d.ts +1 -33
  24. package/build/esm/types.js +0 -30
  25. package/build/esm/types.js.map +1 -1
  26. package/build/esm/version.d.ts +1 -1
  27. package/build/esm/version.js +1 -1
  28. package/build/esm/version.js.map +1 -1
  29. package/build/esnext/index.d.ts +4 -0
  30. package/build/esnext/index.js +19 -0
  31. package/build/esnext/index.js.map +1 -0
  32. package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +13 -0
  33. package/build/esnext/platform/browser/OTLPTraceExporter.js +42 -0
  34. package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -0
  35. package/build/esnext/platform/browser/index.d.ts +2 -0
  36. package/build/esnext/platform/browser/index.js +17 -0
  37. package/build/esnext/platform/browser/index.js.map +1 -0
  38. package/build/esnext/platform/index.d.ts +2 -0
  39. package/build/esnext/platform/index.js +17 -0
  40. package/build/esnext/platform/index.js.map +1 -0
  41. package/build/esnext/platform/node/OTLPTraceExporter.d.ts +13 -0
  42. package/build/esnext/platform/node/OTLPTraceExporter.js +43 -0
  43. package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -0
  44. package/build/esnext/platform/node/index.d.ts +2 -0
  45. package/build/esnext/platform/node/index.js +17 -0
  46. package/build/esnext/platform/node/index.js.map +1 -0
  47. package/build/esnext/transform.d.ts +80 -0
  48. package/build/esnext/transform.js +266 -0
  49. package/build/esnext/transform.js.map +1 -0
  50. package/build/esnext/types.d.ts +209 -0
  51. package/build/esnext/types.js +145 -0
  52. package/build/esnext/types.js.map +1 -0
  53. package/build/esnext/version.d.ts +2 -0
  54. package/build/esnext/version.js +18 -0
  55. package/build/esnext/version.js.map +1 -0
  56. package/build/src/index.d.ts +0 -2
  57. package/build/src/index.js +1 -4
  58. package/build/src/index.js.map +1 -1
  59. package/build/src/platform/browser/OTLPTraceExporter.d.ts +2 -2
  60. package/build/src/platform/browser/OTLPTraceExporter.js +9 -10
  61. package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
  62. package/build/src/platform/browser/index.d.ts +0 -1
  63. package/build/src/platform/browser/index.js +0 -1
  64. package/build/src/platform/browser/index.js.map +1 -1
  65. package/build/src/platform/index.d.ts +0 -1
  66. package/build/src/platform/index.js +0 -3
  67. package/build/src/platform/index.js.map +1 -1
  68. package/build/src/platform/node/OTLPTraceExporter.d.ts +2 -2
  69. package/build/src/platform/node/OTLPTraceExporter.js +10 -10
  70. package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
  71. package/build/src/platform/node/index.d.ts +0 -3
  72. package/build/src/platform/node/index.js +0 -3
  73. package/build/src/platform/node/index.js.map +1 -1
  74. package/build/src/transform.d.ts +2 -2
  75. package/build/src/transform.js.map +1 -1
  76. package/build/src/types.d.ts +1 -33
  77. package/build/src/types.js +1 -13
  78. package/build/src/types.js.map +1 -1
  79. package/build/src/version.d.ts +1 -1
  80. package/build/src/version.js +1 -1
  81. package/build/src/version.js.map +1 -1
  82. package/package.json +30 -21
  83. package/build/esm/OTLPExporterBase.d.ts +0 -36
  84. package/build/esm/OTLPExporterBase.js +0 -114
  85. package/build/esm/OTLPExporterBase.js.map +0 -1
  86. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  87. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +0 -91
  88. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  89. package/build/esm/platform/browser/util.d.ts +0 -17
  90. package/build/esm/platform/browser/util.js +0 -77
  91. package/build/esm/platform/browser/util.js.map +0 -1
  92. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  93. package/build/esm/platform/node/OTLPExporterNodeBase.js +0 -82
  94. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +0 -1
  95. package/build/esm/platform/node/types.d.ts +0 -17
  96. package/build/esm/platform/node/types.js +0 -6
  97. package/build/esm/platform/node/types.js.map +0 -1
  98. package/build/esm/platform/node/util.d.ts +0 -17
  99. package/build/esm/platform/node/util.js +0 -113
  100. package/build/esm/platform/node/util.js.map +0 -1
  101. package/build/esm/util.d.ts +0 -7
  102. package/build/esm/util.js +0 -40
  103. package/build/esm/util.js.map +0 -1
  104. package/build/src/OTLPExporterBase.d.ts +0 -36
  105. package/build/src/OTLPExporterBase.js +0 -113
  106. package/build/src/OTLPExporterBase.js.map +0 -1
  107. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  108. package/build/src/platform/browser/OTLPExporterBrowserBase.js +0 -74
  109. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  110. package/build/src/platform/browser/util.d.ts +0 -17
  111. package/build/src/platform/browser/util.js +0 -70
  112. package/build/src/platform/browser/util.js.map +0 -1
  113. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  114. package/build/src/platform/node/OTLPExporterNodeBase.js +0 -65
  115. package/build/src/platform/node/OTLPExporterNodeBase.js.map +0 -1
  116. package/build/src/platform/node/types.d.ts +0 -17
  117. package/build/src/platform/node/types.js +0 -9
  118. package/build/src/platform/node/types.js.map +0 -1
  119. package/build/src/platform/node/util.d.ts +0 -17
  120. package/build/src/platform/node/util.js +0 -107
  121. package/build/src/platform/node/util.js.map +0 -1
  122. package/build/src/util.d.ts +0 -7
  123. package/build/src/util.js +0 -43
  124. package/build/src/util.js.map +0 -1
@@ -0,0 +1,42 @@
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 { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base';
17
+ import { toOTLPExportTraceServiceRequest } from '../../transform';
18
+ import { getEnv, baggageUtils } from '@opentelemetry/core';
19
+ const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
20
+ const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
21
+ /**
22
+ * Collector Trace Exporter for Web
23
+ */
24
+ export class OTLPTraceExporter extends OTLPExporterBrowserBase {
25
+ constructor(config = {}) {
26
+ super(config);
27
+ this._headers = Object.assign(this._headers, baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
28
+ }
29
+ convert(spans) {
30
+ return toOTLPExportTraceServiceRequest(spans, this, true);
31
+ }
32
+ getDefaultUrl(config) {
33
+ return typeof config.url === 'string'
34
+ ? config.url
35
+ : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
36
+ ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
37
+ : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
38
+ ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
39
+ : DEFAULT_COLLECTOR_URL;
40
+ }
41
+ }
42
+ //# sourceMappingURL=OTLPTraceExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTLPTraceExporter.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPTraceExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,mCAAmC,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAEjH,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,+BAA+B,GAAG,YAAY,CAAC;AACrD,MAAM,qBAAqB,GAAC,wBAAwB,+BAA+B,EAAE,CAAC;AAEtF;;GAEG;AACH,MAAM,OAAO,iBACX,SAAQ,uBAGP;IAED,YAAY,SAAiC,EAAE;QAC7C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAC3B,IAAI,CAAC,QAAQ,EACb,YAAY,CAAC,uBAAuB,CAClC,MAAM,EAAE,CAAC,iCAAiC,CAC3C,CACF,CAAC;IACJ,CAAC;IACD,OAAO,CACL,KAAqB;QAErB,OAAO,+BAA+B,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,aAAa,CAAC,MAA8B;QAC1C,OAAO,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YACnC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,MAAM,EAAE,CAAC,kCAAkC,CAAC,MAAM,GAAG,CAAC;gBACxD,CAAC,CAAC,MAAM,EAAE,CAAC,kCAAkC;gBAC7C,CAAC,CAAC,MAAM,EAAE,CAAC,2BAA2B,CAAC,MAAM,GAAG,CAAC;oBACjD,CAAC,CAAC,mCAAmC,CAAC,MAAM,EAAE,CAAC,2BAA2B,EAAE,+BAA+B,CAAC;oBAC5G,CAAC,CAAC,qBAAqB,CAAC;IAC5B,CAAC;CACF","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 { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base';\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { toOTLPExportTraceServiceRequest } from '../../transform';\nimport * as otlpTypes from '../../types';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';\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 Web\n */\nexport class OTLPTraceExporter\n extends OTLPExporterBrowserBase<\n ReadableSpan,\n otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest\n >\n implements SpanExporter {\n constructor(config: OTLPExporterConfigBase = {}) {\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 convert(\n spans: ReadableSpan[]\n ): otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {\n return toOTLPExportTraceServiceRequest(spans, this, true);\n }\n\n getDefaultUrl(config: OTLPExporterConfigBase): string {\n return typeof config.url === 'string'\n ? config.url\n : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0\n ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT\n : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0\n ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)\n : DEFAULT_COLLECTOR_URL;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './OTLPTraceExporter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
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
+ export * from './OTLPTraceExporter';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,qBAAqB,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\nexport * from './OTLPTraceExporter';\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './node';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
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
+ export * from './node';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,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\nexport * from './node';\n"]}
@@ -0,0 +1,13 @@
1
+ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
2
+ import * as otlpTypes from '../../types';
3
+ import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
4
+ import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
5
+ /**
6
+ * Collector Trace Exporter for Node
7
+ */
8
+ export declare class OTLPTraceExporter extends OTLPExporterNodeBase<ReadableSpan, otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest> implements SpanExporter {
9
+ constructor(config?: OTLPExporterNodeConfigBase);
10
+ convert(spans: ReadableSpan[]): otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest;
11
+ getDefaultUrl(config: OTLPExporterNodeConfigBase): string;
12
+ }
13
+ //# sourceMappingURL=OTLPTraceExporter.d.ts.map
@@ -0,0 +1,43 @@
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 { toOTLPExportTraceServiceRequest } from '../../transform';
17
+ import { getEnv, baggageUtils } from '@opentelemetry/core';
18
+ import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
19
+ import { appendResourcePathToUrlIfNotPresent } from '@opentelemetry/otlp-exporter-base';
20
+ const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
21
+ const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
22
+ /**
23
+ * Collector Trace Exporter for Node
24
+ */
25
+ export class OTLPTraceExporter extends OTLPExporterNodeBase {
26
+ constructor(config = {}) {
27
+ super(config);
28
+ this.headers = Object.assign(this.headers, baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS));
29
+ }
30
+ convert(spans) {
31
+ return toOTLPExportTraceServiceRequest(spans, this, true);
32
+ }
33
+ getDefaultUrl(config) {
34
+ return typeof config.url === 'string'
35
+ ? config.url
36
+ : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
37
+ ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
38
+ : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
39
+ ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
40
+ : DEFAULT_COLLECTOR_URL;
41
+ }
42
+ }
43
+ //# sourceMappingURL=OTLPTraceExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTLPTraceExporter.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPTraceExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAEL,mCAAmC,EACpC,MAAM,mCAAmC,CAAC;AAE3C,MAAM,+BAA+B,GAAG,YAAY,CAAC;AACrD,MAAM,qBAAqB,GAAG,wBAAwB,+BAA+B,EAAE,CAAC;AAExF;;GAEG;AACH,MAAM,OAAO,iBACX,SAAQ,oBACoE;IAE5E,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,OAAO,EACZ,YAAY,CAAC,uBAAuB,CAClC,MAAM,EAAE,CAAC,iCAAiC,CAC3C,CACF,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAqB;QAErB,OAAO,+BAA+B,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,aAAa,CAAC,MAAkC;QAC9C,OAAO,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YACnC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,MAAM,EAAE,CAAC,kCAAkC,CAAC,MAAM,GAAG,CAAC;gBACtD,CAAC,CAAC,MAAM,EAAE,CAAC,kCAAkC;gBAC7C,CAAC,CAAC,MAAM,EAAE,CAAC,2BAA2B,CAAC,MAAM,GAAG,CAAC;oBAC/C,CAAC,CAAC,mCAAmC,CAAC,MAAM,EAAE,CAAC,2BAA2B,EAAE,+BAA+B,CAAC;oBAC5G,CAAC,CAAC,qBAAqB,CAAC;IAChC,CAAC;CACF","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 * as otlpTypes from '../../types';\nimport { toOTLPExportTraceServiceRequest } from '../../transform';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';\nimport {\n OTLPExporterNodeConfigBase,\n appendResourcePathToUrlIfNotPresent\n} from '@opentelemetry/otlp-exporter-base';\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 otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>\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(\n spans: ReadableSpan[]\n ): otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {\n return toOTLPExportTraceServiceRequest(spans, this, 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 ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT\n : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0\n ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)\n : DEFAULT_COLLECTOR_URL;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './OTLPTraceExporter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
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
+ export * from './OTLPTraceExporter';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,qBAAqB,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\nexport * from './OTLPTraceExporter';\n"]}
@@ -0,0 +1,80 @@
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
@@ -0,0 +1,266 @@
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 * as core from '@opentelemetry/core';
17
+ import { OTLP_SPAN_KIND_MAPPING, opentelemetryProto, } from './types';
18
+ const MAX_INTEGER_VALUE = 2147483647;
19
+ const MIN_INTEGER_VALUE = -2147483648;
20
+ /**
21
+ * Converts attributes to KeyValue array
22
+ * @param attributes
23
+ */
24
+ export function toCollectorAttributes(attributes) {
25
+ return Object.keys(attributes).map(key => {
26
+ return toCollectorAttributeKeyValue(key, attributes[key]);
27
+ });
28
+ }
29
+ /**
30
+ * Converts array of unknown value to ArrayValue
31
+ * @param values
32
+ */
33
+ export function toCollectorArrayValue(values) {
34
+ return {
35
+ values: values.map(value => toCollectorAnyValue(value)),
36
+ };
37
+ }
38
+ /**
39
+ * Converts attributes to KeyValueList
40
+ * @param attributes
41
+ */
42
+ export function toCollectorKeyValueList(attributes) {
43
+ return {
44
+ values: toCollectorAttributes(attributes),
45
+ };
46
+ }
47
+ /**
48
+ * Converts key and unknown value to KeyValue
49
+ * @param value event value
50
+ */
51
+ export function toCollectorAttributeKeyValue(key, value) {
52
+ const anyValue = toCollectorAnyValue(value);
53
+ return {
54
+ key,
55
+ value: anyValue,
56
+ };
57
+ }
58
+ /**
59
+ * Converts unknown value to AnyValue
60
+ * @param value
61
+ */
62
+ export function toCollectorAnyValue(value) {
63
+ const anyValue = {};
64
+ if (typeof value === 'string') {
65
+ anyValue.stringValue = value;
66
+ }
67
+ else if (typeof value === 'boolean') {
68
+ anyValue.boolValue = value;
69
+ }
70
+ else if (typeof value === 'number' &&
71
+ value <= MAX_INTEGER_VALUE &&
72
+ value >= MIN_INTEGER_VALUE &&
73
+ Number.isInteger(value)) {
74
+ anyValue.intValue = value;
75
+ }
76
+ else if (typeof value === 'number') {
77
+ anyValue.doubleValue = value;
78
+ }
79
+ else if (Array.isArray(value)) {
80
+ anyValue.arrayValue = toCollectorArrayValue(value);
81
+ }
82
+ else if (value) {
83
+ anyValue.kvlistValue = toCollectorKeyValueList(value);
84
+ }
85
+ return anyValue;
86
+ }
87
+ /**
88
+ *
89
+ * Converts events
90
+ * @param events array of events
91
+ */
92
+ export function toCollectorEvents(timedEvents) {
93
+ return timedEvents.map(timedEvent => {
94
+ const timeUnixNano = core.hrTimeToNanoseconds(timedEvent.time);
95
+ const name = timedEvent.name;
96
+ const attributes = toCollectorAttributes(timedEvent.attributes || {});
97
+ const droppedAttributesCount = 0;
98
+ const protoEvent = {
99
+ timeUnixNano,
100
+ name,
101
+ attributes,
102
+ droppedAttributesCount,
103
+ };
104
+ return protoEvent;
105
+ });
106
+ }
107
+ /**
108
+ * Converts links
109
+ * @param span
110
+ * @param useHex - if ids should be kept as hex without converting to base64
111
+ */
112
+ function toCollectorLinks(span, useHex) {
113
+ return span.links.map((link) => {
114
+ const protoLink = {
115
+ traceId: useHex
116
+ ? link.context.traceId
117
+ : core.hexToBase64(link.context.traceId),
118
+ spanId: useHex
119
+ ? link.context.spanId
120
+ : core.hexToBase64(link.context.spanId),
121
+ attributes: toCollectorAttributes(link.attributes || {}),
122
+ droppedAttributesCount: 0,
123
+ };
124
+ return protoLink;
125
+ });
126
+ }
127
+ /**
128
+ * Converts span
129
+ * @param span
130
+ * @param useHex - if ids should be kept as hex without converting to base64
131
+ */
132
+ export function toCollectorSpan(span, useHex) {
133
+ return {
134
+ traceId: useHex
135
+ ? span.spanContext().traceId
136
+ : core.hexToBase64(span.spanContext().traceId),
137
+ spanId: useHex
138
+ ? span.spanContext().spanId
139
+ : core.hexToBase64(span.spanContext().spanId),
140
+ parentSpanId: span.parentSpanId
141
+ ? useHex
142
+ ? span.parentSpanId
143
+ : core.hexToBase64(span.parentSpanId)
144
+ : undefined,
145
+ traceState: toCollectorTraceState(span.spanContext().traceState),
146
+ name: span.name,
147
+ kind: toCollectorKind(span.kind),
148
+ startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),
149
+ endTimeUnixNano: core.hrTimeToNanoseconds(span.endTime),
150
+ attributes: toCollectorAttributes(span.attributes),
151
+ droppedAttributesCount: 0,
152
+ events: toCollectorEvents(span.events),
153
+ droppedEventsCount: 0,
154
+ status: toCollectorStatus(span.status),
155
+ links: toCollectorLinks(span, useHex),
156
+ droppedLinksCount: 0,
157
+ };
158
+ }
159
+ /**
160
+ * Converts status
161
+ * @param status
162
+ */
163
+ export function toCollectorStatus(status) {
164
+ const spanStatus = {
165
+ code: status.code,
166
+ };
167
+ if (typeof status.message !== 'undefined') {
168
+ spanStatus.message = status.message;
169
+ }
170
+ return spanStatus;
171
+ }
172
+ /**
173
+ * Converts resource
174
+ * @param resource
175
+ * @param additionalAttributes
176
+ */
177
+ export function toCollectorResource(resource, additionalAttributes = {}) {
178
+ const attr = Object.assign({}, additionalAttributes, resource ? resource.attributes : {});
179
+ const resourceProto = {
180
+ attributes: toCollectorAttributes(attr),
181
+ droppedAttributesCount: 0,
182
+ };
183
+ return resourceProto;
184
+ }
185
+ /**
186
+ * Converts span kind
187
+ * @param kind
188
+ */
189
+ export function toCollectorKind(kind) {
190
+ const collectorKind = OTLP_SPAN_KIND_MAPPING[kind];
191
+ return typeof collectorKind === 'number'
192
+ ? collectorKind
193
+ : opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_UNSPECIFIED;
194
+ }
195
+ /**
196
+ * Converts traceState
197
+ * @param traceState
198
+ */
199
+ export function toCollectorTraceState(traceState) {
200
+ if (!traceState)
201
+ return undefined;
202
+ return traceState.serialize();
203
+ }
204
+ /**
205
+ * Prepares trace service request to be sent to collector
206
+ * @param spans spans
207
+ * @param collectorExporterBase
208
+ * @param useHex - if ids should be kept as hex without converting to base64
209
+ */
210
+ export function toOTLPExportTraceServiceRequest(spans, collectorTraceExporterBase, useHex) {
211
+ const groupedSpans = groupSpansByResourceAndLibrary(spans);
212
+ const additionalAttributes = Object.assign({}, collectorTraceExporterBase.attributes);
213
+ return {
214
+ resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes, useHex),
215
+ };
216
+ }
217
+ /**
218
+ * Takes an array of spans and groups them by resource and instrumentation
219
+ * library
220
+ * @param spans spans
221
+ */
222
+ export function groupSpansByResourceAndLibrary(spans) {
223
+ return spans.reduce((spanMap, span) => {
224
+ //group by resource
225
+ let resourceSpans = spanMap.get(span.resource);
226
+ if (!resourceSpans) {
227
+ resourceSpans = new Map();
228
+ spanMap.set(span.resource, resourceSpans);
229
+ }
230
+ //group by instrumentation library
231
+ let libSpans = resourceSpans.get(span.instrumentationLibrary);
232
+ if (!libSpans) {
233
+ libSpans = new Array();
234
+ resourceSpans.set(span.instrumentationLibrary, libSpans);
235
+ }
236
+ libSpans.push(span);
237
+ return spanMap;
238
+ }, new Map());
239
+ }
240
+ /**
241
+ * Convert to InstrumentationLibrarySpans
242
+ * @param instrumentationLibrary
243
+ * @param spans
244
+ * @param useHex - if ids should be kept as hex without converting to base64
245
+ */
246
+ function toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex) {
247
+ return {
248
+ spans: spans.map(span => toCollectorSpan(span, useHex)),
249
+ instrumentationLibrary,
250
+ };
251
+ }
252
+ /**
253
+ * Returns a list of resource spans which will be exported to the collector
254
+ * @param groupedSpans
255
+ * @param baseAttributes
256
+ * @param useHex - if ids should be kept as hex without converting to base64
257
+ */
258
+ function toCollectorResourceSpans(groupedSpans, baseAttributes, useHex) {
259
+ return Array.from(groupedSpans, ([resource, libSpans]) => {
260
+ return {
261
+ resource: toCollectorResource(resource, baseAttributes),
262
+ instrumentationLibrarySpans: Array.from(libSpans, ([instrumentationLibrary, spans]) => toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex)),
263
+ };
264
+ });
265
+ }
266
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
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,MAAM,iBAAiB,GAAG,UAAU,CAAC;AACrC,MAAM,iBAAiB,GAAG,CAAC,UAAU,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAA0B;IAE1B,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACvC,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAiB;IAEjB,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAA0B;IAE1B,OAAO;QACL,MAAM,EAAE,qBAAqB,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAC1C,GAAW,EACX,KAAc;IAEd,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO;QACL,GAAG;QACH,KAAK,EAAE,QAAQ;KAChB,CA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,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;SAC3C;QACD,kCAAkC;QAClC,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,GAAG,IAAI,KAAK,EAAgB,CAAC;YACrC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;SAC1D;QACD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,IAAI,GAAG,EAA8D,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;GAKG;AACH,SAAS,sCAAsC,CAC7C,sBAAmD,EACnD,KAAqB,EACrB,MAAgB;IAEhB,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvD,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAC/B,YAA6E,EAC7E,cAA8B,EAC9B,MAAgB;IAEhB,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;QACvD,OAAO;YACL,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE,cAAc,CAAC;YACvD,2BAA2B,EAAE,KAAK,CAAC,IAAI,CACrC,QAAQ,EACR,CAAC,CAAC,sBAAsB,EAAE,KAAK,CAAC,EAAE,EAAE,CAClC,sCAAsC,CACpC,sBAAsB,EACtB,KAAK,EACL,MAAM,CACP,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"]}