opentelemetry-js/experimental/packages/otlp-transformer
Daniel Dyla 595d0e9c0d
Converge sync and async resources (#5350)
2025-02-03 19:52:16 +00:00
..
protos@1608f92cf0 feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00
src feat(core)!: remove deprecated InstrumentationLibrary (#5308) 2025-01-10 10:20:09 +00:00
test Converge sync and async resources (#5350) 2025-02-03 19:52:16 +00:00
.eslintignore feat(proto): add @opentelemetry/otlp-transformer package with hand-rolled transformation (#2746) 2022-03-23 13:51:15 -04:00
.eslintrc.js chore(deps): update dependency eslint to v8.43.0 (#3929) 2023-07-06 15:14:56 +02:00
.gitignore feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00
README.md feat(otlp-transformer)!: remove internal types and functions from public API (#5200) 2024-12-05 13:11:01 +00:00
karma.conf.js feat(proto): add @opentelemetry/otlp-transformer package with hand-rolled transformation (#2746) 2022-03-23 13:51:15 -04:00
package.json chore!: bump min-supported node to ^18.19.0 || >=20.6.0 (#5397) 2025-01-31 09:18:27 +00:00
submodule.md feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00
tsconfig.esm.json feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00
tsconfig.esnext.json feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00
tsconfig.json feat!: move serialization to `@opentelemetry/otlp-transformer` (#4542) 2024-04-26 16:11:38 +02:00

README.md

OpenTelemetry Protocol

NPM Published Version Apache License

Note: This package is intended for internal use only.

Note: This is an experimental package under active development. New releases may include breaking changes.

This package provides everything needed to serialize OpenTelemetry SDK traces, metrics and logs into the OpenTelemetry Protocol format.

Quick Start

To get started you will need to install a compatible OpenTelemetry API.

Install Peer Dependencies

npm install @opentelemetry/api

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.

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);

License

Apache 2.0 - See LICENSE for more information.