diff --git a/api/test/common/diag/logLevel.test.ts b/api/test/common/diag/logLevel.test.ts index 065e46d6831..e4b20932a93 100644 --- a/api/test/common/diag/logLevel.test.ts +++ b/api/test/common/diag/logLevel.test.ts @@ -77,7 +77,7 @@ describe('LogLevelFilter DiagLogger', () => { const levelMap: Array<{ message: string; - level: DiagLogLevel; + level: number | DiagLogLevel; ignoreFuncs: Array; }> = [ { message: 'ALL', level: DiagLogLevel.ALL, ignoreFuncs: [] }, diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer/package.json index b5ae1444117..e4dfe1966ae 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer/package.json @@ -115,10 +115,11 @@ "nyc": "15.1.0", "protobufjs-cli": "1.1.3", "ts-loader": "9.5.1", - "typescript": "4.4.4", + "typescript": "5.7.2", "webpack": "5.96.1" }, "dependencies": { + "@sinclair/typebox": "0.34.11", "@opentelemetry/api-logs": "0.56.0", "@opentelemetry/core": "1.29.0", "@opentelemetry/resources": "1.29.0", diff --git a/experimental/packages/otlp-transformer/src/common/types.ts b/experimental/packages/otlp-transformer/src/common/types.ts index 732944f2e09..d66851fd421 100644 --- a/experimental/packages/otlp-transformer/src/common/types.ts +++ b/experimental/packages/otlp-transformer/src/common/types.ts @@ -14,72 +14,74 @@ * limitations under the License. */ -/** Properties of an InstrumentationScope. */ -export interface IInstrumentationScope { - /** InstrumentationScope name */ - name: string; - - /** InstrumentationScope version */ - version?: string; - - /** InstrumentationScope attributes */ - attributes?: IKeyValue[]; - - /** InstrumentationScope droppedAttributesCount */ - droppedAttributesCount?: number; -} - -/** Properties of a KeyValue. */ -export interface IKeyValue { - /** KeyValue key */ - key: string; - - /** KeyValue value */ - value: IAnyValue; -} - -/** Properties of an AnyValue. */ -export interface IAnyValue { - /** AnyValue stringValue */ - stringValue?: string | null; - - /** AnyValue boolValue */ - boolValue?: boolean | null; - - /** AnyValue intValue */ - intValue?: number | null; - - /** AnyValue doubleValue */ - doubleValue?: number | null; - - /** AnyValue arrayValue */ - arrayValue?: IArrayValue; - - /** AnyValue kvlistValue */ - kvlistValue?: IKeyValueList; - - /** AnyValue bytesValue */ - bytesValue?: Uint8Array; -} - -/** Properties of an ArrayValue. */ -export interface IArrayValue { - /** ArrayValue values */ - values: IAnyValue[]; -} - -/** Properties of a KeyValueList. */ -export interface IKeyValueList { - /** KeyValueList values */ - values: IKeyValue[]; -} - -export interface LongBits { - low: number; - high: number; -} - -export type Fixed64 = LongBits | string | number; +import { Type, type Static } from "@sinclair/typebox"; + +export const OtelCommonTypes = Type.Module({ + ResourceAttributes: Type.Object({ + key: Type.String(), + value: Type.Any(), + }), + IResource: Type.Object({ + attributes: Type.Array(Type.Ref("ResourceAttributes")), + }), + IKeyValue: Type.Object({ + key: Type.String(), + value: Type.Ref("IAnyValue"), + }), + IKeyValueList: Type.Object({ + values: Type.Array(Type.Ref("IKeyValue")), + }), + IArrayValue: Type.Object({ + values: Type.Array(Type.Ref("IAnyValue")), + }), + IAnyValue: Type.Object({ + stringValue: Type.Optional(Type.Union([Type.String(), Type.Null()])), + boolValue: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])), + intValue: Type.Optional(Type.Union([Type.Number(), Type.Null()])), + doubleValue: Type.Optional(Type.Union([Type.Number(), Type.Null()])), + arrayValue: Type.Optional(Type.Ref("IArrayValue")), + kvlistValue: Type.Optional(Type.Ref("IKeyValueList")), + bytesValue: Type.Optional(Type.Uint8Array()), + }), + IInstrumentationScope: Type.Object({ + name: Type.String(), + version: Type.Optional(Type.String()), + attributes: Type.Optional(Type.Array(Type.Ref("IKeyValue"))), + droppedAttributesCount: Type.Optional(Type.Number()), + }), + LongBits: Type.Object({ + low: Type.Number(), + high: Type.Number(), + }), + Fixed64: Type.Union([Type.Ref("LongBits"), Type.String(), Type.Number()]), +}); + +export const TResourceAttributes = OtelCommonTypes.Import("ResourceAttributes"); +export type ResourceAttributes = Static; + +export const TResource = OtelCommonTypes.Import("IResource"); +export type IResource = Static; + +export const TKeyValue = OtelCommonTypes.Import("IKeyValue"); +export type IKeyValue = Static; + +export const TKeyValueList = OtelCommonTypes.Import("IKeyValueList"); +export type IKeyValueList = Static; + +export const TArrayValue = OtelCommonTypes.Import("IArrayValue"); +export type IArrayValue = Static; + +export const TAnyValue = OtelCommonTypes.Import("IAnyValue"); +export type IAnyValue = Static; + +export const TInstrumentationScope = OtelCommonTypes.Import("IInstrumentationScope"); +export type IInstrumentationScope = Static; + +export const TLongBits = OtelCommonTypes.Import("LongBits"); +export type LongBits = Static; + +export const TFixed64 = OtelCommonTypes.Import("Fixed64"); +export type Fixed64 = Static; export interface OtlpEncodingOptions { /** Convert trace and span IDs to hex strings. */ diff --git a/experimental/packages/otlp-transformer/src/logs/types.ts b/experimental/packages/otlp-transformer/src/logs/types.ts index 57c5422cbb4..94530514949 100644 --- a/experimental/packages/otlp-transformer/src/logs/types.ts +++ b/experimental/packages/otlp-transformer/src/logs/types.ts @@ -14,19 +14,9 @@ * limitations under the License. */ -import type { - Fixed64, - IAnyValue, - IInstrumentationScope, - IKeyValue, -} from '../common/types'; -import type { IResource } from '../resource/types'; - -/** Properties of an ExportLogsServiceRequest. */ -export interface IExportLogsServiceRequest { - /** ExportLogsServiceRequest resourceLogs */ - resourceLogs?: IResourceLogs[]; -} +import { Type, type Static } from "@sinclair/typebox"; +import { TKeyValue, TFixed64, TAnyValue, TInstrumentationScope } from "../common/types"; +import { TResource } from '../resource/types'; export interface IExportLogsServiceResponse { /** ExportLogsServiceResponse partialSuccess */ @@ -41,67 +31,10 @@ export interface IExportLogsPartialSuccess { errorMessage?: string; } -/** Properties of a ResourceLogs. */ -export interface IResourceLogs { - /** ResourceLogs resource */ - resource?: IResource; - - /** ResourceLogs scopeLogs */ - scopeLogs: IScopeLogs[]; - - /** ResourceLogs schemaUrl */ - schemaUrl?: string; -} - -/** Properties of an ScopeLogs. */ -export interface IScopeLogs { - /** IScopeLogs scope */ - scope?: IInstrumentationScope; - - /** IScopeLogs logRecords */ - logRecords?: ILogRecord[]; - - /** IScopeLogs schemaUrl */ - schemaUrl?: string | null; -} - -/** Properties of a LogRecord. */ -export interface ILogRecord { - /** LogRecord timeUnixNano */ - timeUnixNano: Fixed64; - - /** LogRecord observedTimeUnixNano */ - observedTimeUnixNano: Fixed64; - - /** LogRecord severityNumber */ - severityNumber?: ESeverityNumber; - - /** LogRecord severityText */ - severityText?: string; - - /** LogRecord body */ - body?: IAnyValue; - - /** LogRecord attributes */ - attributes: IKeyValue[]; - - /** LogRecord droppedAttributesCount */ - droppedAttributesCount: number; - - /** LogRecord flags */ - flags?: number; - - /** LogRecord traceId */ - traceId?: string | Uint8Array; - - /** LogRecord spanId */ - spanId?: string | Uint8Array; -} - /** * Numerical value of the severity, normalized to values described in Log Data Model. */ -export const enum ESeverityNumber { +export enum ESeverityNumber { /** Unspecified. Do NOT use as default */ SEVERITY_NUMBER_UNSPECIFIED = 0, SEVERITY_NUMBER_TRACE = 1, @@ -129,3 +62,43 @@ export const enum ESeverityNumber { SEVERITY_NUMBER_FATAL3 = 23, SEVERITY_NUMBER_FATAL4 = 24, } + +export const OtelLogTypes = Type.Module({ + ILogRecord: Type.Object({ + timeUnixNano: TFixed64, + observedTimeUnixNano: TFixed64, + severityNumber: Type.Optional(Type.Enum(ESeverityNumber)), + severityText: Type.Optional(Type.String()), + body: Type.Optional(TAnyValue), + attributes: Type.Array(TKeyValue), + droppedAttributesCount: Type.Number(), + flags: Type.Optional(Type.Number()), + traceId: Type.Optional(Type.Union([Type.String(), Type.Uint8Array()])), + spanId: Type.Optional(Type.Union([Type.String(), Type.Uint8Array()])), + }), + IScopeLogs: Type.Object({ + scope: Type.Optional(TInstrumentationScope), + logRecords: Type.Optional(Type.Array(Type.Ref("ILogRecord"))), + schemaUrl: Type.Optional(Type.Union([Type.String(), Type.Null()])), + }), + IResourceLogs: Type.Object({ + resource: Type.Optional(TResource), + scopeLogs: Type.Array(Type.Ref("IScopeLogs")), + schemaUrl: Type.Optional(Type.String()), + }), + IExportLogsServiceRequest: Type.Object({ + resourceLogs: Type.Optional(Type.Array(Type.Ref("IResourceLogs"))), + }), +}); + +export const TLogRecord = OtelLogTypes.Import("ILogRecord"); +export type ILogRecord = Static; + +export const TScopeLogs = OtelLogTypes.Import("IScopeLogs"); +export type IScopeLogs = Static; + +export const TResourceLogs = OtelLogTypes.Import("IResourceLogs"); +export type IResourceLogs = Static; + +export const TExportLogsServiceRequest = OtelLogTypes.Import("IExportLogsServiceRequest"); +export type IExportLogsServiceRequest = Static; diff --git a/experimental/packages/otlp-transformer/src/metrics/types.ts b/experimental/packages/otlp-transformer/src/metrics/types.ts index 208c6aa6782..2ea894ca571 100644 --- a/experimental/packages/otlp-transformer/src/metrics/types.ts +++ b/experimental/packages/otlp-transformer/src/metrics/types.ts @@ -13,14 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Fixed64, IInstrumentationScope, IKeyValue } from '../common/types'; -import { IResource } from '../resource/types'; - -/** Properties of an ExportMetricsServiceRequest. */ -export interface IExportMetricsServiceRequest { - /** ExportMetricsServiceRequest resourceMetrics */ - resourceMetrics: IResourceMetrics[]; -} +import { TFixed64, TInstrumentationScope, TKeyValue } from '../common/types'; +import { TResource } from '../resource/types'; +import { Type, type Static } from "@sinclair/typebox"; export interface IExportMetricsServiceResponse { /** ExportMetricsServiceResponse partialSuccess */ @@ -35,270 +30,12 @@ export interface IExportMetricsPartialSuccess { errorMessage?: string; } -/** Properties of a ResourceMetrics. */ -export interface IResourceMetrics { - /** ResourceMetrics resource */ - resource?: IResource; - - /** ResourceMetrics scopeMetrics */ - scopeMetrics: IScopeMetrics[]; - - /** ResourceMetrics schemaUrl */ - schemaUrl?: string; -} - -/** Properties of an IScopeMetrics. */ -export interface IScopeMetrics { - /** ScopeMetrics scope */ - scope?: IInstrumentationScope; - - /** ScopeMetrics metrics */ - metrics: IMetric[]; - - /** ScopeMetrics schemaUrl */ - schemaUrl?: string; -} - -/** Properties of a Metric. */ -export interface IMetric { - /** Metric name */ - name: string; - - /** Metric description */ - description?: string; - - /** Metric unit */ - unit?: string; - - /** Metric gauge */ - gauge?: IGauge; - - /** Metric sum */ - sum?: ISum; - - /** Metric histogram */ - histogram?: IHistogram; - - /** Metric exponentialHistogram */ - exponentialHistogram?: IExponentialHistogram; - - /** Metric summary */ - summary?: ISummary; -} - -/** Properties of a Gauge. */ -export interface IGauge { - /** Gauge dataPoints */ - dataPoints: INumberDataPoint[]; -} - -/** Properties of a Sum. */ -export interface ISum { - /** Sum dataPoints */ - dataPoints: INumberDataPoint[]; - - /** Sum aggregationTemporality */ - aggregationTemporality: EAggregationTemporality; - - /** Sum isMonotonic */ - isMonotonic?: boolean | null; -} - -/** Properties of a Histogram. */ -export interface IHistogram { - /** Histogram dataPoints */ - dataPoints: IHistogramDataPoint[]; - - /** Histogram aggregationTemporality */ - aggregationTemporality?: EAggregationTemporality; -} - -/** Properties of an ExponentialHistogram. */ -export interface IExponentialHistogram { - /** ExponentialHistogram dataPoints */ - dataPoints: IExponentialHistogramDataPoint[]; - - /** ExponentialHistogram aggregationTemporality */ - aggregationTemporality?: EAggregationTemporality; -} - -/** Properties of a Summary. */ -export interface ISummary { - /** Summary dataPoints */ - dataPoints: ISummaryDataPoint[]; -} - -/** Properties of a NumberDataPoint. */ -export interface INumberDataPoint { - /** NumberDataPoint attributes */ - attributes: IKeyValue[]; - - /** NumberDataPoint startTimeUnixNano */ - startTimeUnixNano?: Fixed64; - - /** NumberDataPoint timeUnixNano */ - timeUnixNano?: Fixed64; - - /** NumberDataPoint asDouble */ - asDouble?: number | null; - - /** NumberDataPoint asInt */ - asInt?: number; - - /** NumberDataPoint exemplars */ - exemplars?: IExemplar[]; - - /** NumberDataPoint flags */ - flags?: number; -} - -/** Properties of a HistogramDataPoint. */ -export interface IHistogramDataPoint { - /** HistogramDataPoint attributes */ - attributes?: IKeyValue[]; - - /** HistogramDataPoint startTimeUnixNano */ - startTimeUnixNano?: Fixed64; - - /** HistogramDataPoint timeUnixNano */ - timeUnixNano?: Fixed64; - - /** HistogramDataPoint count */ - count?: number; - - /** HistogramDataPoint sum */ - sum?: number; - - /** HistogramDataPoint bucketCounts */ - bucketCounts?: number[]; - - /** HistogramDataPoint explicitBounds */ - explicitBounds?: number[]; - - /** HistogramDataPoint exemplars */ - exemplars?: IExemplar[]; - - /** HistogramDataPoint flags */ - flags?: number; - - /** HistogramDataPoint min */ - min?: number; - - /** HistogramDataPoint max */ - max?: number; -} - -/** Properties of an ExponentialHistogramDataPoint. */ -export interface IExponentialHistogramDataPoint { - /** ExponentialHistogramDataPoint attributes */ - attributes?: IKeyValue[]; - - /** ExponentialHistogramDataPoint startTimeUnixNano */ - startTimeUnixNano?: Fixed64; - - /** ExponentialHistogramDataPoint timeUnixNano */ - timeUnixNano?: Fixed64; - - /** ExponentialHistogramDataPoint count */ - count?: number; - - /** ExponentialHistogramDataPoint sum */ - sum?: number; - - /** ExponentialHistogramDataPoint scale */ - scale?: number; - - /** ExponentialHistogramDataPoint zeroCount */ - zeroCount?: number; - - /** ExponentialHistogramDataPoint positive */ - positive?: IBuckets; - - /** ExponentialHistogramDataPoint negative */ - negative?: IBuckets; - - /** ExponentialHistogramDataPoint flags */ - flags?: number; - - /** ExponentialHistogramDataPoint exemplars */ - exemplars?: IExemplar[]; - - /** ExponentialHistogramDataPoint min */ - min?: number; - - /** ExponentialHistogramDataPoint max */ - max?: number; -} - -/** Properties of a SummaryDataPoint. */ -export interface ISummaryDataPoint { - /** SummaryDataPoint attributes */ - attributes?: IKeyValue[]; - - /** SummaryDataPoint startTimeUnixNano */ - startTimeUnixNano?: number; - - /** SummaryDataPoint timeUnixNano */ - timeUnixNano?: string; - - /** SummaryDataPoint count */ - count?: number; - - /** SummaryDataPoint sum */ - sum?: number; - - /** SummaryDataPoint quantileValues */ - quantileValues?: IValueAtQuantile[]; - - /** SummaryDataPoint flags */ - flags?: number; -} - -/** Properties of a ValueAtQuantile. */ -export interface IValueAtQuantile { - /** ValueAtQuantile quantile */ - quantile?: number; - - /** ValueAtQuantile value */ - value?: number; -} - -/** Properties of a Buckets. */ -export interface IBuckets { - /** Buckets offset */ - offset?: number; - - /** Buckets bucketCounts */ - bucketCounts?: number[]; -} - -/** Properties of an Exemplar. */ -export interface IExemplar { - /** Exemplar filteredAttributes */ - filteredAttributes?: IKeyValue[]; - - /** Exemplar timeUnixNano */ - timeUnixNano?: string; - - /** Exemplar asDouble */ - asDouble?: number; - - /** Exemplar asInt */ - asInt?: number; - - /** Exemplar spanId */ - spanId?: string | Uint8Array; - - /** Exemplar traceId */ - traceId?: string | Uint8Array; -} - /** * AggregationTemporality defines how a metric aggregator reports aggregated * values. It describes how those values relate to the time interval over * which they are aggregated. */ -export const enum EAggregationTemporality { +export enum EAggregationTemporality { /* UNSPECIFIED is the default AggregationTemporality, it MUST not be used. */ AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, @@ -365,3 +102,158 @@ export const enum EAggregationTemporality { value was reset (e.g. Prometheus). */ AGGREGATION_TEMPORALITY_CUMULATIVE = 2, } + +export const OtelResourceTypes = Type.Module({ + IExportMetricsServiceRequest: Type.Object({ + resourceMetrics: Type.Array(Type.Ref("IResourceMetrics")), + }), + IResourceMetrics: Type.Object({ + resource: Type.Optional(TResource), + scopeMetrics: Type.Array(Type.Ref("IScopeMetrics")), + schemaUrl: Type.Optional(Type.String()), + }), + IScopeMetrics: Type.Object({ + scope: Type.Optional(TInstrumentationScope), + metrics: Type.Array(Type.Ref("IMetric")), + schemaUrl: Type.Optional(Type.String()), + }), + IMetric: Type.Object({ + name: Type.String(), + description: Type.Optional(Type.String()), + unit: Type.Optional(Type.String()), + gauge: Type.Optional(Type.Ref("IGauge")), + sum: Type.Optional(Type.Ref("ISum")), + histogram: Type.Optional(Type.Ref("IHistogram")), + exponentialHistogram: Type.Optional(Type.Ref("IExponentialHistogram")), + summary: Type.Optional(Type.Ref("ISummary")), + }), + IGauge: Type.Object({ + dataPoints: Type.Array(Type.Ref("INumberDataPoint")), + }), + ISum: Type.Object({ + dataPoints: Type.Array(Type.Ref("INumberDataPoint")), + aggregationTemporality: Type.Enum(EAggregationTemporality), + isMonotonic: Type.Optional(Type.Union([Type.Boolean(), Type.Null()])), + }), + IHistogram: Type.Object({ + dataPoints: Type.Array(Type.Ref("IHistogramDataPoint")), + aggregationTemporality: Type.Optional(Type.Enum(EAggregationTemporality)), + }), + IExponentialHistogram: Type.Object({ + dataPoints: Type.Array(Type.Ref("IExponentialHistogramDataPoint")), + aggregationTemporality: Type.Optional(Type.Enum(EAggregationTemporality)), + }), + ISummary: Type.Object({ + dataPoints: Type.Array(Type.Ref("ISummaryDataPoint")), + }), + INumberDataPoint: Type.Object({ + attributes: Type.Array(TKeyValue), + startTimeUnixNano: Type.Optional(TFixed64), + timeUnixNano: Type.Optional(TFixed64), + asDouble: Type.Optional(Type.Union([Type.Number(), Type.Null()])), + asInt: Type.Optional(Type.Number()), + exemplars: Type.Optional(Type.Array(Type.Ref("IExemplar"))), + flags: Type.Optional(Type.Number()), + }), + IHistogramDataPoint: Type.Object({ + attributes: Type.Optional(Type.Array(TKeyValue)), + startTimeUnixNano: Type.Optional(TFixed64), + timeUnixNano: Type.Optional(TFixed64), + count: Type.Optional(Type.Number()), + sum: Type.Optional(Type.Number()), + bucketCounts: Type.Optional(Type.Array(Type.Number())), + explicitBounds: Type.Optional(Type.Array(Type.Number())), + exemplars: Type.Optional(Type.Array(Type.Ref("IExemplar"))), + flags: Type.Optional(Type.Number()), + min: Type.Optional(Type.Number()), + max: Type.Optional(Type.Number()), + }), + IExponentialHistogramDataPoint: Type.Object({ + attributes: Type.Optional(Type.Array(TKeyValue)), + startTimeUnixNano: Type.Optional(TFixed64), + timeUnixNano: Type.Optional(TFixed64), + count: Type.Optional(Type.Number()), + sum: Type.Optional(Type.Number()), + scale: Type.Optional(Type.Number()), + zeroCount: Type.Optional(Type.Number()), + positive: Type.Optional(Type.Ref("IBuckets")), + negative: Type.Optional(Type.Ref("IBuckets")), + flags: Type.Optional(Type.Number()), + exemplars: Type.Optional(Type.Array(Type.Ref("IExemplar"))), + min: Type.Optional(Type.Number()), + max: Type.Optional(Type.Number()), + }), + ISummaryDataPoint: Type.Object({ + attributes: Type.Optional(Type.Array(TKeyValue)), + startTimeUnixNano: Type.Optional(Type.Number()), + timeUnixNano: Type.Optional(Type.String()), + count: Type.Optional(Type.Number()), + sum: Type.Optional(Type.Number()), + quantileValues: Type.Optional(Type.Array(Type.Ref("IValueAtQuantile"))), + flags: Type.Optional(Type.Number()), + }), + IValueAtQuantile: Type.Object({ + quantile: Type.Optional(Type.Number()), + value: Type.Optional(Type.Number()), + }), + IBuckets: Type.Object({ + offset: Type.Optional(Type.Number()), + bucketCounts: Type.Optional(Type.Array(Type.Number())), + }), + IExemplar: Type.Object({ + filteredAttributes: Type.Optional(Type.Array(TKeyValue)), + timeUnixNano: Type.Optional(Type.String()), + asDouble: Type.Optional(Type.Number()), + asInt: Type.Optional(Type.Number()), + spanId: Type.Optional(Type.Union([Type.String(), Type.Uint8Array()])), + traceId: Type.Optional(Type.Union([Type.String(), Type.Uint8Array()])), + }), +}); + +export const TExportMetricsServiceRequest = OtelResourceTypes.Import("IExportMetricsServiceRequest"); +export type IExportMetricsServiceRequest = Static; + +export const TResourceMetrics = OtelResourceTypes.Import("IResourceMetrics"); +export type IResourceMetrics = Static; + +export const TScopeMetrics = OtelResourceTypes.Import("IScopeMetrics"); +export type IScopeMetrics = Static; + +export const TMetric = OtelResourceTypes.Import("IMetric"); +export type IMetric = Static; + +export const TGauge = OtelResourceTypes.Import("IGauge"); +export type IGauge = Static; + +export const TSum = OtelResourceTypes.Import("ISum"); +export type ISum = Static; + +export const THistogram = OtelResourceTypes.Import("IHistogram"); +export type IHistogram = Static; + +export const TExponentialHistogram = OtelResourceTypes.Import("IExponentialHistogram"); +export type IExponentialHistogram = Static; + +export const TSummary = OtelResourceTypes.Import("ISummary"); +export type ISummary = Static; + +export const TNumberDataPoint = OtelResourceTypes.Import("INumberDataPoint"); +export type INumberDataPoint = Static; + +export const THistogramDataPoint = OtelResourceTypes.Import("IHistogramDataPoint"); +export type IHistogramDataPoint = Static; + +export const TExponentialHistogramDataPoint = OtelResourceTypes.Import("IExponentialHistogramDataPoint"); +export type IExponentialHistogramDataPoint = Static; + +export const TSummaryDataPoint = OtelResourceTypes.Import("ISummaryDataPoint"); +export type ISummaryDataPoint = Static; + +export const TValueAtQuantile = OtelResourceTypes.Import("IValueAtQuantile"); +export type IValueAtQuantile = Static; + +export const TBuckets = OtelResourceTypes.Import("IBuckets"); +export type IBuckets = Static; + +export const TExemplar = OtelResourceTypes.Import("IExemplar"); +export type IExemplar = Static; diff --git a/experimental/packages/otlp-transformer/src/resource/types.ts b/experimental/packages/otlp-transformer/src/resource/types.ts index 7755b756e91..b85abaf399e 100644 --- a/experimental/packages/otlp-transformer/src/resource/types.ts +++ b/experimental/packages/otlp-transformer/src/resource/types.ts @@ -14,13 +14,15 @@ * limitations under the License. */ -import { IKeyValue } from '../common/types'; +import { TKeyValue } from '../common/types'; +import { Type, type Static } from "@sinclair/typebox"; -/** Properties of a Resource. */ -export interface IResource { - /** Resource attributes */ - attributes: IKeyValue[]; +export const OtelResourceTypes = Type.Module({ + IResource: Type.Object({ + attributes: Type.Array(TKeyValue), + droppedAttributesCount: Type.Number(), + }), +}); - /** Resource droppedAttributesCount */ - droppedAttributesCount: number; -} +export const TResource = OtelResourceTypes.Import("IResource"); +export type IResource = Static; diff --git a/experimental/packages/otlp-transformer/src/trace/types.ts b/experimental/packages/otlp-transformer/src/trace/types.ts index d32c85eb5a5..a3c361f6377 100644 --- a/experimental/packages/otlp-transformer/src/trace/types.ts +++ b/experimental/packages/otlp-transformer/src/trace/types.ts @@ -14,14 +14,9 @@ * limitations under the License. */ -import { Fixed64, IInstrumentationScope, IKeyValue } from '../common/types'; -import { IResource } from '../resource/types'; -/** Properties of an ExportTraceServiceRequest. */ -export interface IExportTraceServiceRequest { - /** ExportTraceServiceRequest resourceSpans */ - resourceSpans?: IResourceSpans[]; -} +import { TFixed64, TInstrumentationScope, TKeyValue, TResource } from '../common/types'; +import { Type, type Static } from "@sinclair/typebox"; export interface IExportTraceServiceResponse { /** ExportTraceServiceResponse partialSuccess */ @@ -36,78 +31,6 @@ export interface IExportTracePartialSuccess { errorMessage?: string; } -/** Properties of a ResourceSpans. */ -export interface IResourceSpans { - /** ResourceSpans resource */ - resource?: IResource; - - /** ResourceSpans scopeSpans */ - scopeSpans: IScopeSpans[]; - - /** ResourceSpans schemaUrl */ - schemaUrl?: string; -} - -/** Properties of an ScopeSpans. */ -export interface IScopeSpans { - /** IScopeSpans scope */ - scope?: IInstrumentationScope; - - /** IScopeSpans spans */ - spans?: ISpan[]; - - /** IScopeSpans schemaUrl */ - schemaUrl?: string | null; -} - -/** Properties of a Span. */ -export interface ISpan { - /** Span traceId */ - traceId: string | Uint8Array; - - /** Span spanId */ - spanId: string | Uint8Array; - - /** Span traceState */ - traceState?: string | null; - - /** Span parentSpanId */ - parentSpanId?: string | Uint8Array; - - /** Span name */ - name: string; - - /** Span kind */ - kind: ESpanKind; - - /** Span startTimeUnixNano */ - startTimeUnixNano: Fixed64; - - /** Span endTimeUnixNano */ - endTimeUnixNano: Fixed64; - - /** Span attributes */ - attributes: IKeyValue[]; - - /** Span droppedAttributesCount */ - droppedAttributesCount: number; - - /** Span events */ - events: IEvent[]; - - /** Span droppedEventsCount */ - droppedEventsCount: number; - - /** Span links */ - links: ILink[]; - - /** Span droppedLinksCount */ - droppedLinksCount: number; - - /** Span status */ - status: IStatus; -} - /** * SpanKind is the type of span. Can be used to specify additional relationships between spans * in addition to a parent/child relationship. @@ -144,17 +67,8 @@ export enum ESpanKind { SPAN_KIND_CONSUMER = 5, } -/** Properties of a Status. */ -export interface IStatus { - /** Status message */ - message?: string; - - /** Status code */ - code: EStatusCode; -} - /** StatusCode enum. */ -export const enum EStatusCode { +export enum EStatusCode { /** The default status. */ STATUS_CODE_UNSET = 0, /** The Span has been evaluated by an Application developers or Operator to have completed successfully. */ @@ -163,35 +77,73 @@ export const enum EStatusCode { STATUS_CODE_ERROR = 2, } -/** Properties of an Event. */ -export interface IEvent { - /** Event timeUnixNano */ - timeUnixNano: Fixed64; - - /** Event name */ - name: string; - - /** Event attributes */ - attributes: IKeyValue[]; - - /** Event droppedAttributesCount */ - droppedAttributesCount: number; -} - -/** Properties of a Link. */ -export interface ILink { - /** Link traceId */ - traceId: string | Uint8Array; - - /** Link spanId */ - spanId: string | Uint8Array; - - /** Link traceState */ - traceState?: string; - - /** Link attributes */ - attributes: IKeyValue[]; - - /** Link droppedAttributesCount */ - droppedAttributesCount: number; -} +export const OtelResourceTypes = Type.Module({ + IExportTraceServiceRequest: Type.Object({ + resourceSpans: Type.Optional(Type.Array(Type.Ref("IResourceSpans"))), + }), + IResourceSpans: Type.Object({ + resource: Type.Optional(TResource), + scopeSpans: Type.Array(Type.Ref("IScopeSpans")), + schemaUrl: Type.Optional(Type.String()), + }), + IScopeSpans: Type.Object({ + scope: Type.Optional(TInstrumentationScope), + spans: Type.Optional(Type.Array(Type.Ref("ISpan"))), + schemaUrl: Type.Optional(Type.Union([Type.String(), Type.Null()])), + }), + ISpan: Type.Object({ + traceId: Type.Union([Type.String(), Type.Uint8Array()]), + spanId: Type.Union([Type.String(), Type.Uint8Array()]), + traceState: Type.Optional(Type.Union([Type.String(), Type.Null()])), + parentSpanId: Type.Optional(Type.Union([Type.String(), Type.Uint8Array()])), + name: Type.String(), + kind: Type.Enum(ESpanKind), + startTimeUnixNano: TFixed64, + endTimeUnixNano: TFixed64, + attributes: Type.Array(TKeyValue), + droppedAttributesCount: Type.Number(), + events: Type.Array(Type.Ref("IEvent")), + droppedEventsCount: Type.Number(), + links: Type.Array(Type.Ref("ILink")), + droppedLinksCount: Type.Number(), + status: Type.Ref("IStatus"), + }), + IStatus: Type.Object({ + message: Type.Optional(Type.String()), + code: Type.Enum(EStatusCode), + }), + IEvent: Type.Object({ + timeUnixNano: TFixed64, + name: Type.String(), + attributes: Type.Array(TKeyValue), + droppedAttributesCount: Type.Number(), + }), + ILink: Type.Object({ + traceId: Type.Union([Type.String(), Type.Uint8Array()]), + spanId: Type.Union([Type.String(), Type.Uint8Array()]), + traceState: Type.Optional(Type.String()), + attributes: Type.Array(TKeyValue), + droppedAttributesCount: Type.Number(), + }), +}); + +export const TExportTraceServiceRequest = OtelResourceTypes.Import("IExportTraceServiceRequest"); +export type IExportTraceServiceRequest = Static; + +export const TResourceSpans = OtelResourceTypes.Import("IResourceSpans"); +export type IResourceSpans = Static; + +export const TScopeSpans = OtelResourceTypes.Import("IScopeSpans"); +export type IScopeSpans = Static; + +export const TSpan = OtelResourceTypes.Import("ISpan"); +export type ISpan = Static; + +export const TStatus = OtelResourceTypes.Import("IStatus"); +export type IStatus = Static; + +export const TEvent = OtelResourceTypes.Import("IEvent"); +export type IEvent = Static; + +export const TLink = OtelResourceTypes.Import("ILink"); +export type ILink = Static; diff --git a/package-lock.json b/package-lock.json index cc662cb348f..76b7395ca67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1167,6 +1167,7 @@ "@opentelemetry/sdk-logs": "0.56.0", "@opentelemetry/sdk-metrics": "1.29.0", "@opentelemetry/sdk-trace-base": "1.29.0", + "@sinclair/typebox": "0.34.11", "protobufjs": "^7.3.0" }, "devDependencies": { @@ -1186,7 +1187,7 @@ "nyc": "15.1.0", "protobufjs-cli": "1.1.3", "ts-loader": "9.5.1", - "typescript": "4.4.4", + "typescript": "5.7.2", "webpack": "5.96.1" }, "engines": { @@ -1196,6 +1197,26 @@ "@opentelemetry/api": "^1.3.0" } }, + "experimental/packages/otlp-transformer/node_modules/@sinclair/typebox": { + "version": "0.34.11", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.11.tgz", + "integrity": "sha512-zE9pWGVSG82z+sFO+oUmqmqRVm8Wg5sVhmljYi1fDhLOSphBBy939QmC/qXcKFWqTiRJ6keyG4y75bIoTPRBAw==", + "license": "MIT" + }, + "experimental/packages/otlp-transformer/node_modules/typescript": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "experimental/packages/sampler-jaeger-remote": { "name": "@opentelemetry/sampler-jaeger-remote", "version": "0.56.0", @@ -32466,6 +32487,7 @@ "@opentelemetry/sdk-logs": "0.56.0", "@opentelemetry/sdk-metrics": "1.29.0", "@opentelemetry/sdk-trace-base": "1.29.0", + "@sinclair/typebox": "0.34.11", "@types/mocha": "10.0.10", "@types/webpack-env": "1.16.3", "babel-plugin-istanbul": "7.0.0", @@ -32482,8 +32504,21 @@ "protobufjs": "^7.3.0", "protobufjs-cli": "1.1.3", "ts-loader": "9.5.1", - "typescript": "4.4.4", + "typescript": "5.7.2", "webpack": "5.96.1" + }, + "dependencies": { + "@sinclair/typebox": { + "version": "0.34.11", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.11.tgz", + "integrity": "sha512-zE9pWGVSG82z+sFO+oUmqmqRVm8Wg5sVhmljYi1fDhLOSphBBy939QmC/qXcKFWqTiRJ6keyG4y75bIoTPRBAw==" + }, + "typescript": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "dev": true + } } }, "@opentelemetry/propagator-b3": {