Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An exception SegmentNotFoundException when starting the project with aws-xray-java-agent 2.18.2 #421

Open
factorypoint opened this issue Mar 4, 2025 · 1 comment

Comments

@factorypoint
Copy link

factorypoint commented Mar 4, 2025

My project is deployed in EKS. I've deployed the X-Ray daemon process in EKS. I referred to the X-Ray Java integration documentation (https://docs.aws.amazon.com/zh_cn/xray/latest/devguide/aws-x-ray-auto-instrumentation-agent-for-java.html) and downloaded the latest version of aws-xray-java-agent 2.18.2 (https://github.com/aws/aws-xray-java-agent/releases). I integrated the agent into my Docker image and specified the jvm parameter when starting the project:

-javaagent:'/x-ray-agent/disco-java-agent.jar=pluginPath=/x-ray-agent/disco-plugins'. 

However, after starting, I found the SegmentNotFoundException in the logs. The general content is as follows:

2025-02-28 02:33:24.179Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'fp_admin@rds-mysql-dev': segment cannot be found.
2025-02-28 02:33:24.414Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): No segment in progress.
2025-02-28 02:33:24.423Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found.

Has anyone else the same problem?

Checking my project startup logs, it seems that X-Ray started successfully:

Listening for transport dt_socket at address: 7091
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Feb 28, 2025 2:39:14 AM com.amazonaws.xray.agent.runtime.config.XRaySDKConfiguration init
INFO: Initializing the X-Ray Agent Recorder
Feb 28, 2025 2:39:15 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Feb 28, 2025 2:39:15 AM com.amazonaws.xray.config.DaemonConfiguration setDaemonAddress
INFO: Ignoring call to setDaemonAddress as one of AWS_XRAY_DAEMON_ADDRESS or com.amazonaws.xray.emitters.daemonAddress is set.
Feb 28, 2025 2:39:25 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Feb 28, 2025 2:39:25 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Feb 28, 2025 2:39:25 AM com.amazonaws.xray.AWSXRayRecorder <init>
INFO: Overriding contextMissingStrategy. Environment variable AWS_XRAY_CONTEXT_MISSING has value: "LOG_ERROR".
Feb 28, 2025 2:39:25 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Feb 28, 2025 2:39:25 AM com.amazonaws.xray.AWSXRayRecorderBuilder lambda$build$1
INFO: Collecting trace metadata from com.amazonaws.xray.plugins.EKSPlugin.
Feb 28, 2025 2:39:30 AM com.amazonaws.xray.AWSXRayRecorderBuilder lambda$build$1
INFO: Collecting trace metadata from com.amazonaws.xray.plugins.EC2Plugin.
Feb 28, 2025 2:39:30 AM com.amazonaws.xray.plugins.EC2Plugin populateLogReferences
WARNING: CloudWatch Agent log configuration file not found at /opt/aws/amazon-cloudwatch-agent/etc/log-config.json. Install the CloudWatch Agent on this instance to record log references in X-Ray.
Feb 28, 2025 2:39:30 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Feb 28, 2025 2:39:30 AM com.amazonaws.xray.AWSXRayRecorder <init>
INFO: Overriding contextMissingStrategy. Environment variable AWS_XRAY_CONTEXT_MISSING has value: "LOG_ERROR".
Feb 28, 2025 2:39:30 AM com.amazonaws.xray.config.DaemonConfiguration <init>
INFO: Environment variable AWS_XRAY_DAEMON_ADDRESS is set. Emitting to daemon on address xray-service.default:2000.
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
02:40:12.380 [main] INFO com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager -- [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
02:40:12.387 [main] INFO com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager -- [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.
02:40:51.454 [com.alibaba.nacos.client.remote.worker.1] INFO com.alibaba.nacos.common.ability.AbstractAbilityControlManager -- Ready to get current node abilities...
02:40:51.494 [com.alibaba.nacos.client.remote.worker.1] INFO com.alibaba.nacos.common.ability.AbstractAbilityControlManager -- Ready to initialize current node abilities, support modes: [SDK_CLIENT]
02:40:51.501 [com.alibaba.nacos.client.remote.worker.1] INFO com.alibaba.nacos.common.ability.AbstractAbilityControlManager -- Initialize current abilities finish...
02:40:51.558 [com.alibaba.nacos.client.remote.worker.1] INFO com.alibaba.nacos.common.ability.discover.NacosAbilityManagerHolder -- [AbilityControlManager] Successfully initialize AbilityControlManager
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.4.0)
2025-02-28 02:40:58.923Z  INFO 7 [admin-server] [           main] c.f.admin.server.AdminServerApplication  : Starting AdminServerApplication v0.0.1-SNAPSHOT using Java 17.0.2 with PID 7 (/app/fp_app.jar started by root in /app)
2025-02-28 02:40:58.925Z  INFO 7 [admin-server] [           main] c.f.admin.server.AdminServerApplication  : The following 1 profile is active: "dev"
2025-02-28 02:41:00.213Z  INFO 7 [admin-server] [           main] c.a.c.n.c.NacosConfigDataLoader          : [Nacos Config] Load config[dataId=common-dev.yaml, group=DEFAULT_GROUP] success
2025-02-28 02:41:00.214Z  INFO 7 [admin-server] [           main] c.a.c.n.c.NacosConfigDataLoader          : [Nacos Config] Load config[dataId=admin-server-dev.yaml, group=DEFAULT_GROUP] success
2025-02-28 02:41:34.440Z  INFO 7 [admin-server] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2025-02-28 02:41:34.802Z  INFO 7 [admin-server] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2025-02-28 02:41:35.725Z  INFO 7 [admin-server] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 314 ms. Found 0 Redis repository interfaces.
2025-02-28 02:41:44.547Z  INFO 7 [admin-server] [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=979af92c-fa39-30d7-ae8a-6ddc20e46818
2025-02-28 02:41:45.437Z  WARN 7 [admin-server] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'com.alibaba.cloud.nacos.NacosConfigAutoConfiguration' of type [com.alibaba.cloud.nacos.NacosConfigAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). The currently created BeanPostProcessor [nacosAnnotationProcessor] is declared through a non-static factory method on that class; consider declaring it as static instead.
Debugger failed to attach: handshake failed - received >GET / HTTP/1.1< - expected >JDWP-Handshake<
Debugger failed to attach: handshake failed - received >< - expected >JDWP-Handshake<
2025-02-28 02:42:24.617Z  INFO 7 [admin-server] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8091 (http)
2025-02-28 02:42:24.748Z  INFO 7 [admin-server] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2025-02-28 02:42:24.756Z  INFO 7 [admin-server] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.33]
2025-02-28 02:42:26.302Z  INFO 7 [admin-server] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2025-02-28 02:42:26.305Z  INFO 7 [admin-server] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 86045 ms
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
2025-02-28 02:43:17.637Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'prod-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:43:18.607Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'prod-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:43:19.003Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'prod-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:43:19.196Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'prod-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:43:25.487Z  INFO 7 [admin-server] [           main] c.f.c.config.FpMyBatisAutoConfiguration  : ==> Initializing SensitiveDataParameterInterceptor
2025-02-28 02:43:25.520Z  INFO 7 [admin-server] [           main] c.f.c.config.FpMyBatisAutoConfiguration  : ==> Initializing SensitiveDataResultSetInterceptor
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Get /192.168.48.217 network interface 
Get network interface info: name:eth0 (eth0)
Initialization Sequence datacenterId:0 workerId:7
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.5.9 
2025-02-28 02:43:34.364Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'prod-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:43:36.911Z  WARN 7 [admin-server] [           main] org.apache.velocity.deprecation          : configuration key 'resource.loader' has been deprecated in favor of 'resource.loaders'
2025-02-28 02:43:36.926Z  WARN 7 [admin-server] [           main] org.apache.velocity.deprecation          : configuration key 'classpath.resource.loader.class' has been deprecated in favor of 'resource.loader.classpath.class'
2025-02-28 02:43:38.255Z  INFO 7 [admin-server] [           main] o.s.c.openfeign.FeignClientFactoryBean   : For 'mall-server' URL not provided. Will try picking an instance via load-balancing.
2025-02-28 02:44:08.792Z  WARN 7 [admin-server] [           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2025-02-28 02:44:09.167Z  INFO 7 [admin-server] [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint beneath base path '/actuator'
2025-02-28 02:44:11.449Z  INFO 7 [admin-server] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8091 (http) with context path '/'
2025-02-28 02:44:12.101Z  INFO 7 [admin-server] [           main] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
2025-02-28 02:44:12.101Z  INFO 7 [admin-server] [           main] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth
.ram.RamClientAuthServiceImpl success.
2025-02-28 02:44:12.682Z  INFO 7 [admin-server] [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, DEFAULT_GROUP admin-server 192.168.48.217:8091 register finished
2025-02-28 02:44:12.890Z  INFO 7 [admin-server] [           main] c.f.admin.server.AdminServerApplication  : Started AdminServerApplication in 262.234 seconds (process running for 303.961)
2025-02-28 02:44:13.836Z  INFO 7 [admin-server] [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=common-dev.yaml, group=DEFAULT_GROUP
2025-02-28 02:44:13.844Z  INFO 7 [admin-server] [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=admin-server-dev.yaml, group=DEFAULT_GROUP
2025-02-28 03:15:15.511Z  INFO 7 [admin-server] [nio-8091-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-02-28 03:15:15.515Z  INFO 7 [admin-server] [nio-8091-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2025-02-28 03:15:15.525Z  INFO 7 [admin-server] [nio-8091-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 8 ms
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7ad540e5] was not registered for synchronization because synchronization is not active
2025-02-28 03:15:19.823Z  INFO 7 [admin-server] [nio-8091-exec-1] com.zaxxer.hikari.HikariDataSource       : db.server - Starting...
2025-02-28 03:15:22.104Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'fp_admin@rds-mysql-dev': segment cannot be found.
2025-02-28 03:15:22.385Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): No segment in progress.
2025-02-28 03:15:22.387Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found.
2025-02-28 03:15:22.401Z  INFO 7 [admin-server] [nio-8091-exec-1] com.zaxxer.hikari.pool.HikariPool        : db.server - Added connection com.mysql.cj.jdbc.ConnectionImpl@6e459063
2025-02-28 03:15:22.411Z  INFO 7 [admin-server] [nio-8091-exec-1] com.zaxxer.hikari.HikariDataSource       : db.server - Start completed.
JDBC Connection [HikariProxyConnection@1207725050 wrapping com.mysql.cj.jdbc.ConnectionImpl@6e459063] will not be managed by Spring
==>  Preparing: SELECT aid,status,name,phone_area_code,phone,phone_suffix,email,email_prefix,password,country,state,city,mac,created_at,created_by FROM admins WHERE (email = ?)
==> Parameters: cZOi5t07WzowoUSaXOJfsaN7iAYO0YBl/JANy61SKBA=(String)
2025-02-28 03:15:23.019Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'fp_admin@rds-mysql-dev': segment cannot be found.
2025-02-28 03:15:23.029Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): No segment in progress.
2025-02-28 03:15:23.032Z ERROR 7 [admin-server] [nio-8091-exec-1] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found.
<==      Total: 0
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7ad540e5]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@71d005bd] was not registered for synchronization because synchronization is not active
2025-02-28 03:16:59.928Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'fp_admin@rds-mysql-dev': segment cannot be found.
2025-02-28 03:16:59.969Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): No segment in progress.
2025-02-28 03:16:59.986Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found.
JDBC Connection [HikariProxyConnection@1889248040 wrapping com.mysql.cj.jdbc.ConnectionImpl@6e459063] will not be managed by Spring
==>  Preparing: SELECT aid,status,name,phone_area_code,phone,phone_suffix,email,email_prefix,password,country,state,city,mac,created_at,created_by FROM admins WHERE (email = ?)
==> Parameters: 2iF08q3JtKdbnxTTJCYaxelFE57y+KRl6DjOP3+O0eQ=(String)
2025-02-28 03:17:00.078Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'fp_admin@rds-mysql-dev': segment cannot be found.
2025-02-28 03:17:00.102Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): No segment in progress.
2025-02-28 03:17:00.105Z ERROR 7 [admin-server] [nio-8091-exec-3] c.a.x.s.LogErrorContextMissingStrategy   : Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found.

The following is the YAML script for deploying my X-Ray daemon process:

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: xray-daemon
  name: xray-daemon
  namespace: default
  # Update IAM Role ARN created for X-Ray access
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::xxxxx:role/eksctl-fp-eks-group-dev-addon-iamserviceaccou-Role1-pTYZWLduFMG5
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: xray-daemon
  namespace: default
spec:
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: xray-daemon
  template:
    metadata:
      labels:
        app: xray-daemon
    spec:
      serviceAccountName: xray-daemon
      volumes:
        - name: config-volume
          configMap:
            name: "xray-config"
      containers:
        - name: xray-daemon
          image: amazon/aws-xray-daemon:3.2.0
          command: ["/usr/bin/xray", "-c", "/aws/xray/config.yaml"]
          resources:
            requests:
              cpu: 256m
              memory: 32Mi
            limits:
              cpu: 512m
              memory: 64Mi
          ports:
            - name: xray-ingest
              containerPort: 2000
              hostPort: 2000
              protocol: UDP
            - name: xray-tcp
              containerPort: 2000
              hostPort: 2000
              protocol: TCP
          volumeMounts:
            - name: config-volume
              mountPath: /aws/xray
              readOnly: true
---
# Configuration for AWS X-Ray daemon
apiVersion: v1
kind: ConfigMap
metadata:
  name: xray-config
  namespace: default
data:
  config.yaml: |-
    TotalBufferSizeMB: 24
    Socket:
      UDPAddress: "0.0.0.0:2000"
      TCPAddress: "0.0.0.0:2000"
    Version: 2
---
# k8s service definition for AWS X-Ray daemon headless service
apiVersion: v1
kind: Service
metadata:
  name: xray-service
  namespace: default
spec:
  selector:
    app: xray-daemon
  clusterIP: None
  ports:
    - name: xray-ingest
      port: 2000
      protocol: UDP
    - name: xray-tcp
      port: 2000
      protocol: TCP
@liustve
Copy link

liustve commented Mar 5, 2025

Hi @factorypoint,

SQL queries create only subsegments in the Java Agent auto instrumentation which is where the error likely coming from.

I recommend that you try and manually instrument your code with XRay SDK to create Segments for your SQL queries or use ADOT Java Agent instead which has a workaround on the segment-subsegment design: https://github.com/aws-observability/aws-otel-java-instrumentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants