Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/otel/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ type OtlpPost = {
signal?: AbortSignal;
};

/** Posts with retries, and returns the last response with its body cancelled. */
/**
* Posts with retries, and returns the last response with its body cancelled.
*
* @deprecated Nothing in the SDK calls it, and it will be removed in a future breaking release.
* Use `createTraceExporter`, `createLogExporter`, or `createMetricExporter` to send OTLP.
*/
export const postOtlp = async (post: OtlpPost) => {
const res = await postWithRetries(post);

Expand Down Expand Up @@ -276,7 +281,7 @@ const postWithRetries = async ({ fetchImpl, url, headers, body, signal }: OtlpPo

const GZIP_THRESHOLD_BYTES = 1024;

export async function maybeGzip(
async function gzipLargeBody(
body: Uint8Array,
): Promise<{ body: Uint8Array; contentEncoding?: "gzip" }> {
if (body.byteLength <= GZIP_THRESHOLD_BYTES || globalThis.CompressionStream === undefined) {
Expand All @@ -297,14 +302,20 @@ export async function maybeGzip(
}
}

/**
* @deprecated The exporters already gzip a body over 1 KiB. This export will be removed in a
* future breaking release.
*/
export const maybeGzip = gzipLargeBody;

async function postSerialized(
body: Uint8Array,
target: OtlpTarget,
transport: Transport,
label: string,
signal?: AbortSignal,
): Promise<void> {
const { body: finalBody, contentEncoding } = await maybeGzip(body);
const { body: finalBody, contentEncoding } = await gzipLargeBody(body);

const headers = contentEncoding
? { ...target.headers, "content-encoding": contentEncoding }
Expand Down
Loading