back to all blogsSee all blog posts

Enhancements to distributed tracing in microservices with MicroProfile 2.1 (and more)

image of author
Laura Cowen on Nov 23, 2018
Post available in languages:

Enhancements to distributed tracing (MicroProfile OpenTracing 1.2)

Distributed tracing enables users to see the flow of requests between microservices, including seeing which microservices have high latency and seeing the hierarchy of calls between applications and their dependent microservices.

In MicroProfile OpenTracing 1.2, you can now also:

  • Skip tracing of JAX-RS requests by specifying a regular expression that matches UriInfo.getPath()

  • Use an alternative format for span names. The new format is <http method>:/@Path value of endpoint’s class>/<@Path value of endpoint’s method>. For example, GET:/inventory/list

Enable the two new functions by defining two keys using MicroProfile Config (e.g. in server.xml or bootstrap.properties):

  • mp.opentracing.server.skip-pattern

  • mp.opentracing.server.operation-name-provider

See also:

Package server TAR files for simpler Dockerfiles

Liberty’s server package tool now supports packaging to .tar and .tar.gz files. The package tool has long supported generating to .zip and .jar files (and on z/OS .pax) but, until now, the most common packaging format on Linux hasn’t been an option.

So why now? It all relates to making Liberty work better with Docker. Docker’s ADD command has built-in support for extracting .tar files. Adding a server package to your Dockerfile is now really simple.

Instead of doing this:

   FROM open-liberty
   COPY defaultServer.zip /tmp/defaultServer.zip
   EXEC apt-get update && apt-get install unzip && unzip /tmp/defaultServer.zip /opt/ol/ && apt-get remove -y unzip && rm -rf /var/lib/apt/lists/*

you can now simply write:

   FROM open-liberty
   ADD defaultServer.tar.gz /opt/ol/

Support for sharding in Java 11 (JDBC 4.3)

We’re currently working on Java 11 support for Open Liberty and it mostly works but isn’t complete yet.

If your JDBC driver supports the 4.3 specification level, the JDBC 4.3 feature enables you to take advantage of new capabilities in JDBC 4.3, including requesting connections and support for sharding. This feature requires Java 11.

It is now possible to request connections for a specific sharding key and optionally, super sharding key, if your database supports sharding and provides a JDBC 4.3 compliant driver.

Enable the feature in your server configuration (server.xml):

<featureManager>
  <feature>jdbc-4.3</feature>
  <feature>jndi-1.0</feature>
  ...
</featureManager>

Configure one or more data sources in the server.xml as you would with the prior version JDBC features. For example:

<dataSource jndiName="jdbc/43datasource">
  <properties databaseName="sampledb" serverName="host1.rchland.ibm.com" portNumber="1234"/>
  <containerAuthData user="user1" password="pwd1"/>
</dataSource>

Use the data source from your application in your app:

@Resource(lookup = "jdbc/43datasource")
DataSource datasource;
// Always cache sharding keys to ensure that matching of pooled connections can be successful.
// The JDBC spec does not require an .equals implementation.
ShardingKey key1, key2;
...
public void init(ServletConfig config) throws ServletException {
    try {
        key1 = datasource.createShardingKeyBuilder().subkey("key1", JDBCType.VARCHAR).build();
        key2 = datasource.createShardingKeyBuilder().subkey("key2", JDBCType.VARCHAR).build();
    } catch (SQLException x) {
        throw new ServletException(x);
    }
}
...
try (Connection con = datasource.createConnectionBuilder().shardingKey(key1).build()) {
    // use connection
}

See also:

Try it now in development builds of Open Liberty

Take a look at the latest Open Liberty development builds.