@@ -44,14 +44,17 @@ export interface OtlpExportCounts {
4444}
4545
4646export interface OtlpWriteOptions {
47+ /** Manifest metadata, written as `manifest.json` inside the zip. */
48+ readonly manifest : ManifestInput ;
4749 readonly signal ?: AbortSignal ;
4850 readonly onTempCleanupError ?: ( err : unknown , tempPath : string ) => void ;
4951 /** Fires on either success or failure path so cleanup errors never mask the export outcome. */
5052 readonly onStagingCleanupError ?: ( err : unknown , dir : string ) => void ;
51- /** When provided, a `manifest.json` describing the export is added to the zip. */
52- readonly manifest ?: ManifestInput ;
5353}
5454
55+ /** OTLP/JSON format tag recorded in the manifest. */
56+ const OTLP_FORMAT = "otlp-json" ;
57+
5558interface Channel {
5659 file : EnvelopeFile ;
5760 /** Source events routed to this signal. */
@@ -74,7 +77,7 @@ export async function writeOtlpZipExport(
7477 outputPath : string ,
7578 events : AsyncIterable < TelemetryEvent > ,
7679 context : TelemetryContext ,
77- options : OtlpWriteOptions = { } ,
80+ options : OtlpWriteOptions ,
7881) : Promise < OtlpExportCounts > {
7982 throwIfAborted ( options . signal ) ;
8083 return writeAtomically (
@@ -92,12 +95,7 @@ export async function writeOtlpZipExport(
9295 options . signal ,
9396 options . manifest ,
9497 ) ;
95- await packZip (
96- zipPath ,
97- stagingDir ,
98- options . signal ,
99- options . manifest !== undefined ,
100- ) ;
98+ await packZip ( zipPath , stagingDir , options . signal ) ;
10199 } catch ( err ) {
102100 await safeRemove ( stagingDir , options . onStagingCleanupError ) ;
103101 throw err ;
@@ -129,7 +127,7 @@ async function writeStagedFiles(
129127 events : AsyncIterable < TelemetryEvent > ,
130128 context : TelemetryContext ,
131129 signal : AbortSignal | undefined ,
132- manifestInput : ManifestInput | undefined ,
130+ manifestInput : ManifestInput ,
133131) : Promise < OtlpExportCounts > {
134132 const resource = JSON . stringify ( otlpResource ( context ) ) ;
135133 const scope = JSON . stringify ( otlpScope ( context . extensionVersion ) ) ;
@@ -155,11 +153,7 @@ async function writeStagedFiles(
155153 traces : channels . traces . count ,
156154 metrics : channels . metrics . count ,
157155 } ;
158-
159- if ( manifestInput ) {
160- await writeManifest ( dir , manifestInput , context , channels ) ;
161- }
162-
156+ await writeManifest ( dir , manifestInput , context , channels ) ;
163157 return counts ;
164158}
165159
@@ -177,6 +171,7 @@ async function writeManifest(
177171 const sourceEvents =
178172 channels . logs . count + channels . traces . count + channels . metrics . count ;
179173 const manifest = buildManifest ( {
174+ format : OTLP_FORMAT ,
180175 input,
181176 context,
182177 sourceEvents,
@@ -283,11 +278,10 @@ async function packZip(
283278 outputPath : string ,
284279 sourceDir : string ,
285280 signal : AbortSignal | undefined ,
286- includeManifest : boolean ,
287281) : Promise < void > {
288282 const outStream = createWriteStream ( outputPath ) ;
289283 try {
290- await streamEnvelopesIntoZip ( outStream , sourceDir , signal , includeManifest ) ;
284+ await streamEnvelopesIntoZip ( outStream , sourceDir , signal ) ;
291285 } catch ( err ) {
292286 outStream . destroy ( ) ;
293287 if ( isAbortError ( err ) ) {
@@ -302,7 +296,6 @@ function streamEnvelopesIntoZip(
302296 outStream : WriteStream ,
303297 sourceDir : string ,
304298 signal : AbortSignal | undefined ,
305- includeManifest : boolean ,
306299) : Promise < void > {
307300 return new Promise < void > ( ( resolve , reject ) => {
308301 const fail = ( err : unknown ) : void => reject ( toError ( err ) ) ;
@@ -331,13 +324,7 @@ function streamEnvelopesIntoZip(
331324 }
332325 } ) ;
333326
334- void pumpEnvelopes (
335- zip ,
336- sourceDir ,
337- signal ,
338- waitForDrain ,
339- includeManifest ,
340- ) . catch ( ( err ) => {
327+ void pumpEnvelopes ( zip , sourceDir , signal , waitForDrain ) . catch ( ( err ) => {
341328 zip . terminate ( ) ;
342329 fail ( err ) ;
343330 } ) ;
@@ -349,14 +336,11 @@ async function pumpEnvelopes(
349336 sourceDir : string ,
350337 signal : AbortSignal | undefined ,
351338 waitForDrain : ( ) => Promise < void > ,
352- includeManifest : boolean ,
353339) : Promise < void > {
354- const names : string [ ] = Object . values ( ENVELOPES ) . map (
355- ( envelope ) => envelope . file ,
356- ) ;
357- if ( includeManifest ) {
358- names . push ( MANIFEST_FILE ) ;
359- }
340+ const names = [
341+ ...Object . values ( ENVELOPES ) . map ( ( envelope ) => envelope . file ) ,
342+ MANIFEST_FILE ,
343+ ] ;
360344 for ( const name of names ) {
361345 throwIfAborted ( signal ) ;
362346 await streamFileIntoZip (
0 commit comments