You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS X-Ray + OpenTelemetry gRPC链路追踪中断问题求助

AWS部署的单体仓库多服务架构中,gRPC调用后OpenTelemetry追踪链路中断

在AWS部署的单体仓库多服务架构里,使用OpenTelemetry初始化Tracer后,链路能从API Gateway正常传递到服务,但发起gRPC调用后,追踪链路在此处中断,被调用服务的全量执行链路完全缺失。

已尝试简化传播器(此前使用包含W3C、B3的复合传播器,当前改用AWSXRayPropagator),以下是相关代码细节:

Tracer初始化代码

...
export const generateOtelSDK = (serviceName: string): NodeSDK => {
  const sanitizedServiceName = serviceName.replace('@', '')
  const contextManager = new AsyncLocalStorageContextManager()
  const traceExporter = new OTLPTraceExporter()
  const spanProcessor = new BatchSpanProcessor(traceExporter)
  const textMapPropagator = new AWSXRayPropagator()
  const grpcInstrumentation = new GrpcInstrumentation()
  const otelSDK = new NodeSDK({
    contextManager,
    serviceName: sanitizedServiceName,
    spanProcessor,
    traceExporter,
    textMapPropagator,
    instrumentations: [
      new AwsInstrumentation({ suppressInternalInstrumentation: true }),
      new ExpressInstrumentation(),
      grpcInstrumentation,
      new HttpInstrumentation({
        ignoreIncomingRequestHook: (request: IncomingMessage): boolean => {
          return ignoreIncomingRequestHookOptions(request)
        },
      }),
      new KafkaJsInstrumentation(),
      new NestInstrumentation(),
      new PgInstrumentation(),
    ],
    resource: new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: sanitizedServiceName }),
  })

  otelSDK.configureTracerProvider(
    { idGenerator: new AWSXRayIdGenerator() },
    spanProcessor,
    contextManager,
    textMapPropagator
  )

  return otelSDK
}

追踪启动代码

import { generateOtelSDK } from './Tracer'

export const startTracing = (serviceName: string) => {
  const otelSDK = generateOtelSDK(serviceName)
  otelSDK.start()

  process.on('SIGTERM', () => {
    otelSDK
      .shutdown()
      .then(() => console.log('Tracer shutdown sucessfully.'))
      .catch((err) => console.error('Error shutting down tracer.', err))
    .finally(() => process.exit(0))
  })
}

服务启动入口(所有服务一致)

import * as tracer from '@common/tracing'
import * as dotenv from 'dotenv'
import pkg from '../package.json'

dotenv.config()
tracer.startTracing(pkg.name)

若需要更多细节可补充,恳请社区提供帮助!

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 22:57:38