AWS X-RAY + Opentelemetry gRPC 工具运行不佳

问题描述 投票:0回答:1

我有这段初始化跟踪器的代码。

它的上下文是在单一存储库中使用的,其中多个服务部署到AWS中。跟踪正确地从 api-gw 到服务,但是当它们命中 gRPC 调用时,它们会停在那里,而不是在被调用的服务内继续(其中一个服务使用 gRPC 从同一存储库调用另一个服务),并且基本上错过了整个执行在被调用的服务中。

追踪代码

...
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))
  })
}

其中一个服务main.ts(它们都是一样的)

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

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

我尝试简化传播器,就像之前使用具有多个未使用的 w3c 和 b3 的复合传播器一样。

希望有人可以提供此信息,如果需要更多信息,请询问。 提前感谢社区!

typescript instrumentation open-telemetry aws-xray grpc-node
1个回答
0
投票

请在 opentelemetry-js 存储库中删除问题

仅供参考 grpc 仪器相关问题。 https://github.com/open-telemetry/opentelemetry-js/issues/4053

© www.soinside.com 2019 - 2024. All rights reserved.