Class SqlSubsegments

java.lang.Object
com.amazonaws.xray.sql.SqlSubsegments

public final class SqlSubsegments
extends java.lang.Object
Class containing utility method to create fully-populated SQL subsegments. See https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-sql
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String DATABASE_TYPE
    The type of SQL Database this query is done on, like MySQL or HikariCP
    static java.lang.String DATABASE_VERSION
    The version of the database product itself, like MySQL 8.0
    static java.lang.String DEFAULT_DATABASE_NAME
    The fallback name for subsegments representing SQL queries that failed to be named dynamically
    static java.lang.String DRIVER_VERSION
    The version of the database driver library used for this database
    static java.lang.String SANITIZED_QUERY
    The SQL query string used in this query.
    static java.lang.String URL
    The URL of the database this query is made on
    static java.lang.String USER
    The database username
  • Method Summary

    Modifier and Type Method Description
    static Subsegment forQuery​(java.sql.Connection connection, @Nullable java.lang.String query)
    Begins a Subsegment populated with data provided by the Connection.getMetaData() method.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • URL

      public static final java.lang.String URL
      The URL of the database this query is made on
      See Also:
      Constant Field Values
    • USER

      public static final java.lang.String USER
      The database username
      See Also:
      Constant Field Values
    • DRIVER_VERSION

      public static final java.lang.String DRIVER_VERSION
      The version of the database driver library used for this database
      See Also:
      Constant Field Values
    • DATABASE_TYPE

      public static final java.lang.String DATABASE_TYPE
      The type of SQL Database this query is done on, like MySQL or HikariCP
      See Also:
      Constant Field Values
    • DATABASE_VERSION

      public static final java.lang.String DATABASE_VERSION
      The version of the database product itself, like MySQL 8.0
      See Also:
      Constant Field Values
    • SANITIZED_QUERY

      public static final java.lang.String SANITIZED_QUERY
      The SQL query string used in this query. This is not recorded in subsegments by default due to security issues. SDK users may use this key or forQuery(java.sql.Connection, java.lang.String) to manually record their queries if they wish. See https://github.com/aws/aws-xray-sdk-java/issues/28
      See Also:
      Constant Field Values
    • DEFAULT_DATABASE_NAME

      public static final java.lang.String DEFAULT_DATABASE_NAME
      The fallback name for subsegments representing SQL queries that failed to be named dynamically
      See Also:
      Constant Field Values
  • Method Details

    • forQuery

      public static Subsegment forQuery​(java.sql.Connection connection, @Nullable java.lang.String query)
      Begins a Subsegment populated with data provided by the Connection.getMetaData() method. Includes the SQL query string if it is non-null, omits it otherwise. Takes care to swallow any potential SQLExceptions and always start a subsegment for consistency.
      Parameters:
      connection - the JDBC connection object used for the query this Subsegment represents.
      query - the SQL query string used in this query, or null if it is not desirable to include in the subsegment, e.g. for security concerns.
      Returns:
      the created Subsegment.