Skip to content

[Bug]: X-Amzn-Trace-Id is not added to the header for http requests in Nuxt 3 #615

@hibira

Description

@hibira

Which web client version did you detect this bug with?

v1.21.0

What environment (build systems, module system, and framework) did you detect this bug with?

nodejs 23.8.0
Nuxt3
ofetch 1.4.1

Is your web application a single page application (SPA) or multi page application (MPA)?

SPA

Please provide your web client configuration

import { AwsRum, type AwsRumConfig } from 'aws-rum-web';

export default defineNuxtPlugin((_nuxtApp) => {
  const runtimeConfig = useRuntimeConfig();
  if (runtimeConfig.public.rumEnabled) {
    const config: AwsRumConfig = {
      sessionSampleRate: 1,
      identityPoolId: runtimeConfig.public.rumIdentityPoolId,
      endpoint: runtimeConfig.public.rumEndpoint,
      telemetries: ["performance", "errors", ['http', { addXRayTraceIdHeader: true, recordAllRequests: true, }]],
      allowCookies: true,
      enableXRay: true,
      sessionEventLimit: -1,
    };

    const APPLICATION_ID: string = runtimeConfig.public.rumApplicationId;
    const APPLICATION_VERSION: string = '1.0.0';
    const APPLICATION_REGION: string = runtimeConfig.public.rumApplicationRegion;

    const awsRum: AwsRum = new AwsRum(
      APPLICATION_ID,
      APPLICATION_VERSION,
      APPLICATION_REGION,
      config
    );

    return {
      provide: {
        awsRum: awsRum
      }
    };
  }
});

Please describe the bug/issue

In Nuxt3, X-Amzn-Trace-Id is not added to the http request even if addXrayTraceIdHeader: true is specified.
As a result of debugging, addamznTraceIdHeaderToInit was reached and given by

init.headers [X_AMZN_TRACE_ID] = getAmznTraceIdHeaderValue (traceId, segmentID);, 

Image
Image

But X-Amzn-Trace-Id has not actually reached the server. A similar phenomenon has been confirmed in Chrome's Developer Tool > Network.

Image

Nuxt3 uses ofetch as standard, but it seems that the problem with this problem is that there is a difference between the ofetch header reading method and the addAMZntraceidHeaderToInit header method.

Currently,

addamZnTraceIdHeaderToInit = function (init, traceId, segmentId) {
 if (! init.headers) {
 init.headers = {};
 }
 init.headers [X_AMZN_TRACE_ID] = getAMZnTraceIdHeaderValue (traceID, segmentID);
};

Headers are set as init.headers properties like this, but init.headers is a Header class,

init.headers.set (X_AMZN_TRACE_ID, getAMZnTraceIdHeaderValue (traceID, segmentID));

You need to change it to.
In fact, headers were added when usinginit.headers.set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions