@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.
Files changed (56) hide show
  1. package/README.md +44 -12
  2. package/build/esm/index.d.ts +0 -2
  3. package/build/esm/index.js +0 -3
  4. package/build/esm/index.js.map +1 -1
  5. package/build/esm/platform/browser/OTLPTraceExporter.d.ts +4 -5
  6. package/build/esm/platform/browser/OTLPTraceExporter.js +7 -7
  7. package/build/esm/platform/browser/OTLPTraceExporter.js.map +1 -1
  8. package/build/esm/platform/node/OTLPTraceExporter.d.ts +3 -3
  9. package/build/esm/platform/node/OTLPTraceExporter.js +7 -7
  10. package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
  11. package/build/esm/version.d.ts +1 -1
  12. package/build/esm/version.js +1 -1
  13. package/build/esm/version.js.map +1 -1
  14. package/build/esnext/index.d.ts +0 -2
  15. package/build/esnext/index.js +0 -2
  16. package/build/esnext/index.js.map +1 -1
  17. package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +4 -5
  18. package/build/esnext/platform/browser/OTLPTraceExporter.js +7 -7
  19. package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -1
  20. package/build/esnext/platform/node/OTLPTraceExporter.d.ts +3 -3
  21. package/build/esnext/platform/node/OTLPTraceExporter.js +7 -7
  22. package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -1
  23. package/build/esnext/version.d.ts +1 -1
  24. package/build/esnext/version.js +1 -1
  25. package/build/esnext/version.js.map +1 -1
  26. package/build/src/index.d.ts +0 -2
  27. package/build/src/index.js +0 -5
  28. package/build/src/index.js.map +1 -1
  29. package/build/src/platform/browser/OTLPTraceExporter.d.ts +4 -5
  30. package/build/src/platform/browser/OTLPTraceExporter.js +7 -7
  31. package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
  32. package/build/src/platform/node/OTLPTraceExporter.d.ts +3 -3
  33. package/build/src/platform/node/OTLPTraceExporter.js +6 -6
  34. package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
  35. package/build/src/version.d.ts +1 -1
  36. package/build/src/version.js +1 -1
  37. package/build/src/version.js.map +1 -1
  38. package/package.json +8 -7
  39. package/build/esm/transform.d.ts +0 -80
  40. package/build/esm/transform.js +0 -287
  41. package/build/esm/transform.js.map +0 -1
  42. package/build/esm/types.d.ts +0 -209
  43. package/build/esm/types.js +0 -146
  44. package/build/esm/types.js.map +0 -1
  45. package/build/esnext/transform.d.ts +0 -80
  46. package/build/esnext/transform.js +0 -266
  47. package/build/esnext/transform.js.map +0 -1
  48. package/build/esnext/types.d.ts +0 -209
  49. package/build/esnext/types.js +0 -145
  50. package/build/esnext/types.js.map +0 -1
  51. package/build/src/transform.d.ts +0 -80
  52. package/build/src/transform.js +0 -282
  53. package/build/src/transform.js.map +0 -1
  54. package/build/src/types.d.ts +0 -209
  55. package/build/src/types.js +0 -148
  56. package/build/src/types.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAkB,MAAM,oBAAoB,CAAC;AAE9D,oDAAoD;AACpD,sDAAsD;AAEtD,MAAM,KAAW,kBAAkB,CAkSlC;AAlSD,WAAiB,kBAAkB;IAyBjC,IAAiB,OAAO,CAqIvB;IArID,WAAiB,OAAO;QAAC,IAAA,EAAE,CAqI1B;QArIwB,WAAA,EAAE;YAkEzB,IAAY,sBAkEX;YAlED,WAAY,sBAAsB;gBAChC,0EAA0E;gBAC1E,iIAAuC,CAAA;gBAEvC,2EAA2E;gBAC3E,4EAA4E;gBAC5E,wDAAwD;gBACxD,EAAE;gBACF,oEAAoE;gBACpE,mEAAmE;gBACnE,iEAAiE;gBACjE,EAAE;gBACF,uEAAuE;gBACvE,sEAAsE;gBACtE,gBAAgB;gBAChB,EAAE;gBACF,gDAAgD;gBACh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AC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB;IAC7E,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB;IAC7E,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACjB,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB;IAC9D,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACjB,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB;CAC/D,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 { SpanKind, SpanStatusCode } from '@opentelemetry/api';\n\n/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\nexport namespace opentelemetryProto {\n export namespace collector {\n export namespace trace.v1 {\n export interface TraceService {\n service: opentelemetryProto.collector.trace.v1.TraceService;\n }\n\n export interface ExportTraceServiceRequest {\n resourceSpans: opentelemetryProto.trace.v1.ResourceSpans[];\n }\n }\n export namespace metrics.v1 {\n export interface ExportMetricsServiceRequest {\n resourceMetrics: opentelemetryProto.metrics.v1.ResourceMetrics[];\n }\n }\n }\n\n export namespace resource.v1 {\n export interface Resource {\n attributes: opentelemetryProto.common.v1.KeyValue[];\n droppedAttributesCount: number;\n }\n }\n\n export namespace metrics.v1 {\n export interface Metric {\n name: string;\n description: string;\n unit: string;\n // data:\n intGauge?: opentelemetryProto.metrics.v1.Gauge;\n doubleGauge?: opentelemetryProto.metrics.v1.Gauge;\n intSum?: opentelemetryProto.metrics.v1.Sum;\n doubleSum?: opentelemetryProto.metrics.v1.Sum;\n intHistogram?: opentelemetryProto.metrics.v1.Histogram;\n doubleHistogram?: opentelemetryProto.metrics.v1.Histogram;\n }\n\n export interface Gauge {\n dataPoints: opentelemetryProto.metrics.v1.DataPoint[];\n }\n\n export interface Sum {\n dataPoints: opentelemetryProto.metrics.v1.DataPoint[];\n aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;\n isMonotonic: boolean;\n }\n\n export interface Histogram {\n dataPoints: opentelemetryProto.metrics.v1.HistogramDataPoint[];\n aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;\n }\n\n export interface DataPoint {\n labels: opentelemetryProto.common.v1.StringKeyValue[];\n startTimeUnixNano: number;\n timeUnixNano: number;\n value: number;\n exemplars?: opentelemetryProto.metrics.v1.Exemplar[];\n }\n\n export interface Exemplar {\n filteredLabels: opentelemetryProto.common.v1.StringKeyValue[];\n timeUnixNano: number;\n value: number;\n spanId: Uint8Array;\n traceId: Uint8Array;\n }\n\n export interface HistogramDataPoint {\n labels: opentelemetryProto.common.v1.StringKeyValue[];\n startTimeUnixNano: number;\n timeUnixNano: number;\n count: number;\n sum: number;\n bucketCounts?: number[];\n explicitBounds?: number[];\n exemplars?: opentelemetryProto.metrics.v1.Exemplar[][];\n }\n\n export interface InstrumentationLibraryMetrics {\n instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;\n metrics: opentelemetryProto.metrics.v1.Metric[];\n }\n\n export interface ResourceMetrics {\n resource?: opentelemetryProto.resource.v1.Resource;\n instrumentationLibraryMetrics: opentelemetryProto.metrics.v1.InstrumentationLibraryMetrics[];\n }\n\n export enum AggregationTemporality {\n // UNSPECIFIED is the default AggregationTemporality, it MUST not be used.\n AGGREGATION_TEMPORALITY_UNSPECIFIED = 0,\n\n // DELTA is an AggregationTemporality for a metric aggregator which reports\n // changes since last report time. Successive metrics contain aggregation of\n // values from continuous and non-overlapping intervals.\n //\n // The values for a DELTA metric are based only on the time interval\n // associated with one measurement cycle. There is no dependency on\n // previous measurements like is the case for CUMULATIVE metrics.\n //\n // For example, consider a system measuring the number of requests that\n // it receives and reports the sum of these requests every second as a\n // DELTA metric:\n //\n // 1. The system starts receiving at time=t_0.\n // 2. A request is received, the system measures 1 request.\n // 3. A request is received, the system measures 1 request.\n // 4. A request is received, the system measures 1 request.\n // 5. The 1 second collection cycle ends. A metric is exported for the\n // number of requests received over the interval of time t_0 to\n // t_0+1 with a value of 3.\n // 6. A request is received, the system measures 1 request.\n // 7. A request is received, the system measures 1 request.\n // 8. The 1 second collection cycle ends. A metric is exported for the\n // number of requests received over the interval of time t_0+1 to\n // t_0+2 with a value of 2.\n AGGREGATION_TEMPORALITY_DELTA = 1,\n\n // CUMULATIVE is an AggregationTemporality for a metric aggregator which\n // reports changes since a fixed start time. This means that current values\n // of a CUMULATIVE metric depend on all previous measurements since the\n // start time. Because of this, the sender is required to retain this state\n // in some form. If this state is lost or invalidated, the CUMULATIVE metric\n // values MUST be reset and a new fixed start time following the last\n // reported measurement time sent MUST be used.\n //\n // For example, consider a system measuring the number of requests that\n // it receives and reports the sum of these requests every second as a\n // CUMULATIVE metric:\n //\n // 1. The system starts receiving at time=t_0.\n // 2. A request is received, the system measures 1 request.\n // 3. A request is received, the system measures 1 request.\n // 4. A request is received, the system measures 1 request.\n // 5. The 1 second collection cycle ends. A metric is exported for the\n // number of requests received over the interval of time t_0 to\n // t_0+1 with a value of 3.\n // 6. A request is received, the system measures 1 request.\n // 7. A request is received, the system measures 1 request.\n // 8. The 1 second collection cycle ends. A metric is exported for the\n // number of requests received over the interval of time t_0 to\n // t_0+2 with a value of 5.\n // 9. The system experiences a fault and loses state.\n // 10. The system recovers and resumes receiving at time=t_1.\n // 11. A request is received, the system measures 1 request.\n // 12. The 1 second collection cycle ends. A metric is exported for the\n // number of requests received over the interval of time t_1 to\n // t_0+1 with a value of 1.\n //\n // Note: Even though, when reporting changes since last report time, using\n // CUMULATIVE is valid, it is not recommended. This may cause problems for\n // systems that do not use start_time to determine when the aggregation\n // value was reset (e.g. Prometheus).\n AGGREGATION_TEMPORALITY_CUMULATIVE = 2,\n }\n }\n\n export namespace trace.v1 {\n export namespace ConstantSampler {\n export enum ConstantDecision {\n ALWAYS_OFF = 0,\n ALWAYS_ON = 1,\n ALWAYS_PARENT = 2,\n }\n }\n export namespace Span {\n export interface Event {\n timeUnixNano: number;\n name: string;\n attributes?: opentelemetryProto.common.v1.KeyValue[];\n droppedAttributesCount: number;\n }\n\n export interface Link {\n traceId: string;\n spanId: string;\n traceState?: opentelemetryProto.trace.v1.Span.TraceState;\n attributes?: opentelemetryProto.common.v1.KeyValue[];\n droppedAttributesCount: number;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n export enum SpanKind {\n SPAN_KIND_UNSPECIFIED,\n SPAN_KIND_INTERNAL,\n SPAN_KIND_SERVER,\n SPAN_KIND_CLIENT,\n SPAN_KIND_PRODUCER,\n SPAN_KIND_CONSUMER,\n }\n\n export type TraceState = string | undefined;\n }\n\n export interface ConstantSampler {\n decision?: opentelemetryProto.trace.v1.ConstantSampler.ConstantDecision;\n }\n\n export interface InstrumentationLibrarySpans {\n instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;\n spans: opentelemetryProto.trace.v1.Span[];\n }\n\n export interface ProbabilitySampler {\n samplingProbability?: number | null;\n }\n\n export interface RateLimitingSampler {\n qps?: number | null;\n }\n\n export interface ResourceSpans {\n resource?: opentelemetryProto.resource.v1.Resource;\n instrumentationLibrarySpans: opentelemetryProto.trace.v1.InstrumentationLibrarySpans[];\n }\n\n export interface Span {\n traceId: string;\n spanId: string;\n traceState: opentelemetryProto.trace.v1.Span.TraceState;\n parentSpanId?: string;\n name?: string;\n kind?: opentelemetryProto.trace.v1.Span.SpanKind;\n startTimeUnixNano?: number;\n endTimeUnixNano?: number;\n attributes?: opentelemetryProto.common.v1.KeyValue[];\n droppedAttributesCount: number;\n events?: opentelemetryProto.trace.v1.Span.Event[];\n droppedEventsCount: number;\n links?: opentelemetryProto.trace.v1.Span.Link[];\n droppedLinksCount: number;\n status?: SpanStatus;\n }\n\n export interface SpanStatus {\n /** The status code of this message. */\n code: SpanStatusCode;\n /** A developer-facing error message. */\n message?: string;\n }\n\n export interface TraceConfig {\n constantSampler?: ConstantSampler | null;\n probabilitySampler?: ProbabilitySampler | null;\n rateLimitingSampler?: RateLimitingSampler | null;\n }\n }\n export namespace common.v1 {\n export interface KeyValue {\n key: string;\n value: AnyValue;\n }\n\n export type ArrayValue = {\n values: AnyValue[];\n };\n\n export interface KeyValueList {\n values: KeyValue[];\n }\n\n export type AnyValue = {\n stringValue?: string;\n boolValue?: boolean;\n intValue?: number;\n doubleValue?: number;\n arrayValue?: ArrayValue;\n kvlistValue?: KeyValueList;\n };\n\n export interface InstrumentationLibrary {\n name: string;\n version?: string;\n }\n\n export interface StringKeyValue {\n key: string;\n value: string;\n }\n\n export enum ValueType {\n STRING,\n INT,\n DOUBLE,\n BOOL,\n }\n }\n}\n\n/**\n * Mapping between api SpanKind and proto SpanKind\n */\nexport const OTLP_SPAN_KIND_MAPPING = {\n [SpanKind.INTERNAL]:\n opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_INTERNAL,\n [SpanKind.SERVER]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_SERVER,\n [SpanKind.CLIENT]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT,\n [SpanKind.PRODUCER]:\n opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_PRODUCER,\n [SpanKind.CONSUMER]:\n opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CONSUMER,\n};\n"]}
@@ -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
@@ -1,282 +0,0 @@
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
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.groupSpansByResourceAndLibrary = exports.toOTLPExportTraceServiceRequest = exports.toCollectorTraceState = exports.toCollectorKind = exports.toCollectorResource = exports.toCollectorStatus = exports.toCollectorSpan = exports.toCollectorEvents = exports.toCollectorAnyValue = exports.toCollectorAttributeKeyValue = exports.toCollectorKeyValueList = exports.toCollectorArrayValue = exports.toCollectorAttributes = void 0;
19
- const core = require("@opentelemetry/core");
20
- const types_1 = require("./types");
21
- const MAX_INTEGER_VALUE = 2147483647;
22
- const MIN_INTEGER_VALUE = -2147483648;
23
- /**
24
- * Converts attributes to KeyValue array
25
- * @param attributes
26
- */
27
- function toCollectorAttributes(attributes) {
28
- return Object.keys(attributes).map(key => {
29
- return toCollectorAttributeKeyValue(key, attributes[key]);
30
- });
31
- }
32
- exports.toCollectorAttributes = toCollectorAttributes;
33
- /**
34
- * Converts array of unknown value to ArrayValue
35
- * @param values
36
- */
37
- function toCollectorArrayValue(values) {
38
- return {
39
- values: values.map(value => toCollectorAnyValue(value)),
40
- };
41
- }
42
- exports.toCollectorArrayValue = toCollectorArrayValue;
43
- /**
44
- * Converts attributes to KeyValueList
45
- * @param attributes
46
- */
47
- function toCollectorKeyValueList(attributes) {
48
- return {
49
- values: toCollectorAttributes(attributes),
50
- };
51
- }
52
- exports.toCollectorKeyValueList = toCollectorKeyValueList;
53
- /**
54
- * Converts key and unknown value to KeyValue
55
- * @param value event value
56
- */
57
- function toCollectorAttributeKeyValue(key, value) {
58
- const anyValue = toCollectorAnyValue(value);
59
- return {
60
- key,
61
- value: anyValue,
62
- };
63
- }
64
- exports.toCollectorAttributeKeyValue = toCollectorAttributeKeyValue;
65
- /**
66
- * Converts unknown value to AnyValue
67
- * @param value
68
- */
69
- function toCollectorAnyValue(value) {
70
- const anyValue = {};
71
- if (typeof value === 'string') {
72
- anyValue.stringValue = value;
73
- }
74
- else if (typeof value === 'boolean') {
75
- anyValue.boolValue = value;
76
- }
77
- else if (typeof value === 'number' &&
78
- value <= MAX_INTEGER_VALUE &&
79
- value >= MIN_INTEGER_VALUE &&
80
- Number.isInteger(value)) {
81
- anyValue.intValue = value;
82
- }
83
- else if (typeof value === 'number') {
84
- anyValue.doubleValue = value;
85
- }
86
- else if (Array.isArray(value)) {
87
- anyValue.arrayValue = toCollectorArrayValue(value);
88
- }
89
- else if (value) {
90
- anyValue.kvlistValue = toCollectorKeyValueList(value);
91
- }
92
- return anyValue;
93
- }
94
- exports.toCollectorAnyValue = toCollectorAnyValue;
95
- /**
96
- *
97
- * Converts events
98
- * @param events array of events
99
- */
100
- function toCollectorEvents(timedEvents) {
101
- return timedEvents.map(timedEvent => {
102
- const timeUnixNano = core.hrTimeToNanoseconds(timedEvent.time);
103
- const name = timedEvent.name;
104
- const attributes = toCollectorAttributes(timedEvent.attributes || {});
105
- const droppedAttributesCount = 0;
106
- const protoEvent = {
107
- timeUnixNano,
108
- name,
109
- attributes,
110
- droppedAttributesCount,
111
- };
112
- return protoEvent;
113
- });
114
- }
115
- exports.toCollectorEvents = toCollectorEvents;
116
- /**
117
- * Converts links
118
- * @param span
119
- * @param useHex - if ids should be kept as hex without converting to base64
120
- */
121
- function toCollectorLinks(span, useHex) {
122
- return span.links.map((link) => {
123
- const protoLink = {
124
- traceId: useHex
125
- ? link.context.traceId
126
- : core.hexToBase64(link.context.traceId),
127
- spanId: useHex
128
- ? link.context.spanId
129
- : core.hexToBase64(link.context.spanId),
130
- attributes: toCollectorAttributes(link.attributes || {}),
131
- droppedAttributesCount: 0,
132
- };
133
- return protoLink;
134
- });
135
- }
136
- /**
137
- * Converts span
138
- * @param span
139
- * @param useHex - if ids should be kept as hex without converting to base64
140
- */
141
- function toCollectorSpan(span, useHex) {
142
- return {
143
- traceId: useHex
144
- ? span.spanContext().traceId
145
- : core.hexToBase64(span.spanContext().traceId),
146
- spanId: useHex
147
- ? span.spanContext().spanId
148
- : core.hexToBase64(span.spanContext().spanId),
149
- parentSpanId: span.parentSpanId
150
- ? useHex
151
- ? span.parentSpanId
152
- : core.hexToBase64(span.parentSpanId)
153
- : undefined,
154
- traceState: toCollectorTraceState(span.spanContext().traceState),
155
- name: span.name,
156
- kind: toCollectorKind(span.kind),
157
- startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),
158
- endTimeUnixNano: core.hrTimeToNanoseconds(span.endTime),
159
- attributes: toCollectorAttributes(span.attributes),
160
- droppedAttributesCount: 0,
161
- events: toCollectorEvents(span.events),
162
- droppedEventsCount: 0,
163
- status: toCollectorStatus(span.status),
164
- links: toCollectorLinks(span, useHex),
165
- droppedLinksCount: 0,
166
- };
167
- }
168
- exports.toCollectorSpan = toCollectorSpan;
169
- /**
170
- * Converts status
171
- * @param status
172
- */
173
- function toCollectorStatus(status) {
174
- const spanStatus = {
175
- code: status.code,
176
- };
177
- if (typeof status.message !== 'undefined') {
178
- spanStatus.message = status.message;
179
- }
180
- return spanStatus;
181
- }
182
- exports.toCollectorStatus = toCollectorStatus;
183
- /**
184
- * Converts resource
185
- * @param resource
186
- * @param additionalAttributes
187
- */
188
- function toCollectorResource(resource, additionalAttributes = {}) {
189
- const attr = Object.assign({}, additionalAttributes, resource ? resource.attributes : {});
190
- const resourceProto = {
191
- attributes: toCollectorAttributes(attr),
192
- droppedAttributesCount: 0,
193
- };
194
- return resourceProto;
195
- }
196
- exports.toCollectorResource = toCollectorResource;
197
- /**
198
- * Converts span kind
199
- * @param kind
200
- */
201
- function toCollectorKind(kind) {
202
- const collectorKind = types_1.OTLP_SPAN_KIND_MAPPING[kind];
203
- return typeof collectorKind === 'number'
204
- ? collectorKind
205
- : types_1.opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_UNSPECIFIED;
206
- }
207
- exports.toCollectorKind = toCollectorKind;
208
- /**
209
- * Converts traceState
210
- * @param traceState
211
- */
212
- function toCollectorTraceState(traceState) {
213
- if (!traceState)
214
- return undefined;
215
- return traceState.serialize();
216
- }
217
- exports.toCollectorTraceState = toCollectorTraceState;
218
- /**
219
- * Prepares trace service request to be sent to collector
220
- * @param spans spans
221
- * @param collectorExporterBase
222
- * @param useHex - if ids should be kept as hex without converting to base64
223
- */
224
- function toOTLPExportTraceServiceRequest(spans, collectorTraceExporterBase, useHex) {
225
- const groupedSpans = groupSpansByResourceAndLibrary(spans);
226
- const additionalAttributes = Object.assign({}, collectorTraceExporterBase.attributes);
227
- return {
228
- resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes, useHex),
229
- };
230
- }
231
- exports.toOTLPExportTraceServiceRequest = toOTLPExportTraceServiceRequest;
232
- /**
233
- * Takes an array of spans and groups them by resource and instrumentation
234
- * library
235
- * @param spans spans
236
- */
237
- function groupSpansByResourceAndLibrary(spans) {
238
- return spans.reduce((spanMap, span) => {
239
- //group by resource
240
- let resourceSpans = spanMap.get(span.resource);
241
- if (!resourceSpans) {
242
- resourceSpans = new Map();
243
- spanMap.set(span.resource, resourceSpans);
244
- }
245
- //group by instrumentation library
246
- let libSpans = resourceSpans.get(span.instrumentationLibrary);
247
- if (!libSpans) {
248
- libSpans = new Array();
249
- resourceSpans.set(span.instrumentationLibrary, libSpans);
250
- }
251
- libSpans.push(span);
252
- return spanMap;
253
- }, new Map());
254
- }
255
- exports.groupSpansByResourceAndLibrary = groupSpansByResourceAndLibrary;
256
- /**
257
- * Convert to InstrumentationLibrarySpans
258
- * @param instrumentationLibrary
259
- * @param spans
260
- * @param useHex - if ids should be kept as hex without converting to base64
261
- */
262
- function toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex) {
263
- return {
264
- spans: spans.map(span => toCollectorSpan(span, useHex)),
265
- instrumentationLibrary,
266
- };
267
- }
268
- /**
269
- * Returns a list of resource spans which will be exported to the collector
270
- * @param groupedSpans
271
- * @param baseAttributes
272
- * @param useHex - if ids should be kept as hex without converting to base64
273
- */
274
- function toCollectorResourceSpans(groupedSpans, baseAttributes, useHex) {
275
- return Array.from(groupedSpans, ([resource, libSpans]) => {
276
- return {
277
- resource: toCollectorResource(resource, baseAttributes),
278
- instrumentationLibrarySpans: Array.from(libSpans, ([instrumentationLibrary, spans]) => toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex)),
279
- };
280
- });
281
- }
282
- //# sourceMappingURL=transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AASH,4CAA4C;AAG5C,mCAGiB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AC;SAC1D;QACD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,IAAI,GAAG,EAA8D,CAAC,CAAC;AAC5E,CAAC;AAnBD,wEAmBC;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"]}
@@ -1,209 +0,0 @@
1
- import { SpanStatusCode } from '@opentelemetry/api';
2
- export declare namespace opentelemetryProto {
3
- namespace collector {
4
- namespace trace.v1 {
5
- interface TraceService {
6
- service: opentelemetryProto.collector.trace.v1.TraceService;
7
- }
8
- interface ExportTraceServiceRequest {
9
- resourceSpans: opentelemetryProto.trace.v1.ResourceSpans[];
10
- }
11
- }
12
- namespace metrics.v1 {
13
- interface ExportMetricsServiceRequest {
14
- resourceMetrics: opentelemetryProto.metrics.v1.ResourceMetrics[];
15
- }
16
- }
17
- }
18
- namespace resource.v1 {
19
- interface Resource {
20
- attributes: opentelemetryProto.common.v1.KeyValue[];
21
- droppedAttributesCount: number;
22
- }
23
- }
24
- namespace metrics.v1 {
25
- interface Metric {
26
- name: string;
27
- description: string;
28
- unit: string;
29
- intGauge?: opentelemetryProto.metrics.v1.Gauge;
30
- doubleGauge?: opentelemetryProto.metrics.v1.Gauge;
31
- intSum?: opentelemetryProto.metrics.v1.Sum;
32
- doubleSum?: opentelemetryProto.metrics.v1.Sum;
33
- intHistogram?: opentelemetryProto.metrics.v1.Histogram;
34
- doubleHistogram?: opentelemetryProto.metrics.v1.Histogram;
35
- }
36
- interface Gauge {
37
- dataPoints: opentelemetryProto.metrics.v1.DataPoint[];
38
- }
39
- interface Sum {
40
- dataPoints: opentelemetryProto.metrics.v1.DataPoint[];
41
- aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;
42
- isMonotonic: boolean;
43
- }
44
- interface Histogram {
45
- dataPoints: opentelemetryProto.metrics.v1.HistogramDataPoint[];
46
- aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;
47
- }
48
- interface DataPoint {
49
- labels: opentelemetryProto.common.v1.StringKeyValue[];
50
- startTimeUnixNano: number;
51
- timeUnixNano: number;
52
- value: number;
53
- exemplars?: opentelemetryProto.metrics.v1.Exemplar[];
54
- }
55
- interface Exemplar {
56
- filteredLabels: opentelemetryProto.common.v1.StringKeyValue[];
57
- timeUnixNano: number;
58
- value: number;
59
- spanId: Uint8Array;
60
- traceId: Uint8Array;
61
- }
62
- interface HistogramDataPoint {
63
- labels: opentelemetryProto.common.v1.StringKeyValue[];
64
- startTimeUnixNano: number;
65
- timeUnixNano: number;
66
- count: number;
67
- sum: number;
68
- bucketCounts?: number[];
69
- explicitBounds?: number[];
70
- exemplars?: opentelemetryProto.metrics.v1.Exemplar[][];
71
- }
72
- interface InstrumentationLibraryMetrics {
73
- instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;
74
- metrics: opentelemetryProto.metrics.v1.Metric[];
75
- }
76
- interface ResourceMetrics {
77
- resource?: opentelemetryProto.resource.v1.Resource;
78
- instrumentationLibraryMetrics: opentelemetryProto.metrics.v1.InstrumentationLibraryMetrics[];
79
- }
80
- enum AggregationTemporality {
81
- AGGREGATION_TEMPORALITY_UNSPECIFIED = 0,
82
- AGGREGATION_TEMPORALITY_DELTA = 1,
83
- AGGREGATION_TEMPORALITY_CUMULATIVE = 2
84
- }
85
- }
86
- namespace trace.v1 {
87
- namespace ConstantSampler {
88
- enum ConstantDecision {
89
- ALWAYS_OFF = 0,
90
- ALWAYS_ON = 1,
91
- ALWAYS_PARENT = 2
92
- }
93
- }
94
- namespace Span {
95
- interface Event {
96
- timeUnixNano: number;
97
- name: string;
98
- attributes?: opentelemetryProto.common.v1.KeyValue[];
99
- droppedAttributesCount: number;
100
- }
101
- interface Link {
102
- traceId: string;
103
- spanId: string;
104
- traceState?: opentelemetryProto.trace.v1.Span.TraceState;
105
- attributes?: opentelemetryProto.common.v1.KeyValue[];
106
- droppedAttributesCount: number;
107
- }
108
- enum SpanKind {
109
- SPAN_KIND_UNSPECIFIED = 0,
110
- SPAN_KIND_INTERNAL = 1,
111
- SPAN_KIND_SERVER = 2,
112
- SPAN_KIND_CLIENT = 3,
113
- SPAN_KIND_PRODUCER = 4,
114
- SPAN_KIND_CONSUMER = 5
115
- }
116
- type TraceState = string | undefined;
117
- }
118
- interface ConstantSampler {
119
- decision?: opentelemetryProto.trace.v1.ConstantSampler.ConstantDecision;
120
- }
121
- interface InstrumentationLibrarySpans {
122
- instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;
123
- spans: opentelemetryProto.trace.v1.Span[];
124
- }
125
- interface ProbabilitySampler {
126
- samplingProbability?: number | null;
127
- }
128
- interface RateLimitingSampler {
129
- qps?: number | null;
130
- }
131
- interface ResourceSpans {
132
- resource?: opentelemetryProto.resource.v1.Resource;
133
- instrumentationLibrarySpans: opentelemetryProto.trace.v1.InstrumentationLibrarySpans[];
134
- }
135
- interface Span {
136
- traceId: string;
137
- spanId: string;
138
- traceState: opentelemetryProto.trace.v1.Span.TraceState;
139
- parentSpanId?: string;
140
- name?: string;
141
- kind?: opentelemetryProto.trace.v1.Span.SpanKind;
142
- startTimeUnixNano?: number;
143
- endTimeUnixNano?: number;
144
- attributes?: opentelemetryProto.common.v1.KeyValue[];
145
- droppedAttributesCount: number;
146
- events?: opentelemetryProto.trace.v1.Span.Event[];
147
- droppedEventsCount: number;
148
- links?: opentelemetryProto.trace.v1.Span.Link[];
149
- droppedLinksCount: number;
150
- status?: SpanStatus;
151
- }
152
- interface SpanStatus {
153
- /** The status code of this message. */
154
- code: SpanStatusCode;
155
- /** A developer-facing error message. */
156
- message?: string;
157
- }
158
- interface TraceConfig {
159
- constantSampler?: ConstantSampler | null;
160
- probabilitySampler?: ProbabilitySampler | null;
161
- rateLimitingSampler?: RateLimitingSampler | null;
162
- }
163
- }
164
- namespace common.v1 {
165
- interface KeyValue {
166
- key: string;
167
- value: AnyValue;
168
- }
169
- type ArrayValue = {
170
- values: AnyValue[];
171
- };
172
- interface KeyValueList {
173
- values: KeyValue[];
174
- }
175
- type AnyValue = {
176
- stringValue?: string;
177
- boolValue?: boolean;
178
- intValue?: number;
179
- doubleValue?: number;
180
- arrayValue?: ArrayValue;
181
- kvlistValue?: KeyValueList;
182
- };
183
- interface InstrumentationLibrary {
184
- name: string;
185
- version?: string;
186
- }
187
- interface StringKeyValue {
188
- key: string;
189
- value: string;
190
- }
191
- enum ValueType {
192
- STRING = 0,
193
- INT = 1,
194
- DOUBLE = 2,
195
- BOOL = 3
196
- }
197
- }
198
- }
199
- /**
200
- * Mapping between api SpanKind and proto SpanKind
201
- */
202
- export declare const OTLP_SPAN_KIND_MAPPING: {
203
- 0: opentelemetryProto.trace.v1.Span.SpanKind;
204
- 1: opentelemetryProto.trace.v1.Span.SpanKind;
205
- 2: opentelemetryProto.trace.v1.Span.SpanKind;
206
- 3: opentelemetryProto.trace.v1.Span.SpanKind;
207
- 4: opentelemetryProto.trace.v1.Span.SpanKind;
208
- };
209
- //# sourceMappingURL=types.d.ts.map