From ec2720d34cc9d4d8985c0ec149023fb67a3ac549 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Fri, 13 Dec 2024 13:17:47 +0100 Subject: [PATCH] feat(otlp-transformer)!: use factory functions over constants to better allow keeping state in the future --- experimental/CHANGELOG.md | 18 ++++ .../src/OTLPLogExporter.ts | 4 +- .../src/platform/browser/OTLPLogExporter.ts | 4 +- .../src/platform/node/OTLPLogExporter.ts | 4 +- .../src/platform/browser/OTLPLogExporter.ts | 4 +- .../src/platform/node/OTLPLogExporter.ts | 4 +- .../src/OTLPTraceExporter.ts | 4 +- .../src/platform/browser/OTLPTraceExporter.ts | 4 +- .../src/platform/node/OTLPTraceExporter.ts | 4 +- .../src/platform/browser/OTLPTraceExporter.ts | 4 +- .../src/platform/node/OTLPTraceExporter.ts | 4 +- .../src/OTLPMetricExporter.ts | 4 +- .../platform/browser/OTLPMetricExporter.ts | 4 +- .../src/platform/node/OTLPMetricExporter.ts | 4 +- .../src/OTLPMetricExporter.ts | 4 +- .../packages/otlp-transformer/README.md | 99 ++++++++++--------- .../packages/otlp-transformer/src/index.ts | 1 + .../otlp-transformer/src/logs/index.ts | 1 + .../otlp-transformer/src/logs/json/index.ts | 3 +- .../otlp-transformer/src/logs/json/logs.ts | 32 +++--- .../src/logs/protobuf/index.ts | 3 +- .../src/logs/protobuf/logs.ts | 22 +++-- .../otlp-transformer/src/metrics/index.ts | 1 + .../src/metrics/json/index.ts | 3 +- .../src/metrics/json/metrics.ts | 30 +++--- .../src/metrics/protobuf/index.ts | 3 +- .../src/metrics/protobuf/metrics.ts | 22 +++-- .../otlp-transformer/src/trace/index.ts | 1 + .../otlp-transformer/src/trace/json/index.ts | 3 +- .../otlp-transformer/src/trace/json/trace.ts | 32 +++--- .../src/trace/protobuf/index.ts | 3 +- .../src/trace/protobuf/trace.ts | 22 +++-- .../otlp-transformer/test/logs.test.ts | 21 ++-- .../otlp-transformer/test/metrics.test.ts | 12 +-- .../otlp-transformer/test/trace.test.ts | 19 ++-- 35 files changed, 231 insertions(+), 176 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index fb1383cb57..c04cd2330b 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -9,6 +9,24 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) +* feat(oltp-transformer)!: move each serializer to its own entrypoint + * This package depends on all signals, as well as `protobuf.js`, so some bundlers like rollup would issue warnings even if the user made a conscious decision to not use a protobuf exporter + * (user-facing) All types except for `ISerializer` were removed from the main entrypoint, to get previously exported types, use the following entrypoints + * `@opentelemetry/otlp-transformer/metrics`: metrics export service return types + * `@opentelemetry/otlp-transformer/metrics/json`: metrics json serializer + * `@opentelemetry/otlp-transformer/metrics/protobuf`: metrics protobuf serializer + * `@opentelemetry/otlp-transformer/trace`: trace export service return types + * `@opentelemetry/otlp-transformer/trace/trace`: trace json serializer + * `@opentelemetry/otlp-transformer/trace/protobuf`: trace protobuf serializer + * `@opentelemetry/otlp-transformer/logs`: logs export service return types + * `@opentelemetry/otlp-transformer/logs/trace`: logs export service return types + * `@opentelemetry/otlp-transformer/logs/protobuf`: logs export service return types +* feat(otlp-transformer)!: change serializer acquisition from constant to factory function + * (user-facing) serializer constant export have now been removed and replaced by factory functions + * to acquire a serializer, replace `Serializer` with `createSerializer()` + * example: `ProtobufMetricsSerializer` -> `createProtobufMetricsSerializer()` + * this was done to simplify future performance improvements without having to introduce additional APIs + ### :bug: (Bug Fix) ### :books: (Refine Doc) diff --git a/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts index 433ab76b85..67dce6d001 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts @@ -20,7 +20,7 @@ import { createOtlpGrpcExportDelegate, OTLPGRPCExporterConfigNode, } from '@opentelemetry/otlp-grpc-exporter-base'; -import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; +import { createProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; /** @@ -34,7 +34,7 @@ export class OTLPLogExporter super( createOtlpGrpcExportDelegate( convertLegacyOtlpGrpcOptions(config, 'LOGS'), - ProtobufLogsSerializer, + createProtobufLogsSerializer(), 'LogsExportService', '/opentelemetry.proto.collector.logs.v1.LogsService/Export' ) diff --git a/experimental/packages/exporter-logs-otlp-http/src/platform/browser/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-http/src/platform/browser/OTLPLogExporter.ts index 024256d840..1f257c5616 100644 --- a/experimental/packages/exporter-logs-otlp-http/src/platform/browser/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-http/src/platform/browser/OTLPLogExporter.ts @@ -21,7 +21,7 @@ import type { import type { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http'; -import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json'; +import { createJsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json'; /** * Collector Logs Exporter for Web @@ -34,7 +34,7 @@ export class OTLPLogExporter super( createLegacyOtlpBrowserExportDelegate( config, - JsonLogsSerializer, + createJsonLogsSerializer(), 'v1/logs', { 'Content-Type': 'application/json' } ) diff --git a/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts index 40c0fd12cd..134a31487a 100644 --- a/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts @@ -20,7 +20,7 @@ import type { } from '@opentelemetry/sdk-logs'; import type { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; -import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json'; +import { createJsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json'; import { VERSION } from '../../version'; import { convertLegacyHttpOptions, @@ -41,7 +41,7 @@ export class OTLPLogExporter 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, 'Content-Type': 'application/json', }), - JsonLogsSerializer + createJsonLogsSerializer() ) ); } diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts index 19185f31cb..d4843e3a97 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts @@ -18,7 +18,7 @@ import { OTLPExporterConfigBase, OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base'; -import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; +import { createProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; import { ReadableLogRecord, LogRecordExporter } from '@opentelemetry/sdk-logs'; import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http'; @@ -34,7 +34,7 @@ export class OTLPLogExporter super( createLegacyOtlpBrowserExportDelegate( config, - ProtobufLogsSerializer, + createProtobufLogsSerializer(), 'v1/logs', { 'Content-Type': 'application/x-protobuf' } ) diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts index ec07f45a86..34a2fb37fd 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts @@ -18,7 +18,7 @@ import { OTLPExporterBase, OTLPExporterNodeConfigBase, } from '@opentelemetry/otlp-exporter-base'; -import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; +import { createProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; import { convertLegacyHttpOptions, createOtlpHttpExportDelegate, @@ -41,7 +41,7 @@ export class OTLPLogExporter 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, 'Content-Type': 'application/x-protobuf', }), - ProtobufLogsSerializer + createProtobufLogsSerializer() ) ); } diff --git a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts index 07fa578939..9194b9d964 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { createOtlpGrpcExportDelegate, OTLPGRPCExporterConfigNode, } from '@opentelemetry/otlp-grpc-exporter-base'; -import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; +import { createProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; /** @@ -34,7 +34,7 @@ export class OTLPTraceExporter super( createOtlpGrpcExportDelegate( convertLegacyOtlpGrpcOptions(config, 'TRACES'), - ProtobufTraceSerializer, + createProtobufTraceSerializer(), 'TraceExportService', '/opentelemetry.proto.collector.trace.v1.TraceService/Export' ) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index baaebb2503..c837997530 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -19,7 +19,7 @@ import { OTLPExporterConfigBase, OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base'; -import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json'; +import { createJsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json'; import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http'; /** @@ -33,7 +33,7 @@ export class OTLPTraceExporter super( createLegacyOtlpBrowserExportDelegate( config, - JsonTraceSerializer, + createJsonTraceSerializer(), 'v1/traces', { 'Content-Type': 'application/json' } ) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 9d307db18a..65a1c4c413 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base'; import { VERSION } from '../../version'; -import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json'; +import { createJsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json'; import { convertLegacyHttpOptions, createOtlpHttpExportDelegate, @@ -40,7 +40,7 @@ export class OTLPTraceExporter 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, 'Content-Type': 'application/json', }), - JsonTraceSerializer + createJsonTraceSerializer() ) ); } diff --git a/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts index a5c47809c5..77715504ea 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts @@ -19,7 +19,7 @@ import { OTLPExporterConfigBase, OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base'; -import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; +import { createProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; @@ -35,7 +35,7 @@ export class OTLPTraceExporter super( createLegacyOtlpBrowserExportDelegate( config, - ProtobufTraceSerializer, + createProtobufTraceSerializer(), DEFAULT_COLLECTOR_RESOURCE_PATH, { 'Content-Type': 'application/x-protobuf' } ) diff --git a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts index 6697b56f99..e28e779ca7 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts @@ -19,7 +19,7 @@ import { OTLPExporterNodeConfigBase, OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base'; -import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; +import { createProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf'; import { VERSION } from '../../version'; import { createOtlpHttpExportDelegate, @@ -40,7 +40,7 @@ export class OTLPTraceExporter 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, 'Content-Type': 'application/x-protobuf', }), - ProtobufTraceSerializer + createProtobufTraceSerializer() ) ); } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts index d8838f146d..c31dd073ee 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -23,7 +23,7 @@ import { createOtlpGrpcExportDelegate, OTLPGRPCExporterConfigNode, } from '@opentelemetry/otlp-grpc-exporter-base'; -import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf'; +import { createProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf'; /** * OTLP-gRPC metric exporter @@ -33,7 +33,7 @@ export class OTLPMetricExporter extends OTLPMetricExporterBase { super( createOtlpGrpcExportDelegate( convertLegacyOtlpGrpcOptions(config ?? {}, 'METRICS'), - ProtobufMetricsSerializer, + createProtobufMetricsSerializer(), 'MetricsExportService', '/opentelemetry.proto.collector.metrics.v1.MetricsService/Export' ), diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index d9a6155ccb..7728e3964b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -17,7 +17,7 @@ import { OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions'; import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase'; import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { JsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json'; +import { createJsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json'; import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http'; /** @@ -28,7 +28,7 @@ export class OTLPMetricExporter extends OTLPMetricExporterBase { super( createLegacyOtlpBrowserExportDelegate( config ?? {}, - JsonMetricsSerializer, + createJsonMetricsSerializer(), 'v1/metrics', { 'Content-Type': 'application/json' } ) diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index fbdb369712..db82350a1e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -17,7 +17,7 @@ import { OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions'; import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { JsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json'; +import { createJsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json'; import { VERSION } from '../../version'; import { convertLegacyHttpOptions, @@ -39,7 +39,7 @@ export class OTLPMetricExporter extends OTLPMetricExporterBase { ...USER_AGENT, 'Content-Type': 'application/json', }), - JsonMetricsSerializer + createJsonMetricsSerializer() ), config ); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 1947972327..14893e0570 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -17,7 +17,7 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-http'; import { OTLPMetricExporterBase } from '@opentelemetry/exporter-metrics-otlp-http'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf'; +import { createProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf'; import { VERSION } from './version'; import { convertLegacyHttpOptions, @@ -32,7 +32,7 @@ export class OTLPMetricExporter extends OTLPMetricExporterBase { 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, 'Content-Type': 'application/x-protobuf', }), - ProtobufMetricsSerializer + createProtobufMetricsSerializer() ), config ); diff --git a/experimental/packages/otlp-transformer/README.md b/experimental/packages/otlp-transformer/README.md index bf16717479..2e57ed003f 100644 --- a/experimental/packages/otlp-transformer/README.md +++ b/experimental/packages/otlp-transformer/README.md @@ -19,21 +19,12 @@ To get started you will need to install a compatible OpenTelemetry API. npm install @opentelemetry/api ``` -### Entrypoints - -Since this package depends on all signals, and protobuf.js for serialization, -this package offers multiple entrypoints to avoid polluting the app during bundling. - -- `@opentelmetry/otlp-transformer` interfaces used by every signal -- `@opentelmetry/otlp-transformer/metrics` interfaces used by metrics -- `@opentelmetry/otlp-transformer/metrics/protobuf` OTLP protobuf serialization for metrics -- `@opentelmetry/otlp-transformer/metrics/json` OTLP JSON serialization for metrics -- `@opentelmetry/otlp-transformer/trace` interfaces used by trace -- `@opentelmetry/otlp-transformer/trace/protobuf` OTLP protobuf serialization for trace -- `@opentelmetry/otlp-transformer/trace/json` OTLP JSON serialization for trace -- `@opentelmetry/otlp-transformer/experimental/logs` interfaces used by logs -- `@opentelmetry/otlp-transformer/experimental/logs/protobuf` OTLP protobuf serialization for logs -- `@opentelmetry/otlp-transformer/experimental/logs/json` OTLP JSON serialization for logs +### Experimental Features and Entrypoint + +This package is currently marked as experimental. New minor versions may include breaking changes, regardless of +the entrypoint used. Once the package is marked as stable, only the `experimental/` entrypoint will break in +minor versions of the package. If you use experimental features it is therefore recommended to pin the package or use +to depend on a tilde-version. ### Serialize Traces/Metrics/Logs @@ -41,37 +32,53 @@ This module exports serializers to serialize traces, metrics and logs from the O or JSON which can be sent over HTTP or gRPC (protobuf-only) to the OpenTelemetry collector or a compatible receiver. ```typescript -import { - JsonLogsSerializer, - JsonMetricsSerializer, - JsonTraceSerializer, - ProtobufLogsSerializer, - ProtobufMetricsSerializer, - ProtobufTraceSerializer, - IExportLogsServiceResponse, - IExportMetricsServiceResponse, - IExportTraceServiceResponse, -} from '@opentelemetry/otlp-transformer'; - -// serialize to JSON export requests -const serializedJsonLogs: Uint8Array = JsonLogsSerializer.serializeRequest(readableLogRecords); -const serializedJsonMetrics: Uint8Array = JsonMetricsSerializer.serializeRequest(resourceMetrics); -const serializedJsonTraces: Uint8Array = JsonTraceSerializer.serializeRequest(readableSpans); - -// serialize to Protobuf export requests -const serializedProtobufLogs: Uint8Array = ProtobufLogsSerializer.serializeRequest(readableLogRecords); -const serializedProtobufMetrics: Uint8Array = ProtobufMetricsSerializer.serializeRequest(resourceMetrics); -const serializedProtobufTraces: Uint8Array = ProtobufTraceSerializer.serializeRequest(readableSpans); - -// deserialize JSON export responses -const deserializedJsonLogResponse: IExportLogsServiceResponse = JsonLogsSerializer.deserializeResponse(jsonLogResponse); -const deserializedJsonMetricsResponse: IExportMetricsServiceResponse = JsonMetricsSerializer.deserializeResponse(jsonMetricsResponse); -const deserializedJsonTraceResponse: IExportTraceServiceResponse = JsonTraceSerializer.deserializeResponse(jsonTraceResponse); - -// deserialize Protobuf export responses -const deserializedProtobufLogResponse: IExportLogsServiceResponse = ProtobufLogsSerializer.deserializeResponse(protobufLogResponse); -const deserializedProtobufMetricsResponse: IExportMetricsServiceResponse = ProtobufMetricsSerializer.deserializeResponse(protobufMetricsResponse); -const deserializedProtobufTraceResponse: IExportTraceServiceResponse = ProtobufTraceSerializer.deserializeResponse(protobufTraceResponse); +// Logs (protobuf) - experimental +import {IExportLogsServiceResponse} from '@opentelemetry/otlp-transformer/experimental/logs'; +import {createProtobufLogsSerializer} from '@opentelemetry/otlp-transformer/experimental/logs/protobuf'; + +const protobufLogsSerializer = createProtobufTraceSerializer(); +const serializedProtobufLogs: Uint8Array = protobufLogsSerializer.serializeRequest(readableLogRecords); +const deserializedProtobufLogResponse: IExportLogsServiceResponse = protobufLogsSerializer.deserializeResponse(protobufLogResponse); + +// Logs (json) - experimental +import {IExportLogsServiceResponse} from '@opentelemetry/otlp-transformer/experimental/logs'; +import {createJsonLogsSerializer} from '@opentelemetry/otlp-transformer/experimental/logs/json'; + +const jsonLogsSerializer = createJsonLogsSerializer(); +const serializedJsonLogs: Uint8Array = jsonLogsSerializer.serializeRequest(readableLogRecords); +const deserializedJsonLogResponse: IExportLogsServiceResponse = jsonLogsSerializer.deserializeResponse(jsonLogResponse); + +// Metrics (protobuf) +import {IExportMetricsServiceResponse} from '@opentelemetry/otlp-transformer/metrics' +import {createProtobufMetricsSerializer} from '@opentelemetry/otlp-transformer/metrics/protobuf'; + +const protobufMetricsSerializer = createProtobufMetricsSerializer(); +const serializedProtobufMetrics: Uint8Array = protobufMetricsSerializer.serializeRequest(resourceMetrics); +const deserializedProtobufMetricsResponse: IExportMetricsServiceResponse = protobufMetricsSerializer.deserializeResponse(protobufMetricsResponse); + +// Metrics (json) +import {IExportMetricsServiceResponse} from '@opentelemetry/otlp-transformer/metrics' +import {createJsonMetricsSerializer} from '@opentelemetry/otlp-transformer/metrics/json'; + +const jsonMetricsSerializer = createJsonMetricsSerializer(); +const serializedJsonMetrics: Uint8Array = jsonMetricsSerializer.serializeRequest(resourceMetrics); +const deserializedJsonMetricsResponse: IExportMetricsServiceResponse = jsonMetricsSerializer.deserializeResponse(jsonMetricsResponse); + +// Traces (protobuf) +import {IExportTraceServiceResponse} from '@opentelemetry/otlp-transformer/trace' +import {createProtobufTraceSerializer} from '@opentelemetry/otlp-transformer/trace/protobuf'; + +const protobufTraceSerializer = createProtobufTraceSerializer(); +const serializedProtobufTraces: Uint8Array = protobufTraceSerializer.serializeRequest(readableSpans); +const deserializedProtobufTraceResponse: IExportTraceServiceResponse = protobufTraceSerializer.deserializeResponse(protobufTraceResponse); + +// Traces (json) +import {IExportTraceServiceResponse} from '@opentelemetry/otlp-transformer/trace' +import {createJsonTraceSerializer} from '@opentelemetry/otlp-transformer/trace/json'; + +const jsonTraceSerializer = createJsonTraceSerializer(); +const deserializedJsonTraceResponse: IExportTraceServiceResponse = jsonTraceSerializer.deserializeResponse(jsonTraceResponse); +const serializedJsonTraces: Uint8Array = jsonTraceSerializer.serializeRequest(readableSpans); ``` ## Useful links diff --git a/experimental/packages/otlp-transformer/src/index.ts b/experimental/packages/otlp-transformer/src/index.ts index 1ab1613071..295f82781f 100644 --- a/experimental/packages/otlp-transformer/src/index.ts +++ b/experimental/packages/otlp-transformer/src/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ +// IMPORTANT: exports added here are public export { ISerializer } from './i-serializer'; diff --git a/experimental/packages/otlp-transformer/src/logs/index.ts b/experimental/packages/otlp-transformer/src/logs/index.ts index 390463c486..2578d9b43a 100644 --- a/experimental/packages/otlp-transformer/src/logs/index.ts +++ b/experimental/packages/otlp-transformer/src/logs/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +// IMPORTANT: exports added here are public export { IExportLogsServiceResponse, IExportLogsPartialSuccess, diff --git a/experimental/packages/otlp-transformer/src/logs/json/index.ts b/experimental/packages/otlp-transformer/src/logs/json/index.ts index 89518efe7a..edae69cbf7 100644 --- a/experimental/packages/otlp-transformer/src/logs/json/index.ts +++ b/experimental/packages/otlp-transformer/src/logs/json/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { JsonLogsSerializer } from './logs'; +// IMPORTANT: exports added here are public +export { createJsonLogsSerializer } from './logs'; diff --git a/experimental/packages/otlp-transformer/src/logs/json/logs.ts b/experimental/packages/otlp-transformer/src/logs/json/logs.ts index b9e6f6b15c..c19a523e49 100644 --- a/experimental/packages/otlp-transformer/src/logs/json/logs.ts +++ b/experimental/packages/otlp-transformer/src/logs/json/logs.ts @@ -21,20 +21,22 @@ import { IExportLogsServiceResponse } from '../export-response'; /* * @experimental this serializer may receive breaking changes in minor versions, pin this package's version when using this constant */ -export const JsonLogsSerializer: ISerializer< +export function createJsonLogsSerializer(): ISerializer< ReadableLogRecord[], IExportLogsServiceResponse -> = { - serializeRequest: (arg: ReadableLogRecord[]) => { - const request = createExportLogsServiceRequest(arg, { - useHex: true, - useLongBits: false, - }); - const encoder = new TextEncoder(); - return encoder.encode(JSON.stringify(request)); - }, - deserializeResponse: (arg: Uint8Array) => { - const decoder = new TextDecoder(); - return JSON.parse(decoder.decode(arg)) as IExportLogsServiceResponse; - }, -}; +> { + return { + serializeRequest: (arg: ReadableLogRecord[]) => { + const request = createExportLogsServiceRequest(arg, { + useHex: true, + useLongBits: false, + }); + const encoder = new TextEncoder(); + return encoder.encode(JSON.stringify(request)); + }, + deserializeResponse: (arg: Uint8Array) => { + const decoder = new TextDecoder(); + return JSON.parse(decoder.decode(arg)) as IExportLogsServiceResponse; + }, + }; +} diff --git a/experimental/packages/otlp-transformer/src/logs/protobuf/index.ts b/experimental/packages/otlp-transformer/src/logs/protobuf/index.ts index af594b5bc2..9423f6d389 100644 --- a/experimental/packages/otlp-transformer/src/logs/protobuf/index.ts +++ b/experimental/packages/otlp-transformer/src/logs/protobuf/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { ProtobufLogsSerializer } from './logs'; +// IMPORTANT: exports added here are public +export { createProtobufLogsSerializer } from './logs'; diff --git a/experimental/packages/otlp-transformer/src/logs/protobuf/logs.ts b/experimental/packages/otlp-transformer/src/logs/protobuf/logs.ts index a5b32453b6..5877b5660e 100644 --- a/experimental/packages/otlp-transformer/src/logs/protobuf/logs.ts +++ b/experimental/packages/otlp-transformer/src/logs/protobuf/logs.ts @@ -32,15 +32,17 @@ const logsRequestType = root.opentelemetry.proto.collector.logs.v1 /* * @experimental this serializer may receive breaking changes in minor versions, pin this package's version when using this constant */ -export const ProtobufLogsSerializer: ISerializer< +export function createProtobufLogsSerializer(): ISerializer< ReadableLogRecord[], IExportLogsServiceResponse -> = { - serializeRequest: (arg: ReadableLogRecord[]) => { - const request = createExportLogsServiceRequest(arg); - return logsRequestType.encode(request).finish(); - }, - deserializeResponse: (arg: Uint8Array) => { - return logsResponseType.decode(arg); - }, -}; +> { + return { + serializeRequest: (arg: ReadableLogRecord[]) => { + const request = createExportLogsServiceRequest(arg); + return logsRequestType.encode(request).finish(); + }, + deserializeResponse: (arg: Uint8Array) => { + return logsResponseType.decode(arg); + }, + }; +} diff --git a/experimental/packages/otlp-transformer/src/metrics/index.ts b/experimental/packages/otlp-transformer/src/metrics/index.ts index 65ed0bfd71..288a0dbbc8 100644 --- a/experimental/packages/otlp-transformer/src/metrics/index.ts +++ b/experimental/packages/otlp-transformer/src/metrics/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +// IMPORTANT: exports added here are public export { IExportMetricsPartialSuccess, IExportMetricsServiceResponse, diff --git a/experimental/packages/otlp-transformer/src/metrics/json/index.ts b/experimental/packages/otlp-transformer/src/metrics/json/index.ts index 7da6e9c9a3..471f596568 100644 --- a/experimental/packages/otlp-transformer/src/metrics/json/index.ts +++ b/experimental/packages/otlp-transformer/src/metrics/json/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { JsonMetricsSerializer } from './metrics'; +// IMPORTANT: exports added here are public +export { createJsonMetricsSerializer } from './metrics'; diff --git a/experimental/packages/otlp-transformer/src/metrics/json/metrics.ts b/experimental/packages/otlp-transformer/src/metrics/json/metrics.ts index 9f7273cbc4..8f5bfb888e 100644 --- a/experimental/packages/otlp-transformer/src/metrics/json/metrics.ts +++ b/experimental/packages/otlp-transformer/src/metrics/json/metrics.ts @@ -18,19 +18,21 @@ import { ResourceMetrics } from '@opentelemetry/sdk-metrics'; import { createExportMetricsServiceRequest } from '../internal'; import { IExportMetricsServiceResponse } from '../export-response'; -export const JsonMetricsSerializer: ISerializer< +export function createJsonMetricsSerializer(): ISerializer< ResourceMetrics, IExportMetricsServiceResponse -> = { - serializeRequest: (arg: ResourceMetrics) => { - const request = createExportMetricsServiceRequest([arg], { - useLongBits: false, - }); - const encoder = new TextEncoder(); - return encoder.encode(JSON.stringify(request)); - }, - deserializeResponse: (arg: Uint8Array) => { - const decoder = new TextDecoder(); - return JSON.parse(decoder.decode(arg)) as IExportMetricsServiceResponse; - }, -}; +> { + return { + serializeRequest: (arg: ResourceMetrics) => { + const request = createExportMetricsServiceRequest([arg], { + useLongBits: false, + }); + const encoder = new TextEncoder(); + return encoder.encode(JSON.stringify(request)); + }, + deserializeResponse: (arg: Uint8Array) => { + const decoder = new TextDecoder(); + return JSON.parse(decoder.decode(arg)) as IExportMetricsServiceResponse; + }, + }; +} diff --git a/experimental/packages/otlp-transformer/src/metrics/protobuf/index.ts b/experimental/packages/otlp-transformer/src/metrics/protobuf/index.ts index 7332284411..842eaa226b 100644 --- a/experimental/packages/otlp-transformer/src/metrics/protobuf/index.ts +++ b/experimental/packages/otlp-transformer/src/metrics/protobuf/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { ProtobufMetricsSerializer } from './metrics'; +// IMPORTANT: exports added here are public +export { createProtobufMetricsSerializer } from './metrics'; diff --git a/experimental/packages/otlp-transformer/src/metrics/protobuf/metrics.ts b/experimental/packages/otlp-transformer/src/metrics/protobuf/metrics.ts index ee21ca93eb..739d1f7016 100644 --- a/experimental/packages/otlp-transformer/src/metrics/protobuf/metrics.ts +++ b/experimental/packages/otlp-transformer/src/metrics/protobuf/metrics.ts @@ -28,15 +28,17 @@ const metricsResponseType = root.opentelemetry.proto.collector.metrics.v1 const metricsRequestType = root.opentelemetry.proto.collector.metrics.v1 .ExportMetricsServiceRequest as ExportType; -export const ProtobufMetricsSerializer: ISerializer< +export function createProtobufMetricsSerializer(): ISerializer< ResourceMetrics, IExportMetricsServiceResponse -> = { - serializeRequest: (arg: ResourceMetrics) => { - const request = createExportMetricsServiceRequest([arg]); - return metricsRequestType.encode(request).finish(); - }, - deserializeResponse: (arg: Uint8Array) => { - return metricsResponseType.decode(arg); - }, -}; +> { + return { + serializeRequest: (arg: ResourceMetrics) => { + const request = createExportMetricsServiceRequest([arg]); + return metricsRequestType.encode(request).finish(); + }, + deserializeResponse: (arg: Uint8Array) => { + return metricsResponseType.decode(arg); + }, + }; +} diff --git a/experimental/packages/otlp-transformer/src/trace/index.ts b/experimental/packages/otlp-transformer/src/trace/index.ts index 3b21dc94f8..04ead47a2b 100644 --- a/experimental/packages/otlp-transformer/src/trace/index.ts +++ b/experimental/packages/otlp-transformer/src/trace/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +// IMPORTANT: exports added here are public export { IExportTracePartialSuccess, IExportTraceServiceResponse, diff --git a/experimental/packages/otlp-transformer/src/trace/json/index.ts b/experimental/packages/otlp-transformer/src/trace/json/index.ts index be6bb64643..552bc1931c 100644 --- a/experimental/packages/otlp-transformer/src/trace/json/index.ts +++ b/experimental/packages/otlp-transformer/src/trace/json/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { JsonTraceSerializer } from './trace'; +// IMPORTANT: exports added here are public +export { createJsonTraceSerializer } from './trace'; diff --git a/experimental/packages/otlp-transformer/src/trace/json/trace.ts b/experimental/packages/otlp-transformer/src/trace/json/trace.ts index da188b090a..c134fbc68c 100644 --- a/experimental/packages/otlp-transformer/src/trace/json/trace.ts +++ b/experimental/packages/otlp-transformer/src/trace/json/trace.ts @@ -18,20 +18,22 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { IExportTraceServiceResponse } from '../export-response'; import { createExportTraceServiceRequest } from '../internal'; -export const JsonTraceSerializer: ISerializer< +export function createJsonTraceSerializer(): ISerializer< ReadableSpan[], IExportTraceServiceResponse -> = { - serializeRequest: (arg: ReadableSpan[]) => { - const request = createExportTraceServiceRequest(arg, { - useHex: true, - useLongBits: false, - }); - const encoder = new TextEncoder(); - return encoder.encode(JSON.stringify(request)); - }, - deserializeResponse: (arg: Uint8Array) => { - const decoder = new TextDecoder(); - return JSON.parse(decoder.decode(arg)) as IExportTraceServiceResponse; - }, -}; +> { + return { + serializeRequest: (arg: ReadableSpan[]) => { + const request = createExportTraceServiceRequest(arg, { + useHex: true, + useLongBits: false, + }); + const encoder = new TextEncoder(); + return encoder.encode(JSON.stringify(request)); + }, + deserializeResponse: (arg: Uint8Array) => { + const decoder = new TextDecoder(); + return JSON.parse(decoder.decode(arg)) as IExportTraceServiceResponse; + }, + }; +} diff --git a/experimental/packages/otlp-transformer/src/trace/protobuf/index.ts b/experimental/packages/otlp-transformer/src/trace/protobuf/index.ts index fb34bd9baf..1c3479fdc0 100644 --- a/experimental/packages/otlp-transformer/src/trace/protobuf/index.ts +++ b/experimental/packages/otlp-transformer/src/trace/protobuf/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export { ProtobufTraceSerializer } from './trace'; +// IMPORTANT: exports added here are public +export { createProtobufTraceSerializer } from './trace'; diff --git a/experimental/packages/otlp-transformer/src/trace/protobuf/trace.ts b/experimental/packages/otlp-transformer/src/trace/protobuf/trace.ts index 87d5f481fe..c06db13e85 100644 --- a/experimental/packages/otlp-transformer/src/trace/protobuf/trace.ts +++ b/experimental/packages/otlp-transformer/src/trace/protobuf/trace.ts @@ -28,15 +28,17 @@ const traceResponseType = root.opentelemetry.proto.collector.trace.v1 const traceRequestType = root.opentelemetry.proto.collector.trace.v1 .ExportTraceServiceRequest as ExportType; -export const ProtobufTraceSerializer: ISerializer< +export function createProtobufTraceSerializer(): ISerializer< ReadableSpan[], IExportTraceServiceResponse -> = { - serializeRequest: (arg: ReadableSpan[]) => { - const request = createExportTraceServiceRequest(arg); - return traceRequestType.encode(request).finish(); - }, - deserializeResponse: (arg: Uint8Array) => { - return traceResponseType.decode(arg); - }, -}; +> { + return { + serializeRequest: (arg: ReadableSpan[]) => { + const request = createExportTraceServiceRequest(arg); + return traceRequestType.encode(request).finish(); + }, + deserializeResponse: (arg: Uint8Array) => { + return traceResponseType.decode(arg); + }, + }; +} diff --git a/experimental/packages/otlp-transformer/test/logs.test.ts b/experimental/packages/otlp-transformer/test/logs.test.ts index 4cf3c93090..40b1069cdf 100644 --- a/experimental/packages/otlp-transformer/test/logs.test.ts +++ b/experimental/packages/otlp-transformer/test/logs.test.ts @@ -27,8 +27,8 @@ import { IExportLogsServiceRequest, } from '../src/logs/internal-types'; import { createExportLogsServiceRequest } from '../src/logs/internal'; -import { ProtobufLogsSerializer } from '../src/logs/protobuf'; -import { JsonLogsSerializer } from '../src/logs/json'; +import { createProtobufLogsSerializer } from '../src/logs/protobuf'; +import { createJsonLogsSerializer } from '../src/logs/json'; function createExpectedLogJson( options: OtlpEncodingOptions @@ -293,7 +293,9 @@ describe('Logs', () => { describe('ProtobufLogsSerializer', function () { it('serializes an export request', () => { - const serialized = ProtobufLogsSerializer.serializeRequest([log_1_1_1]); + const serialized = createProtobufLogsSerializer().serializeRequest([ + log_1_1_1, + ]); assert.ok(serialized, 'serialized response is undefined'); const decoded = root.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest.decode( @@ -329,9 +331,10 @@ describe('Logs', () => { } ).finish(); - const deserializedResponse = ProtobufLogsSerializer.deserializeResponse( - protobufSerializedResponse - ); + const deserializedResponse = + createProtobufLogsSerializer().deserializeResponse( + protobufSerializedResponse + ); assert.ok( deserializedResponse.partialSuccess, @@ -353,7 +356,9 @@ describe('Logs', () => { createExpectedLogJson({ useHex: true, useLongBits: false }) ) ); - const serialized = JsonLogsSerializer.serializeRequest([log_1_1_1]); + const serialized = createJsonLogsSerializer().serializeRequest([ + log_1_1_1, + ]); const decoder = new TextDecoder(); assert.deepStrictEqual(JSON.parse(decoder.decode(serialized)), expected); @@ -370,7 +375,7 @@ describe('Logs', () => { const encodedResponse = encoder.encode(JSON.stringify(expectedResponse)); const deserializedResponse = - JsonLogsSerializer.deserializeResponse(encodedResponse); + createJsonLogsSerializer().deserializeResponse(encodedResponse); assert.ok( deserializedResponse.partialSuccess, diff --git a/experimental/packages/otlp-transformer/test/metrics.test.ts b/experimental/packages/otlp-transformer/test/metrics.test.ts index 5ad8615548..0b76a491a3 100644 --- a/experimental/packages/otlp-transformer/test/metrics.test.ts +++ b/experimental/packages/otlp-transformer/test/metrics.test.ts @@ -28,8 +28,8 @@ import { EAggregationTemporality } from '../src/metrics/internal-types'; import { hrTime, hrTimeToNanoseconds } from '@opentelemetry/core'; import * as root from '../src/generated/root'; import { encodeAsLongBits, encodeAsString } from '../src/common/utils'; -import { ProtobufMetricsSerializer } from '../src/metrics/protobuf'; -import { JsonMetricsSerializer } from '../src/metrics/json'; +import { createProtobufMetricsSerializer } from '../src/metrics/protobuf'; +import { createJsonMetricsSerializer } from '../src/metrics/json'; const START_TIME = hrTime(); const END_TIME = hrTime(); @@ -785,7 +785,7 @@ describe('Metrics', () => { describe('ProtobufMetricsSerializer', function () { it('serializes an export request', () => { - const serialized = ProtobufMetricsSerializer.serializeRequest( + const serialized = createProtobufMetricsSerializer().serializeRequest( createResourceMetrics([ createCounterData(10, AggregationTemporality.DELTA), ]) @@ -852,7 +852,7 @@ describe('Metrics', () => { ).finish(); const deserializedResponse = - ProtobufMetricsSerializer.deserializeResponse( + createProtobufMetricsSerializer().deserializeResponse( protobufSerializedResponse ); @@ -870,7 +870,7 @@ describe('Metrics', () => { describe('JsonMetricsSerializer', function () { it('serializes an export request', () => { - const serialized = JsonMetricsSerializer.serializeRequest( + const serialized = createJsonMetricsSerializer().serializeRequest( createResourceMetrics([ createCounterData(10, AggregationTemporality.DELTA), ]) @@ -925,7 +925,7 @@ describe('Metrics', () => { const encodedResponse = encoder.encode(JSON.stringify(expectedResponse)); const deserializedResponse = - JsonMetricsSerializer.deserializeResponse(encodedResponse); + createJsonMetricsSerializer().deserializeResponse(encodedResponse); assert.ok( deserializedResponse.partialSuccess, diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index 81ad9eb2cc..9bba96e8ef 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -23,8 +23,8 @@ import { toBase64 } from './utils'; import { OtlpEncodingOptions } from '../src/common/internal-types'; import { ESpanKind, EStatusCode } from '../src/trace/internal-types'; import { createExportTraceServiceRequest } from '../src/trace/internal'; -import { ProtobufTraceSerializer } from '../src/trace/protobuf'; -import { JsonTraceSerializer } from '../src/trace/json'; +import { createProtobufTraceSerializer } from '../src/trace/protobuf'; +import { createJsonTraceSerializer } from '../src/trace/json'; function createExpectedSpanJson(options: OtlpEncodingOptions) { const useHex = options.useHex ?? false; @@ -439,7 +439,9 @@ describe('Trace', () => { describe('ProtobufTracesSerializer', function () { it('serializes an export request', () => { - const serialized = ProtobufTraceSerializer.serializeRequest([span]); + const serialized = createProtobufTraceSerializer().serializeRequest([ + span, + ]); assert.ok(serialized, 'serialized response is undefined'); const decoded = root.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest.decode( @@ -475,9 +477,10 @@ describe('Trace', () => { } ).finish(); - const deserializedResponse = ProtobufTraceSerializer.deserializeResponse( - protobufSerializedResponse - ); + const deserializedResponse = + createProtobufTraceSerializer().deserializeResponse( + protobufSerializedResponse + ); assert.ok( deserializedResponse.partialSuccess, @@ -502,7 +505,7 @@ describe('Trace', () => { }) ) ); - const serialized = JsonTraceSerializer.serializeRequest([span]); + const serialized = createJsonTraceSerializer().serializeRequest([span]); const decoder = new TextDecoder(); assert.deepStrictEqual(JSON.parse(decoder.decode(serialized)), expected); @@ -519,7 +522,7 @@ describe('Trace', () => { const encodedResponse = encoder.encode(JSON.stringify(expectedResponse)); const deserializedResponse = - JsonTraceSerializer.deserializeResponse(encodedResponse); + createJsonTraceSerializer().deserializeResponse(encodedResponse); assert.ok( deserializedResponse.partialSuccess,