Skip to content

Commit 629db8c

Browse files
dahliaclaude
andcommitted
Add gRPC and http/protobuf protocol support to @logtape/otel
This change adds support for gRPC and http/protobuf protocols in the OpenTelemetry sink, addressing issue #103. The protocol is automatically selected based on environment variables: - OTEL_EXPORTER_OTLP_LOGS_PROTOCOL (highest priority) - OTEL_EXPORTER_OTLP_PROTOCOL (fallback) - Default: http/json (for backward compatibility) Key changes: - Add @opentelemetry/exporter-logs-otlp-grpc and @opentelemetry/exporter-logs-otlp-proto dependencies - Refactor OpenTelemetrySinkOptions to union type (provider vs exporter) - Implement lazy initialization for browser compatibility with gRPC - Use dynamic imports to avoid loading gRPC code in browsers - Update OpenTelemetry SDK versions to 0.208.0 - Return Sink & AsyncDisposable type for proper cleanup - Expand test suite from 10 to 35 comprehensive tests - Update documentation with protocol selection section Closes #103 Co-Authored-By: Claude <[email protected]>
1 parent e7f3e5b commit 629db8c

File tree

8 files changed

+1401
-156
lines changed

8 files changed

+1401
-156
lines changed

CHANGES.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@ To be released.
4040

4141
[#102]: https://github.com/dahlia/logtape/issues/102
4242

43+
### @logtape/otel
44+
45+
- Added support for gRPC and HTTP/Protobuf protocols for OTLP log export.
46+
[[#103]]
47+
48+
- Added `@opentelemetry/exporter-logs-otlp-grpc` dependency for gRPC
49+
protocol support.
50+
51+
- Added `@opentelemetry/exporter-logs-otlp-proto` dependency for
52+
HTTP/Protobuf protocol support.
53+
54+
- Protocol is determined by environment variables following the
55+
OpenTelemetry specification:
56+
57+
1. `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL` (highest priority)
58+
2. `OTEL_EXPORTER_OTLP_PROTOCOL` (fallback)
59+
3. Default: `"http/json"` (for backward compatibility)
60+
61+
- Added `OtlpProtocol` type for protocol values (`"grpc"`,
62+
`"http/protobuf"`, `"http/json"`).
63+
64+
- Uses dynamic imports to maintain browser compatibility when gRPC
65+
is not used.
66+
67+
- Refactored `OpenTelemetrySinkOptions` to a discriminated union type for
68+
better type safety.
69+
70+
- Added `OpenTelemetrySinkProviderOptions` interface for providing a custom
71+
`LoggerProvider` (recommended for production use).
72+
- Added `OpenTelemetrySinkExporterOptions` interface for automatic exporter
73+
creation based on environment variables.
74+
- `loggerProvider` and exporter options (`serviceName`,
75+
`otlpExporterConfig`) are now mutually exclusive at the type level.
76+
77+
- Changed the exporter initialization to use lazy loading. The exporter
78+
is now created asynchronously when the first log record is emitted,
79+
rather than synchronously when `getOpenTelemetrySink()` is called.
80+
This allows the main API to remain synchronous while supporting
81+
dynamic imports for protocol selection.
82+
83+
[#103]: https://github.com/dahlia/logtape/issues/103
84+
4385

4486
Version 1.2.2
4587
-------------

0 commit comments

Comments
 (0)