diff --git a/packages/build/src/core/flags.js b/packages/build/src/core/flags.js index 6f9521345f..268ae93eac 100644 --- a/packages/build/src/core/flags.js +++ b/packages/build/src/core/flags.js @@ -244,6 +244,11 @@ Default: false`, describe: 'Trace flags containing the trace settings for the given trace ID', hidden: true, }, + 'tracing.baggageFilePath': { + string: true, + describe: '', + hidden: true, + }, offline: { boolean: true, describe: `Do not send requests to the Netlify API to retrieve site settings. diff --git a/packages/build/src/core/normalize_flags.ts b/packages/build/src/core/normalize_flags.ts index 6b9925d326..e736f60f6c 100644 --- a/packages/build/src/core/normalize_flags.ts +++ b/packages/build/src/core/normalize_flags.ts @@ -106,6 +106,7 @@ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) { sampleRate: 1, httpProtocol: DEFAULT_OTEL_ENDPOINT_PROTOCOL, port: DEFAULT_OTEL_TRACING_PORT, + baggageFilePath: '', }, timeline: 'build', quiet: false, diff --git a/packages/build/src/core/types.ts b/packages/build/src/core/types.ts index 3594f940fa..3df505424e 100644 --- a/packages/build/src/core/types.ts +++ b/packages/build/src/core/types.ts @@ -86,4 +86,5 @@ export type TracingOptions = { traceId: string traceFlags: number parentSpanId: string + baggageFilePath: string } diff --git a/packages/build/src/tracing/main.ts b/packages/build/src/tracing/main.ts index f90e1edf52..d6b37b81a0 100644 --- a/packages/build/src/tracing/main.ts +++ b/packages/build/src/tracing/main.ts @@ -49,12 +49,17 @@ export const startTracing = function (options: TracingOptions, logger: (...args: // Sets the current trace ID and span ID based on the options received // this is used as a way to propagate trace context from Buildbot - return trace.setSpanContext(context.active(), { + const ctx = trace.setSpanContext(context.active(), { traceId: options.traceId, spanId: options.parentSpanId, traceFlags: options.traceFlags, isRemote: true, }) + + // Loads the contents of the passed baggageFilePath into the baggage + loadBaggageFromFile(options.baggageFilePath) + + return ctx } /** Stops the tracing service if there's one running. This will flush any ongoing events */