feat(otlp-exporter-base): add custom fetch option to OTLP HTTP exporters#6377
feat(otlp-exporter-base): add custom fetch option to OTLP HTTP exporters#6377zakcutner wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
40cb2d5 to
60b2f41
Compare
60b2f41 to
db5111b
Compare
|
@blumamir @hectorhdzg @JacksonWeber @martinkuba @maryliag @raphael-theriault-swi @svetlanabrennan Would it be possible for a review of these changes, when you get a moment? I'm also happy to open an issue for discussion or change the approach if you would prefer. Sorry for the pings by the way, the contributing guide included that I should @ the approvers on my PR. |
|
@zakcutner - my original idea was to provide an interface for people to pass their own transports to the exporters, because different transport implementations are so widely requested. My idea was that people would be able to do something like this, but I ran out of time to work on it: const exporter = createOtlpExporter({
serializer: ProtobufTraceSerializer,
transport: createMyCustomFetchTransport() // returns a custom IExporterTransport impl
});the underlying implementation is already somewhat setup for such a thing, but requires a bit more boilerplate import { createOtlpNetworkExportDelegate } from '@opentelemetry/otlp-exporter-base';
import { ProtobufTraceSerializer } from `@opentelemetry/otlp-transformer`;
const exporter: SpanExporter = new createOtlpExportDelegate({
options: { /** provide all required options accoding to type**/ },
serializer: ProtobufTraceSerializer, // or JsonTraceSerializer
transport: createMyCustomFetchTransport() /** implement this yourself, a wrapper around your custom fetch, make sure to set the content-type header to what you're sending: `application/x-protobuf` or `application/json` **/
}); /* delegate happens to match the SpanExporter type, this won't work for metrics today though, because some methods are missing */I suppose this is what you mean by
IMO this is a good enough workaround for now. Once we drop support for older Node.js versions (around July 2026), we can also finally use |
|
So my recommendation for this feature is:
|
Which problem is this PR solving?
I'm using OpenTelemetry JS in Cloudflare Workers and I need to send telemetry to a collector running in a private network via Workers VPC. Workers VPC provides a custom
fetchfunction that can route requests through private networks, but there was no way to easily pass this to the OTLP exporters.Before this change, the only way to achieve this was to create a custom version
FetchTransport, which would require duplicating much of its implementation, or to monkey patchglobalThis.fetch.Specifying a custom
fetchfunction could also be useful for other scenarios like adding request/response interceptors, using fetch polyfills, or testing with mocks.Short description of the changes
Adds a
fetchconfiguration option to OTLP HTTP exporters, allowing users to provide a customfetchimplementation instead of usingglobalThis.fetch.Type of change
How Has This Been Tested?
mergeOtlpHttpConfigurationWithDefaults)FetchTransportusing custom fetchnpm test(144 passing)npm run test:browser(85 passing)Checklist: