Skip to content

Commit

Permalink
feat(oltp-transformer)!: introduce sparate entry-points
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Dec 13, 2024
1 parent 5ad61ec commit 8c1c6be
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 57 deletions.
12 changes: 12 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ All notable changes to experimental packages in this project will be documented
### :rocket: (Enhancement)

* feat(opentelemetry-sdk-node): automatically configure metrics exporter based on environment variables [#5168](https://github.com/open-telemetry/opentelemetry-js/pull/5168) @bhaskarbanerjee
* feat(oltp-transformer)!: move each serializer to its own entrypoint [#5263](https://github.com/open-telemetry/opentelemetry-js/pull/5263) @pichlermarc
* 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

### :bug: (Bug Fix)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createOtlpGrpcExportDelegate,
OTLPGRPCExporterConfigNode,
} from '@opentelemetry/otlp-grpc-exporter-base';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf';
import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import type {
} from '@opentelemetry/sdk-logs';
import type { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';
import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer';
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';
import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json';

/**
* Collector Logs Exporter for Web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json';
import { VERSION } from '../../version';
import {
convertLegacyHttpOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
OTLPExporterConfigBase,
OTLPExporterBase,
} from '@opentelemetry/otlp-exporter-base';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf';

import { ReadableLogRecord, LogRecordExporter } from '@opentelemetry/sdk-logs';
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
OTLPExporterBase,
OTLPExporterNodeConfigBase,
} from '@opentelemetry/otlp-exporter-base';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf';
import {
convertLegacyHttpOptions,
createOtlpHttpExportDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createOtlpGrpcExportDelegate,
OTLPGRPCExporterConfigNode,
} from '@opentelemetry/otlp-grpc-exporter-base';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf';
import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
OTLPExporterConfigBase,
OTLPExporterBase,
} from '@opentelemetry/otlp-exporter-base';
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json';
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
OTLPExporterBase,
} from '@opentelemetry/otlp-exporter-base';
import { VERSION } from '../../version';
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json';
import {
convertLegacyHttpOptions,
createOtlpHttpExportDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
OTLPExporterConfigBase,
OTLPExporterBase,
} from '@opentelemetry/otlp-exporter-base';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf';
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';

const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
OTLPExporterNodeConfigBase,
OTLPExporterBase,
} from '@opentelemetry/otlp-exporter-base';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf';
import { VERSION } from '../../version';
import {
createOtlpHttpExportDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
createOtlpGrpcExportDelegate,
OTLPGRPCExporterConfigNode,
} from '@opentelemetry/otlp-grpc-exporter-base';
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer';
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf';

/**
* OTLP-gRPC metric exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { JsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json';
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { JsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json';
import { VERSION } from '../../version';
import {
convertLegacyHttpOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf';
import { VERSION } from './version';
import {
convertLegacyHttpOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { createLoggingPartialSuccessResponseHandler } from '../../src/logging-response-handler';
import * as sinon from 'sinon';
import { IExportTraceServiceResponse } from '@opentelemetry/otlp-transformer';
import { IExportTraceServiceResponse } from '@opentelemetry/otlp-transformer/trace';
import { registerMockDiagLogger } from './test-utils';

describe('loggingResponseHandler', function () {
Expand Down
65 changes: 41 additions & 24 deletions experimental/packages/otlp-transformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,60 @@ To get started you will need to install a compatible OpenTelemetry API.
npm install @opentelemetry/api
```

### 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

This module exports serializers to serialize traces, metrics and logs from the OpenTelemetry SDK into protocol buffers
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);
// Logs (protobuf) - experimental
import { IExportLogsServiceResponse } from '@opentelemetry/otlp-transformer/experimental/logs';
import { ProtobufLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/protobuf';

// serialize to Protobuf export requests
const serializedProtobufLogs: Uint8Array = ProtobufLogsSerializer.serializeRequest(readableLogRecords);
const serializedProtobufMetrics: Uint8Array = ProtobufMetricsSerializer.serializeRequest(resourceMetrics);
const serializedProtobufTraces: Uint8Array = ProtobufTraceSerializer.serializeRequest(readableSpans);
const deserializedProtobufLogResponse: IExportLogsServiceResponse = ProtobufLogsSerializer.deserializeResponse(protobufLogResponse);

// Logs (json) - experimental
import { IExportLogsServiceResponse } from '@opentelemetry/otlp-transformer/experimental/logs';
import { JsonLogsSerializer } from '@opentelemetry/otlp-transformer/experimental/logs/json';

// deserialize JSON export responses
const serializedJsonLogs: Uint8Array = JsonLogsSerializer.serializeRequest(readableLogRecords);
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);
// Metrics (protobuf)
import { IExportMetricsServiceResponse } from '@opentelemetry/otlp-transformer/metrics'
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/protobuf';

const serializedProtobufMetrics: Uint8Array = ProtobufMetricsSerializer.serializeRequest(resourceMetrics);
const deserializedProtobufMetricsResponse: IExportMetricsServiceResponse = ProtobufMetricsSerializer.deserializeResponse(protobufMetricsResponse);

// Metrics (json)
import { IExportMetricsServiceResponse } from '@opentelemetry/otlp-transformer/metrics'
import { JsonMetricsSerializer } from '@opentelemetry/otlp-transformer/metrics/json';

const serializedJsonMetrics: Uint8Array = JsonMetricsSerializer.serializeRequest(resourceMetrics);
const deserializedJsonMetricsResponse: IExportMetricsServiceResponse = JsonMetricsSerializer.deserializeResponse(jsonMetricsResponse);

// Traces (protobuf)
import { IExportTraceServiceResponse } from '@opentelemetry/otlp-transformer/trace'
import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer/trace/protobuf';

const serializedProtobufTraces: Uint8Array = ProtobufTraceSerializer.serializeRequest(readableSpans);
const deserializedProtobufTraceResponse: IExportTraceServiceResponse = ProtobufTraceSerializer.deserializeResponse(protobufTraceResponse);

// Traces (json)
import { IExportTraceServiceResponse } from '@opentelemetry/otlp-transformer/trace'
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace/json';

const deserializedJsonTraceResponse: IExportTraceServiceResponse = JsonTraceSerializer.deserializeResponse(jsonTraceResponse);
const serializedJsonTraces: Uint8Array = JsonTraceSerializer.serializeRequest(readableSpans);
```

## Useful links
Expand Down
96 changes: 96 additions & 0 deletions experimental/packages/otlp-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,102 @@
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"main": "build/src/index.js",
"exports": {
".": {
"module": "./build/esm/index.js",
"esnext": "./build/esnext/index.js",
"types": "./build/src/index.d.ts",
"default": "./build/src/index.js"
},
"./metrics": {
"module": "./build/esm/metrics/index.js",
"esnext": "./build/esnext/metrics/index.js",
"types": "./build/src/metrics/index.d.ts",
"default": "./build/src/metrics/index.js"
},
"./metrics/protobuf": {
"module": "./build/esm/metrics/protobuf/index.js",
"esnext": "./build/esnext/metrics/protobuf/index.js",
"types": "./build/src/metrics/protobuf/index.d.ts",
"default": "./build/src/metrics/protobuf/index.js"
},
"./metrics/json": {
"module": "./build/esm/metrics/json/index.js",
"esnext": "./build/esnext/metrics/json/index.js",
"types": "./build/src/metrics/json/index.d.ts",
"default": "./build/src/metrics/json/index.js"
},
"./trace": {
"module": "./build/esm/trace/index.js",
"esnext": "./build/esnext/trace/index.js",
"types": "./build/src/trace/index.d.ts",
"default": "./build/src/trace/index.js"
},
"./trace/protobuf": {
"module": "./build/esm/trace/protobuf/index.js",
"esnext": "./build/esnext/trace/protobuf/index.js",
"types": "./build/src/trace/protobuf/index.d.ts",
"default": "./build/src/trace/protobuf/index.js"
},
"./trace/json": {
"module": "./build/esm/trace/json/index.js",
"esnext": "./build/esnext/trace/json/index.js",
"types": "./build/src/trace/json/index.d.ts",
"default": "./build/src/trace/json/index.js"
},
"./experimental/logs": {
"module": "./build/esm/logs/index.js",
"esnext": "./build/esnext/logs/index.js",
"types": "./build/src/logs/index.d.ts",
"default": "./build/src/logs/index.js"
},
"./experimental/logs/protobuf": {
"module": "./build/esm/logs/protobuf/index.js",
"esnext": "./build/esnext/logs/protobuf/index.js",
"types": "./build/src/logs/protobuf/index.d.ts",
"default": "./build/src/logs/protobuf/index.js"
},
"./experimental/logs/json": {
"module": "./build/esm/logs/json/index.js",
"esnext": "./build/esnext/logs/json/index.js",
"types": "./build/src/logs/json/index.d.ts",
"default": "./build/src/logs/json/index.js"
}
},
"typesVersions": {
"*": {
"*": [
"./build/src/index.d.ts"
],
"metrics": [
"./build/src/metrics/index.d.ts"
],
"metrics/protobuf": [
"./build/src/metrics/protobuf/index.d.ts"
],
"metrics/json": [
"./build/src/metrics/json/index.d.ts"
],
"trace": [
"./build/src/trace/index.d.ts"
],
"trace/protobuf": [
"./build/src/trace/protobuf/index.d.ts"
],
"trace/json": [
"./build/src/trace/json/index.d.ts"
],
"experimental/logs": [
"./build/src/logs/index.d.ts"
],
"experimental/logs/protobuf": [
"./build/src/logs/protobuf/index.d.ts"
],
"experimental/logs/json": [
"./build/src/logs/json/index.d.ts"
]
}
},
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"prepublishOnly": "npm run compile",
Expand Down
19 changes: 1 addition & 18 deletions experimental/packages/otlp-transformer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,5 @@
* limitations under the License.
*/

export {
IExportMetricsPartialSuccess,
IExportMetricsServiceResponse,
} from './metrics';
export {
IExportTracePartialSuccess,
IExportTraceServiceResponse,
} from './trace';
export { IExportLogsServiceResponse, IExportLogsPartialSuccess } from './logs';

export { ProtobufLogsSerializer } from './logs/protobuf';
export { ProtobufMetricsSerializer } from './metrics/protobuf';
export { ProtobufTraceSerializer } from './trace/protobuf';

export { JsonLogsSerializer } from './logs/json';
export { JsonMetricsSerializer } from './metrics/json';
export { JsonTraceSerializer } from './trace/json';

// IMPORTANT: exports added here are public
export { ISerializer } from './i-serializer';

0 comments on commit 8c1c6be

Please sign in to comment.